Skip to content
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

Feat: fixed-argument emulated pairing #708

Merged
merged 21 commits into from
Jul 4, 2023
Merged

Conversation

yelhousni
Copy link
Contributor

@yelhousni yelhousni commented May 30, 2023

This PR adds circuits for emulated pairing e(P,G₂) and e(P,G₂)*e(T,Q) where G₂ is a fixed point (the canonical generator of the G2 subgroup). The idea is to precompute all the lines and avoid to do EC arithmetic in-circuit. This scenario happens for e.g. BLS signature (minimal-signature-size variant) and KZG.

TODO for later PRs:

  • pre-compute product of lines when bit is 1 or -1
  • emulated BLS signature gadget
  • emulated KZG gadget
  • allow fixed arguments other than G₂ (KZG has 2 pairings, one with fixed G₂ and one with fixed [α]G₂ from the SRS)

  • same for native pairing packages
    • BLS12-377
    • BLS24-315

@yelhousni yelhousni added this to the v0.9.0 milestone May 30, 2023
@yelhousni yelhousni requested a review from ivokub May 30, 2023 16:22
@yelhousni
Copy link
Contributor Author

yelhousni commented May 31, 2023

For a single fixed-argument BN254 pairing, i.e. e(P,G2), this PR saves 301k r1cs:

BenchmarkSinglePairing
groth16:  1525855

BenchmarkSingleFixedPairing
groth16:  1223891

For a double BN254 pairing where only one is fixed-argument, i.e. e(P1,G2)*e(P2,Q), this saves 173k r1cs:

BenchmarkDoublePairing
groth16:  1876157

BenchmarkDoubleFixedPairing
groth16:  1702867

Same goes for BLS12-381.

Copy link
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.

I made a few changes:

  • for native I just made the computated lines private.
  • for emulated I made the computed lines private and also initalise lazily as there is small overhead. It is not significant, but in the future when we maybe want to provide fixed point as a paremeter, then it is bigger.

Otherwise looks good as always!

Copy link
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.

Your modifications also approved.

@yelhousni yelhousni merged commit 8ce12ed into develop Jul 4, 2023
@yelhousni yelhousni deleted the feat/fixed-pairing branch July 4, 2023 10:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants