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: emulated BLS12-381 pairing #591

Merged
merged 15 commits into from
Mar 23, 2023
Merged

Feat: emulated BLS12-381 pairing #591

merged 15 commits into from
Mar 23, 2023

Conversation

yelhousni
Copy link
Contributor

@yelhousni yelhousni commented Mar 20, 2023

Following #566, this PR implements an emulated BLS12-381 pairing circuit. It costs 3177374 = ~3.1M R1CS constraints when verified in a BN254 Groth16. The gap between BN254 pairing (3.1M-2M=1.1M) is justified by BLS12-381 size (emulating a 381-bit field in a 254-bit compared to 254-bit in 254-bit).

The PR needs Consensys/gnark-crypto#360 for testing.

TODOs:

  • When loopCounter[i]=1, multiply lines between them (Mul014By014) before multiplying by the accumulator (MulBy01245). This is less efficient than 2 multiplications of lines by accumulator (MulBy014) because MulBy01245 costs one more multiplication compared to MulBy01234 in the case of a D-type twist (e.g. BN254).
  • We implement SQR2345 variant of Karabina's cyclotomic square which is the most circuit-efficient for a series of 4+ squares. However, in Expt() here, there is a shift of size 3 which is optimal with SQR12345 variant (paragraph 5.6).

(we don't use Karabina nor Granger-Scott cyclotomic square anymore. All the final exp is done with T2 arithmetic.)

@yelhousni yelhousni self-assigned this Mar 20, 2023
@yelhousni
Copy link
Contributor Author

Following #594, the last commit uses torus-based arithmetic for the entire final exp. This removes 323413 = ~323k constraints taking the whole BLS12-381 pairing down to 2853961 = ~2.8M constraints. An additional 2136 can be saved when we only need to check that a pairing product is 1 (no need to decompress pairing result --> check equality in E6).

@yelhousni
Copy link
Contributor Author

To finish this PR, here is the total number of constraints for an emulated bls12-381 pairing over bn254 scalar field: 2702761 = ~2.7M

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.

Looks good. I only made the double method on E6 public to be consistent with other methods.

@yelhousni yelhousni merged commit 79be5a1 into develop Mar 23, 2023
@yelhousni yelhousni deleted the feat/bls12-381-pairing branch March 23, 2023 17:19
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