-
Notifications
You must be signed in to change notification settings - Fork 70
feat: Parse struct name in algebra + ECC init macros as string #1891
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- rename remaining structs - switch from num-bigint-dig to num-bigint
…weierstrass and edwards curves)
Co-authored-by: Jonathan Wang <[email protected]>
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.
Commit: 5a3de18 |
CodSpeed WallTime Performance ReportMerging #1891 will not alter performanceComparing
|
…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]>
…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]>
You can merge #1945 and this branch into your twisted edwards branch |
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 likeWeierstrassPoint
andIntMod
). 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!
, andte_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'sset_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 intofeat/new-execution
first.TODO: remember to remove the
branch = ...
fromexamples/algebra/Cargo.toml
andexamples/ecc/Cargo.toml
before merging.