-
Notifications
You must be signed in to change notification settings - Fork 504
refactor: crossfield hints in non-native #1539
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors the hint-calling convention to introduce a generic, multi-field hint API and migrates all existing hint methods and tests to use it.
- Adds
NewHintGenericandNewVarGenericHintwith aHintContextwrapper. - Updates
UnwrapHint*,NewHint,NewHintWithNativeOutput, andNewHintWithNativeInputto delegate to the new generic mechanism. - Refactors all native and emulated hint implementations and their tests to use the new context-based API.
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| std/math/emulated/field_test.go | Removed legacy multi-hint tests, retained only sub-constant test |
| std/math/emulated/field_hint_test.go | Updated unit tests to call generic hints and renamed package for internal access |
| std/math/emulated/field_hint_example_test.go | Added an example demonstrating the new generic hint usage |
| std/math/emulated/field_hint.go | Introduced HintContext, NewHintGeneric, NewVarGenericHint, removed old wrap |
| std/algebra/native/sw_bls12377/hints.go | Migrated halfGCDEisenstein to the new context-based API, removed sign-only hint |
| std/algebra/native/sw_bls12377/g1.go | Switched GLV/fake-GLV hint calls to use NewHintGeneric |
| std/algebra/emulated/sw_emulated/point.go | Updated scalar‐mul GLV hints to use the generic API |
| std/algebra/emulated/sw_emulated/hints.go | Refactored all SW emulated hints to use HintContext |
| std/algebra/emulated/sw_bls12381/hints.go | Refactored BLS12-381 decomposition hints to the new API |
| std/algebra/emulated/sw_bls12381/g2.go | Updated G2 GLV decomposition calls to use NewHintGeneric |
Comments suppressed due to low confidence (5)
std/math/emulated/field_hint_test.go:309
- [nitpick] There's a typo in the function name:
Emulatedeshould beEmulated. Consider renaming totestGenericHintNativeInEmulatedOutfor clarity.
func testGenericHintNativeInEmulatedeOut[T FieldParams](t *testing.T) {
std/math/emulated/field_hint_test.go:327
- [nitpick] Typo in the test name:
Emulatedeshould beEmulated. Rename toTestGenericHintNativeInEmulatedOutto match the function under test.
func TestGenericHintNativeInEmulatedeOut(t *testing.T) {
std/math/emulated/field_hint_test.go:655
- Consider adding unit tests for
Field.NewHintWithNativeOutputandField.NewHintWithNativeInputto verify those code paths are covered by the test suite.
}
std/math/emulated/field_hint.go:326
- This loop uses
range nbEmulated1Outputs, butnbEmulated1Outputsis an integer, not a slice. It will not compile. Consider iterating over the sliceemulated1Outputs(e.g.,for i := range emulated1Outputs) or usingfor i := 0; i < nbEmulated1Outputs; i++.
for i := range nbEmulated1Outputs {
std/math/emulated/field_hint.go:336
- Similarly,
nbEmulated2Outputsis an integer, sorange nbEmulated2Outputsis invalid. Update this to iterate by index or over theemulated2Outputsslice.
for i := range nbEmulated2Outputs {
Description
Previously we had mechanisms for being able to call hints in non-native gadget where either the inputs xor the outputs are in native field. But this wasn't sufficient for all use cases we had, sometimes we had to be able to provide the inputs from two different fields or we would have outputs in different fields. And the fields could be either native or non-native.
This PR refactors the hint calling convention to be more generic, allowing for all possible use cases. It additionally adds an option to be able to have inputs over multiple emulated fields. As we use type parametrization, then it is currently limited to 2 emulated fields, but the wrapping/unwrapping in principle supports arbitrary number of emulated fields.
I refactored current wrapping/unwrapping to use the new mechanism. All changes are backwards compatible, so any internal/external uses should keep working as is.
This also enables #1303 as now we can also pass in A, B to the scalarmul hint nicely and just do generic SW scalar multiplication.
Finally, it also allowed to change the hints in EC arithmetic where we previously called similar hints multiple times to return the emulated values and signs.
Type of change
How has this been tested?
Checklist:
golangci-lintdoes not output errors locally