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

Rust implementation of the MultiPairingCheck calldata builder #202

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
3f81f06
Saving temporary work file
raugfer Sep 17, 2024
609507e
Further simplification of test_mpc.py
raugfer Sep 18, 2024
2b7dfb0
Another pass of simplification to test_mpc.py
raugfer Sep 18, 2024
13576ed
Further simplification of test_mpc.py
raugfer Sep 18, 2024
f5a9a6b
More simplification to test_mpc.py
raugfer Sep 18, 2024
b43be9b
Minor changes to test_mpc.py
raugfer Sep 18, 2024
d5d6983
Another pass of simplification to test_mpc.py
raugfer Sep 19, 2024
fc8bd2f
Another pass of simplification to test_mpc.py
raugfer Sep 19, 2024
bbfcb63
Yet another pass simplifying test_mpc.py
raugfer Sep 19, 2024
d2947db
Renames method
raugfer Sep 19, 2024
338a6be
Another pass of simplification to test_mpc.py
raugfer Sep 19, 2024
c71fa49
Initial rust implementation of MPC calldata builder
raugfer Sep 20, 2024
65ac213
Merge branch 'main' into mpc-calldata-builder
raugfer Sep 20, 2024
6148841
Adds frobenius map generator as comments
raugfer Sep 20, 2024
3d411a9
Adds a module to calculate the frobenius
raugfer Sep 20, 2024
fede1b9
Adds loop_counter definitions
raugfer Sep 20, 2024
31605b5
Completes the preliminary implementation of miller_loop
raugfer Sep 20, 2024
3417315
Completes the preliminary implementation of multi_pairing_check
raugfer Sep 20, 2024
575ebe6
Completes the preliminary implementation of build_mpcheck_hint
raugfer Sep 20, 2024
d1d41bb
Adds Python and TypeScript bidings for mpc_calldata_builder
raugfer Sep 20, 2024
0799c56
Adds test to compare MPC calldata generated by python/rust
raugfer Sep 20, 2024
871ce71
Adds handle_curve for mpc_calldata
raugfer Sep 20, 2024
11ae828
Tentative implementation of mpc calldata serialization
raugfer Sep 20, 2024
d98a517
Decouples python binding from ark_ff for final_exp_witness
raugfer Sep 23, 2024
0a3a160
Implements nondeterministic_extension_field_div
raugfer Sep 23, 2024
66cca91
Implements get_root_and_scaling_factor
raugfer Sep 24, 2024
b9343ce
Corrects bridging between Python and Rust for the MPC bindings
raugfer Sep 24, 2024
464729f
Fixes condition in g2point
raugfer Sep 24, 2024
740871d
Adds padding to polynomials
raugfer Sep 24, 2024
be91111
Comments assertions temporarily
raugfer Sep 24, 2024
3ace031
Fixes bug and adds tests as comments
raugfer Sep 24, 2024
8bd6a67
Fixes warnings
raugfer Sep 24, 2024
217fd92
Fixes nondeterministic_extension_field_div and adds tests to extf_mul
raugfer Sep 24, 2024
8a67dc4
Adds tests for get_final_exp_witness
raugfer Sep 24, 2024
771164d
Simplifies bit cases
raugfer Sep 24, 2024
0930651
Adds tests and fixes to get_root_and_scaling_factor
raugfer Sep 24, 2024
d7424ee
Adds tests for bit cases in multi_pairing_check.rs
raugfer Sep 24, 2024
44e4de4
Fixes extf_mul parameters in multi_pairing_check
raugfer Sep 24, 2024
1c8ba4a
Adds a test for extf_inv
raugfer Sep 24, 2024
aadf7c1
Rewrites multi_pairing_check loop
raugfer Sep 24, 2024
2e4eff6
Fixes silly bugs when copyiong points and flagging 288 bits
raugfer Sep 24, 2024
30215e7
Adds test for result size for mpc_calldata_builder tests
raugfer Sep 25, 2024
3cc1a32
Updates wasm-pack generated files
raugfer Sep 25, 2024
9a844e0
Applies Python formatting
raugfer Sep 25, 2024
aaf40d4
Applies Rust formatting
raugfer Sep 25, 2024
a98a207
Removes trailing space
raugfer Sep 25, 2024
c76187c
Moves G1G2Pair to its own module
raugfer Sep 25, 2024
35c117a
Applies cargo clippy fixes
raugfer Sep 25, 2024
67ae411
Applies cargo clippy fixes
raugfer Sep 25, 2024
55aecb5
Removes curve_id parameter from internal calls
raugfer Sep 25, 2024
d55066d
Tightens type Vec<FieldElement> to [FieldElement; 12] wherever it app…
raugfer Sep 25, 2024
2095d38
Adds E2, E6, and E12 as type parameters to be able to use Degree*Exte…
raugfer Sep 26, 2024
830a14c
Temporarily adds test call data values for comparison
raugfer Sep 26, 2024
ca3ff18
Changes the definition of G2Point to use Degree2ExtensionField
raugfer Sep 26, 2024
5e1b546
Rewrites G2Point::new
raugfer Sep 26, 2024
de9b3b8
Uses G1Point/G2Point types throught mpc caldata builder
raugfer Sep 26, 2024
7c7235c
Replaces [FieldElement<F>; 2] by FieldElement<E2>
raugfer Sep 27, 2024
7acda2a
Replaces [FieldElement<F>; 12] by Polynomial<F> at various places
raugfer Sep 27, 2024
2304f72
Replaces [FieldElement<F>; 12] by Polynomial<F> at various places
raugfer Sep 27, 2024
f6802d4
Applies most of cargo clippy suggestions
raugfer Sep 27, 2024
8ee776e
Review of extf_mul.rs
raugfer Sep 30, 2024
5df8556
Reviews frobenius.rs
raugfer Sep 30, 2024
127ef5b
Merge branch 'main' into mpc-calldata-builder
raugfer Sep 30, 2024
5ffe7fb
Review of mpc_calldata.rs
raugfer Sep 30, 2024
e90a9a6
Reviews multi_pairing_check.rs
raugfer Sep 30, 2024
135553a
Review of G2Point and FieldElement<E2>
raugfer Sep 30, 2024
8f1375d
Updates files generated by wasm-pack
raugfer Sep 30, 2024
248c5d3
Merge branch 'main' into mpc-calldata-builder
feltroidprime Oct 1, 2024
9ac0f5a
Merge branch 'main' into mpc-calldata-builder
raugfer Oct 1, 2024
c65341e
Merge branch 'main' into mpc-calldata-builder
raugfer Oct 3, 2024
54121e5
Replaces if chain by pattern matching
raugfer Oct 3, 2024
84a3344
Merges <function> with <function>_step in miller loop implementation
raugfer Oct 3, 2024
86bcaaf
Moves compute_adding_slope/compute_adding_slope to G2Point and other …
raugfer Oct 3, 2024
4a5b125
Provides better naming and comments for filter_elements/compact_elements
raugfer Oct 3, 2024
73737fe
Fixes default option handling in garaga_ts
raugfer Oct 3, 2024
444fdc6
Removes test_mpc.py
raugfer Oct 3, 2024
9e5864d
Improves the handling of error, specially when pairing result is not 1
raugfer Oct 3, 2024
7a42d88
Removes long and redundand mpc calldata tests
raugfer Oct 3, 2024
f55545a
Fixes Rust use warning
raugfer Oct 3, 2024
f28d169
Updates files generated by wasm-pack
raugfer Oct 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion hydra/garaga/starknet/tests_and_calldata_generators/mpcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from dataclasses import dataclass
from functools import lru_cache

from garaga import garaga_rs
from garaga import modulo_circuit_structs as structs
from garaga.algebra import Polynomial, PyFelt
from garaga.definitions import CurveID, G1G2Pair, get_base_field, get_irreducible_poly
Expand Down Expand Up @@ -325,7 +326,25 @@ def to_cairo_1_test(self):
"""
return code

def serialize_to_calldata(self) -> list[int]:
def _serialize_to_calldata_rust(self) -> list[int]:
return garaga_rs.mpc_calldata_builder(
self.curve_id.value,
[element.value for pair in self.pairs for element in pair.to_pyfelt_list()],
self.n_fixed_g2,
(
[element.value for element in self.public_pair.to_pyfelt_list()]
if self.public_pair is not None
else []
),
)

def serialize_to_calldata(
self,
use_rust=False,
) -> list[int]:
if use_rust:
return self._serialize_to_calldata_rust()

mpcheck_hint, small_Q = self.build_mpcheck_hint()

call_data: list[int] = []
Expand Down
35 changes: 34 additions & 1 deletion tests/hydra/starknet/test_calldata.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,47 @@
import pytest

from garaga.definitions import CURVES, CurveID, G1Point
from garaga.precompiled_circuits.multi_pairing_check import get_pairing_check_input
from garaga.starknet.tests_and_calldata_generators.mpcheck import MPCheckCalldataBuilder
from garaga.starknet.tests_and_calldata_generators.msm import MSMCalldataBuilder

# Define the curves to be tested
curves = list(CurveID)


@pytest.mark.parametrize("curve_id", [CurveID.BN254, CurveID.BLS12_381])
@pytest.mark.parametrize("mpc_size", [2, 3])
@pytest.mark.parametrize("n_fixed_g2", [2])
@pytest.mark.parametrize("include_m", [True, False])
def test_mpc_calldata_builder(
curve_id,
mpc_size,
n_fixed_g2,
include_m,
):
pairs, public_pair = get_pairing_check_input(
curve_id=curve_id,
n_pairs=mpc_size,
include_m=include_m,
return_pairs=True,
)

mpc = MPCheckCalldataBuilder(
curve_id=curve_id,
pairs=pairs,
n_fixed_g2=n_fixed_g2,
public_pair=public_pair,
)

calldata1 = mpc.serialize_to_calldata(use_rust=False)

calldata2 = mpc.serialize_to_calldata(use_rust=True)

assert calldata1 == calldata2


@pytest.mark.parametrize("curve_id", curves)
@pytest.mark.parametrize("msm_size", range(1, 2))
@pytest.mark.parametrize("msm_size", [1, 2])
@pytest.mark.parametrize("include_digits_decomposition", [True, False])
@pytest.mark.parametrize("include_points_and_scalars", [True, False])
@pytest.mark.parametrize("serialize_as_pure_felt252_array", [True, False])
Expand Down
Loading
Loading