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

u288 struct + calldata refactors #187

Merged
merged 24 commits into from
Sep 9, 2024
Merged

u288 struct + calldata refactors #187

merged 24 commits into from
Sep 9, 2024

Conversation

feltroidprime
Copy link
Collaborator

@feltroidprime feltroidprime commented Sep 5, 2024

Fixes #182
Notable changes :

  • Cairo/Scarb updated to 2.8.2.

src/src

definitions.cairo

  • Adds a u288 struct that holds 3 u96 limbs + impl Serde for it.
  • Make E12D struct generic on <T> (in practice T=u384 or u288) + impl Serde for T=u288 & 384.
  • Made G2Line struct also dependent on T. (Serde not needed as those are hardcoded)
  • Made MillerLoopResultScalingFactor also dependent on T.
  • Implement the corelib::num::traits::One & Zero for u384 & u288
  • Implement the corelib::num::traits::One for E12D<u384> and E12D<u288>
  • Implement corelib::num::traits::Zero for G1Point to represent the point at infinity. Removes the G1PointInfinity struct.
  • Removes the E12DDefinitions trait (replaced by the num traits)
  • Moves the E12D.conjugate method of the E12DDefinitions trait to a function in groth16.cairo

ec_ops.cairo

  • Use the Zero trait instead of G1PointInfinity

Splitted utils.cairo into utils/hashing.cairo and utils/neg_3.cairo

hashing.cairo

  • Added functions to hash based on u384 or u288.

pairing_check.cairo

  • Update MPCheckHint structs to depend on u288 (bn) or u384 (bls)
  • Update mpcheck_2P_2F functions to work with the updates in definitions.cairo & hashing.cairo

groth16.cairo

  • Update mpcheck_3P_2F functions to work with the updates in definitions.cairo & hashing.cairo

core/circuit.cairo

  • Add a next_u288 method for circuit_inputs.

hydra

  • Adaptations to circuit compiler to support u288 and u288 related generic structs.
  • Adaptations to groth16 generators to support u288.
  • Groth16 calldata is now serialized as pure felt252 array instead of structs. The signature of groth16 contracts is now simply
fn verify_groth16_proof_bn254(
            ref self: ContractState, full_proof_with_hints: Span<felt252>,
        ) -> bool { 
  • get_pairing_check_inputin multi_pairing_check.py generates input that looks like bls signature instead of previously ((P, Q), (-P, Q)) . This changes the tests for 2P_2F cases in pairing_test.cairo, as the previous hint content was sparse and not realistic.

src/contracts

  • Groth16 contracts examples re-generated following the mentioned changes (using make rewrite)

BN254 groth16 now takes 9% less steps to verify thx to this, uses less calldata, and contracts uses a bit less bytecode.

@feltroidprime feltroidprime marked this pull request as ready for review September 9, 2024 16:12
@feltroidprime feltroidprime changed the title Calldata refactor introduce u288 struct + calldata refactors Sep 9, 2024
@feltroidprime feltroidprime changed the title introduce u288 struct + calldata refactors u288 struct + calldata refactors Sep 9, 2024
@feltroidprime feltroidprime merged commit 7e16413 into main Sep 9, 2024
22 checks passed
@feltroidprime feltroidprime deleted the calldata-refactor branch September 9, 2024 19:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: Improve serialization and calldata size for all curves except BLS
1 participant