Skip to content

Fix: edge cases in std/algebra elliptic curve arithmetic circuit (emulated and 2-chains)#1023

Merged
yelhousni merged 14 commits into
masterfrom
fix/ec-edgecases
Jan 29, 2024
Merged

Fix: edge cases in std/algebra elliptic curve arithmetic circuit (emulated and 2-chains)#1023
yelhousni merged 14 commits into
masterfrom
fix/ec-edgecases

Conversation

@yelhousni
Copy link
Copy Markdown
Contributor

@yelhousni yelhousni commented Jan 26, 2024

Description

  • Fix edge cases in std/algebra involving scalars 0 and points (0,0) using the UseSafe option.
  • Fix bug when scalar is 1 in scalarMulGeneric, scalarBitsMulGeneric and related methods.
  • Fix fix: PLONK verifier gadget in-circuit without commitments #964 (but the fix is commented out to save constraints for the cases with appi.Commit that we use in Linea)

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How has this been tested?

  • Current tests
  • New tests for missing methods
  • New tests taking into accounts all edge cases

How has this been benchmarked?

Constraints count doesn't change when UseSafe option is not used (except for scalarMulGeneric), which is what interests us the most for our use-cases. The option is to capture all edge cases in all use-cases.
Best thing forward is to add relevant emulated circuits to internal/stats.

Checklist:

  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • I did not modify files generated from templates
  • golangci-lint does not output errors locally
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@yelhousni yelhousni marked this pull request as draft January 26, 2024 13:49
@yelhousni yelhousni changed the title Fix: edge cases in std elliptic curve arithmetic circuit (emulated and 2-chains) Fix: edge cases in std/algebra elliptic curve arithmetic circuit (emulated and 2-chains) Jan 26, 2024
@yelhousni yelhousni self-assigned this Jan 26, 2024
@yelhousni yelhousni requested a review from ivokub January 26, 2024 14:32
@yelhousni yelhousni added type: bug Something isn't working type: consolidate strengthen an existing feature labels Jan 26, 2024
@yelhousni yelhousni added this to the v0.9.0 milestone Jan 26, 2024
@yelhousni yelhousni marked this pull request as ready for review January 26, 2024 14:38
Copy link
Copy Markdown
Collaborator

@ivokub ivokub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, however I think for scalarmul by constant we can have fast paths which do not perform computations.

Dunno about PLONK verifier options though - I think they are good to have but not essential. I think we can implement them later (but creating an issue for tracking), it is up to you.

Comment thread std/algebra/native/sw_bls12377/g1.go Outdated
Comment thread std/algebra/native/sw_bls12377/g1.go Outdated
Comment thread std/algebra/native/sw_bls12377/g2.go Outdated
Comment thread std/algebra/native/sw_bls12377/g2.go Outdated
Comment thread std/algebra/native/sw_bls24315/g1.go Outdated
Comment thread std/algebra/native/sw_bls24315/g2.go
Comment thread std/recursion/plonk/verifier.go
Comment thread std/recursion/plonk/verifier.go
Comment thread std/recursion/plonk/verifier_test.go
@yelhousni
Copy link
Copy Markdown
Contributor Author

yelhousni commented Jan 29, 2024

Looks good, however I think for scalarmul by constant we can have fast paths which do not perform computations.

Dunno about PLONK verifier options though - I think they are good to have but not essential. I think we can implement them later (but creating an issue for tracking), it is up to you.

Applied fast path for constScalarMul when s==0. For the case s==1 I didn't do it since we never use this method anyway and we can also specialize paths for s==2 and so on.. but s==0 is just to have the exposed method working for all cases even if it's never used in our use-cases. For the plonk option I will create an issue and close this PR. Wdyt?

@yelhousni yelhousni requested a review from ivokub January 29, 2024 10:47
Copy link
Copy Markdown
Collaborator

@ivokub ivokub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied fast path for constScalarMul when s==0. For the case s==1 I didn't do it since we never use this method anyway and we can also specialize paths for s==2 and so on.. but s==0 is just to have the exposed method working for all cases even if it's never used in our use-cases. For the plonk option I will create an issue and close this PR. Wdyt?

Yep, I agree - lets only handle s==0 in the fast path and everything else in regular path. Your changes look good 👍 !

And I also agree with handling PLONK verifier options in separate PR. It is nice to have but nothing critical.

@yelhousni yelhousni merged commit 4c81525 into master Jan 29, 2024
@yelhousni yelhousni deleted the fix/ec-edgecases branch January 29, 2024 12:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: bug Something isn't working type: consolidate strengthen an existing feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: PLONK verifier gadget in-circuit without commitments

2 participants