Skip to content

Conversation

Avaneesh-axiom
Copy link
Contributor

@Avaneesh-axiom Avaneesh-axiom commented Jul 23, 2025

Currently, we use the struct path as a shared id between the *_declare! and *_init! macros so that they could agree on the extern func names. However, this requires the struct to be in scope (as well as some traits like WeierstrassPoint and IntMod). This isn't good for UX with the guest library re-org since these structs and traits are internal, and ideally should be invisible to the user.

This PR modifies the complex_init!, sw_init!, and te_init! macros to take in the struct name as a string. This requires some logic from the setup extern funcs to be moved to the ECC struct's set_up_once associated function. In particular, the setup extern function is now just a wrapper on the custom asm instructions. It's purpose is simply to select the correct opcode (which is how it should have been originally).

Note: this branch is based on feat/edwards-curve-new-execution so #1858 should be reviewed and merged into feat/new-execution first.

TODO: remember to remove the branch = ... from examples/algebra/Cargo.toml and examples/ecc/Cargo.toml before merging.

jonathanpwang and others added 30 commits June 9, 2025 21:31
- rename remaining structs
- switch from num-bigint-dig to num-bigint
A bug involving opcode collisions between short Weierstrass and twisted Edwards curves was found.

To fix this, CurveConfig was rewritten and separate opcodes were given to the two types of curves.
Copy link

group app.proof_time_ms app.cycles app.cells_used leaf.proof_time_ms leaf.cycles leaf.cells_used
verify_fibair (+53 [+4.2%]) 1,305 322,697 17,271,166 - - -
fibonacci (-8 [-0.3%]) 2,341 1,500,277 50,589,231 - - -
regex (+53 [+0.8%]) 7,059 4,165,432 166,449,586 - - -
ecrecover (+18 [+1.3%]) 1,393 (-162 [-0.1%]) 137,121 8,172,044 - - -
pairing (+131 [+3.4%]) 3,980 (+19974 [+1.1%]) 1,882,938 (+711748 [+0.7%]) 103,242,601 - - -

Commit: 5a3de18

Benchmark Workflow

Copy link

codspeed-hq bot commented Jul 23, 2025

CodSpeed WallTime Performance Report

Merging #1891 will not alter performance

Comparing feat/remove-import-for-init (5a3de18) with feat/new-execution (63667e2)

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

Summary

✅ 24 untouched benchmarks

jonathanpwang added a commit that referenced this pull request Aug 7, 2025
…1945)

Cherry-picked from #1891
without the twisted Edwards macros.

The `complex_init!` and `sw_init!` macros are updated so that instead of
parsing a `Path`, it parses a `LitStr`. This makes it so that the
`_init!` macros do not require any path imports in the file where it is
called, which greatly improves the developer experience.

The main files changed aside from test files and auto-generates
`openvm_init.rs` files are:
- extensions/algebra/complex-macros/src/lib.rs
- extensions/ecc/sw-macros/src/lib.rs

In both macros, the change essentially boils down to changing:
(before)
```rust
        let items = input.parse_terminated(<Expr as Parse>::parse, Token![,])?;
```
to (after)
```rust
        let items = input.parse_terminated(<LitStr as Parse>::parse, Token![,])?;
```
and then associated type changes (mostly simplifications) in converting
tokens to strings.

There is one additional change needed only for the `sw_init!` macro
case. Previously the linked function
```rust
extern "C" fn #setup_extern_func()
```
defined by the `sw_init!` macro did use the path of the struct within
the function implementation. After this PR, we avoid this import by
moving that part of the logic into the `fn set_up_once()` function
defined for the struct itself. This changed the function signature of
the extern function to:
```rust
            extern "C" fn #setup_extern_func(uninit: *mut core::ffi::c_void, p1: *const u8, p2: *const u8)
```
[Here](https://www.diffchecker.com/0ncTMwe2/) is the diff of the code
that was moved from the `#setup_extern_func()` into the `set_up_once()`
function.

---------

Co-authored-by: Avaneesh Kulkarni <[email protected]>
jonathanpwang added a commit that referenced this pull request Aug 7, 2025
…1945)

Cherry-picked from #1891
without the twisted Edwards macros.

The `complex_init!` and `sw_init!` macros are updated so that instead of
parsing a `Path`, it parses a `LitStr`. This makes it so that the
`_init!` macros do not require any path imports in the file where it is
called, which greatly improves the developer experience.

The main files changed aside from test files and auto-generates
`openvm_init.rs` files are:
- extensions/algebra/complex-macros/src/lib.rs
- extensions/ecc/sw-macros/src/lib.rs

In both macros, the change essentially boils down to changing:
(before)
```rust
        let items = input.parse_terminated(<Expr as Parse>::parse, Token![,])?;
```
to (after)
```rust
        let items = input.parse_terminated(<LitStr as Parse>::parse, Token![,])?;
```
and then associated type changes (mostly simplifications) in converting
tokens to strings.

There is one additional change needed only for the `sw_init!` macro
case. Previously the linked function
```rust
extern "C" fn #setup_extern_func()
```
defined by the `sw_init!` macro did use the path of the struct within
the function implementation. After this PR, we avoid this import by
moving that part of the logic into the `fn set_up_once()` function
defined for the struct itself. This changed the function signature of
the extern function to:
```rust
            extern "C" fn #setup_extern_func(uninit: *mut core::ffi::c_void, p1: *const u8, p2: *const u8)
```
[Here](https://www.diffchecker.com/0ncTMwe2/) is the diff of the code
that was moved from the `#setup_extern_func()` into the `set_up_once()`
function.

---------

Co-authored-by: Avaneesh Kulkarni <[email protected]>
@jonathanpwang
Copy link
Contributor

You can merge #1945 and this branch into your twisted edwards branch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants