From 2857fcbbe928edaaa734825c741689a0fa7ec8bb Mon Sep 17 00:00:00 2001 From: feltroidprime Date: Sat, 27 Jul 2024 17:59:41 +0200 Subject: [PATCH] CI: cairoZero format, scarb test --- .github/workflows/cairo.yml | 3 +- .github/workflows/fustat.yml | 30 + .github/workflows/hydra.yml | 2 +- hydra/algebra.py | 1 - hydra/definitions.py | 4 +- hydra/precompiled_circuits/all_circuits.py | 62 +- hydra/precompiled_circuits/final_exp.py | 83 +- src/cairo/src/circuits/extf_mul.cairo | 1439 +++++--------------- src/fustat/definitions.cairo | 2 +- tools/make/fustat_format_check.sh | 27 + tools/make/setup.sh | 39 + 11 files changed, 497 insertions(+), 1195 deletions(-) create mode 100644 .github/workflows/fustat.yml create mode 100755 tools/make/fustat_format_check.sh diff --git a/.github/workflows/cairo.yml b/.github/workflows/cairo.yml index 2dd9f62a..a4eb513c 100644 --- a/.github/workflows/cairo.yml +++ b/.github/workflows/cairo.yml @@ -3,7 +3,7 @@ name: Cairo 1 tests on: push: merge_group: - pull_request: + pull_request_target: jobs: check: @@ -15,3 +15,4 @@ jobs: scarb-version: "2.7.0-rc.3" - run: scarb fmt --check working-directory: src/cairo + - run: cd src/cairo && scarb test \ No newline at end of file diff --git a/.github/workflows/fustat.yml b/.github/workflows/fustat.yml new file mode 100644 index 00000000..4430c434 --- /dev/null +++ b/.github/workflows/fustat.yml @@ -0,0 +1,30 @@ +name: Cairo Zero (Fustat) tests + +on: + push: + merge_group: + pull_request_target: + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Set up Python 3.10.14 + uses: actions/setup-python@v2 + with: + python-version: 3.10.14 + - name: Install dependencies + run: | + python -m venv venv + source venv/bin/activate + echo 'export PYTHONPATH="$PWD:$PYTHONPATH"' >> venv/bin/activate + pip install cairo-lang==0.13.2a0 + - name: Install GNU Parallel + run: sudo apt-get update && sudo apt-get install -y parallel + - name: Check cairo Formatting + run: | + source venv/bin/activate && ./tools/make/fustat_format_check.sh + - name: Compile cairo files + run: | + source venv/bin/activate && make build \ No newline at end of file diff --git a/.github/workflows/hydra.yml b/.github/workflows/hydra.yml index 91ac058d..c13e0e57 100644 --- a/.github/workflows/hydra.yml +++ b/.github/workflows/hydra.yml @@ -3,7 +3,7 @@ name: Hydra backend test on: push: merge_group: - pull_request: + pull_request_target: jobs: test: diff --git a/hydra/algebra.py b/hydra/algebra.py index 4386902a..aba6e641 100644 --- a/hydra/algebra.py +++ b/hydra/algebra.py @@ -385,7 +385,6 @@ class Polynomial(Generic[T]): Parameters : coefficients (list[PyFelt | ModuloCircuitElement]): A list of coefficients for the polynomial. - raw_init (bool): A flag indicating whether to initialize the polynomial directly from a list of coefficients of PyFelt type. Magic Methods Summary: - __init__: Initializes a polynomial with a list of coefficients. diff --git a/hydra/definitions.py b/hydra/definitions.py index e60667c9..836b3e83 100644 --- a/hydra/definitions.py +++ b/hydra/definitions.py @@ -436,8 +436,7 @@ def get_irreducible_poly(curve_id: int | CurveID, extension_degree: int) -> Poly return Polynomial( coefficients=[ field(x) for x in CURVES[curve_id].irreducible_polys[extension_degree] - ], - raw_init=True, + ] ) @@ -1017,5 +1016,6 @@ def replace_consecutive_zeros(lst): i += 1 return result + if __name__ == "__main__": pass diff --git a/hydra/precompiled_circuits/all_circuits.py b/hydra/precompiled_circuits/all_circuits.py index c53f8f02..591c34bb 100644 --- a/hydra/precompiled_circuits/all_circuits.py +++ b/hydra/precompiled_circuits/all_circuits.py @@ -4,25 +4,45 @@ from random import randint, seed import hydra.modulo_circuit_structs as structs -from hydra.definitions import (BLS12_381_ID, BN254_ID, CURVES, N_LIMBS, STARK, - CurveID, G1Point, G2Point, get_base_field, - get_irreducible_poly) -from hydra.extension_field_modulo_circuit import (ExtensionFieldModuloCircuit, - ModuloCircuit, - ModuloCircuitElement, PyFelt, - WriteOps) +from hydra.definitions import ( + BLS12_381_ID, + BN254_ID, + CURVES, + N_LIMBS, + STARK, + CurveID, + G1Point, + G2Point, + get_base_field, + get_irreducible_poly, +) +from hydra.extension_field_modulo_circuit import ( + ExtensionFieldModuloCircuit, + ModuloCircuit, + ModuloCircuitElement, + PyFelt, + WriteOps, +) from hydra.hints import neg_3 from hydra.hints.ecip import slope_intercept from hydra.hints.io import int_array_to_u384_array, int_to_u384 -from hydra.modulo_circuit_structs import (E12D, BLSProcessedPair, - BNProcessedPair, - Cairo1SerializableStruct, - G1PointCircuit, G2PointCircuit, - MillerLoopResultScalingFactor, u384) -from hydra.precompiled_circuits import (final_exp, multi_miller_loop, - multi_pairing_check) -from hydra.precompiled_circuits.ec import (BasicEC, DerivePointFromX, - ECIPCircuits, IsOnCurveCircuit) +from hydra.modulo_circuit_structs import ( + E12D, + BLSProcessedPair, + BNProcessedPair, + Cairo1SerializableStruct, + G1PointCircuit, + G2PointCircuit, + MillerLoopResultScalingFactor, + u384, +) +from hydra.precompiled_circuits import final_exp, multi_miller_loop, multi_pairing_check +from hydra.precompiled_circuits.ec import ( + BasicEC, + DerivePointFromX, + ECIPCircuits, + IsOnCurveCircuit, +) from tools.gnark_cli import GnarkCLI seed(0) @@ -2794,11 +2814,11 @@ def format_cairo_files_in_parallel(filenames, compilation_mode): "params": None, "filename": "ec", }, - CircuitID.FP12_MUL: { - "class": FP12MulCircuit, - "params": None, - "filename": "extf_mul", - }, + # CircuitID.FP12_MUL: { + # "class": FP12MulCircuit, + # "params": None, + # "filename": "extf_mul", + # }, CircuitID.ADD_EC_POINT: { "class": AddECPointCircuit, "params": None, diff --git a/hydra/precompiled_circuits/final_exp.py b/hydra/precompiled_circuits/final_exp.py index 3d36801b..de07c56f 100644 --- a/hydra/precompiled_circuits/final_exp.py +++ b/hydra/precompiled_circuits/final_exp.py @@ -2,16 +2,27 @@ from enum import Enum from random import randint -from hydra.definitions import (BLS12_381_ID, BN254_ID, CURVES, STARK, Curve, - CurveID, get_sparsity) -from hydra.extension_field_modulo_circuit import (AccPolyInstructionType, - AccumulatePolyInstructions, - EuclideanPolyAccumulator, - ExtensionFieldModuloCircuit, - ModuloCircuitElement, - Polynomial, PyFelt) -from hydra.hints.extf_mul import (nondeterministic_extension_field_mul_divmod, - nondeterministic_square_torus) +from hydra.definitions import ( + BLS12_381_ID, + BN254_ID, + CURVES, + STARK, + CurveID, + get_sparsity, +) +from hydra.extension_field_modulo_circuit import ( + AccPolyInstructionType, + AccumulatePolyInstructions, + EuclideanPolyAccumulator, + ExtensionFieldModuloCircuit, + ModuloCircuitElement, + Polynomial, + PyFelt, +) +from hydra.hints.extf_mul import ( + nondeterministic_extension_field_mul_divmod, + nondeterministic_square_torus, +) from hydra.hints.frobenius import generate_frobenius_maps, get_V_torus_powers from hydra.modulo_circuit import WriteOps from hydra.poseidon_transcript import CairoPoseidonTranscript @@ -456,27 +467,31 @@ def test_final_exp(curve_id: CurveID): if __name__ == "__main__": import random - from hydra.definitions import (CurveID, Polynomial, get_base_field, - get_irreducible_poly) - - def test_frobenius_torus(): - from archive_tmp.bn254.pairing_final_exp import frobenius_torus - - field = get_base_field(CurveID.BN254.value) - X = [field(random.randint(0, field.p - 1)) for _ in range(6)] - t = FinalExpTorusCircuit("test", CurveID.BN254.value, 6) - t.create_powers_of_Z(field(2)) - X = t.write_elements(X) - XF = t.frobenius_torus(X, 1) - # Xpoly = Polynomial([x.felt for x in X]) - # XFpoly = Xpoly.pow(field.p, get_irreducible_poly(CurveID.BN254.value, )) - # assert t.finalize_circuit() - # t.values_segment = t.values_segment.non_interactive_transform() - - TT = frobenius_torus([x.value for x in X]) - assert all(x.value == y for x, y in zip(XF, TT)) - - t.print_value_segment() - - test_final_exp(CurveID.BN254) - test_final_exp(CurveID.BLS12_381) + from hydra.definitions import ( + CurveID, + Polynomial, + get_base_field, + get_irreducible_poly, + ) + + # def test_frobenius_torus(): + # from archive_tmp.bn254.pairing_final_exp import frobenius_torus + + # field = get_base_field(CurveID.BN254.value) + # X = [field(random.randint(0, field.p - 1)) for _ in range(6)] + # t = FinalExpTorusCircuit("test", CurveID.BN254.value, 6) + # t.create_powers_of_Z(field(2)) + # X = t.write_elements(X) + # XF = t.frobenius_torus(X, 1) + # # Xpoly = Polynomial([x.felt for x in X]) + # # XFpoly = Xpoly.pow(field.p, get_irreducible_poly(CurveID.BN254.value, )) + # # assert t.finalize_circuit() + # # t.values_segment = t.values_segment.non_interactive_transform() + + # TT = frobenius_torus([x.value for x in X]) + # assert all(x.value == y for x, y in zip(XF, TT)) + + # t.print_value_segment() + + # test_final_exp(CurveID.BN254) + # test_final_exp(CurveID.BLS12_381) diff --git a/src/cairo/src/circuits/extf_mul.cairo b/src/cairo/src/circuits/extf_mul.cairo index 11bee0c2..62adc415 100644 --- a/src/cairo/src/circuits/extf_mul.cairo +++ b/src/cairo/src/circuits/extf_mul.cairo @@ -10,6 +10,7 @@ use garaga::definitions::{ get_a, get_b, get_p, get_g, get_min_one, G1Point, G2Point, E12D, E12DMulQuotient, G1G2Pair, BNProcessedPair, BLSProcessedPair, MillerLoopResultScalingFactor }; +use garaga::ec_ops::{SlopeInterceptOutput, FunctionFeltEvaluations, FunctionFelt}; use core::option::Option; fn run_BLS12_381_FP12_MUL_ASSERT_ONE_circuit( @@ -191,197 +192,6 @@ fn run_BLS12_381_FP12_MUL_ASSERT_ONE_circuit( let check: u384 = outputs.get_output(t81); return (check,); } -fn run_BLS12_381_FP12_MUL_circuit(mut input: Array) -> Array { - // CONSTANT stack - let in0 = CE::> {}; // 0x2 - let in1 = CE::> {}; // -0x2 % p - - // INPUT stack - let (in2, in3) = (CE::> {}, CE::> {}); - let (in4, in5) = (CE::> {}, CE::> {}); - let (in6, in7) = (CE::> {}, CE::> {}); - let (in8, in9) = (CE::> {}, CE::> {}); - let (in10, in11) = (CE::> {}, CE::> {}); - let (in12, in13) = (CE::> {}, CE::> {}); - let (in14, in15) = (CE::> {}, CE::> {}); - let (in16, in17) = (CE::> {}, CE::> {}); - let (in18, in19) = (CE::> {}, CE::> {}); - let (in20, in21) = (CE::> {}, CE::> {}); - let (in22, in23) = (CE::> {}, CE::> {}); - let (in24, in25) = (CE::> {}, CE::> {}); - - // COMMIT stack - let (in26, in27) = (CE::> {}, CE::> {}); - let (in28, in29) = (CE::> {}, CE::> {}); - let (in30, in31) = (CE::> {}, CE::> {}); - let (in32, in33) = (CE::> {}, CE::> {}); - let (in34, in35) = (CE::> {}, CE::> {}); - let (in36, in37) = (CE::> {}, CE::> {}); - let (in38, in39) = (CE::> {}, CE::> {}); - let (in40, in41) = (CE::> {}, CE::> {}); - let (in42, in43) = (CE::> {}, CE::> {}); - let (in44, in45) = (CE::> {}, CE::> {}); - let (in46, in47) = (CE::> {}, CE::> {}); - let in48 = CE::> {}; - - // FELT stack - let (in49, in50) = (CE::> {}, CE::> {}); - let t0 = circuit_mul(in50, in50); // Compute z^2 - let t1 = circuit_mul(t0, in50); // Compute z^3 - let t2 = circuit_mul(t1, in50); // Compute z^4 - let t3 = circuit_mul(t2, in50); // Compute z^5 - let t4 = circuit_mul(t3, in50); // Compute z^6 - let t5 = circuit_mul(t4, in50); // Compute z^7 - let t6 = circuit_mul(t5, in50); // Compute z^8 - let t7 = circuit_mul(t6, in50); // Compute z^9 - let t8 = circuit_mul(t7, in50); // Compute z^10 - let t9 = circuit_mul(t8, in50); // Compute z^11 - let t10 = circuit_mul(t9, in50); // Compute z^12 - let t11 = circuit_mul(in3, in50); // Eval UnnamedPoly step coeff_1 * z^1 - let t12 = circuit_add(in2, t11); // Eval UnnamedPoly step + (coeff_1 * z^1) - let t13 = circuit_mul(in4, t0); // Eval UnnamedPoly step coeff_2 * z^2 - let t14 = circuit_add(t12, t13); // Eval UnnamedPoly step + (coeff_2 * z^2) - let t15 = circuit_mul(in5, t1); // Eval UnnamedPoly step coeff_3 * z^3 - let t16 = circuit_add(t14, t15); // Eval UnnamedPoly step + (coeff_3 * z^3) - let t17 = circuit_mul(in6, t2); // Eval UnnamedPoly step coeff_4 * z^4 - let t18 = circuit_add(t16, t17); // Eval UnnamedPoly step + (coeff_4 * z^4) - let t19 = circuit_mul(in7, t3); // Eval UnnamedPoly step coeff_5 * z^5 - let t20 = circuit_add(t18, t19); // Eval UnnamedPoly step + (coeff_5 * z^5) - let t21 = circuit_mul(in8, t4); // Eval UnnamedPoly step coeff_6 * z^6 - let t22 = circuit_add(t20, t21); // Eval UnnamedPoly step + (coeff_6 * z^6) - let t23 = circuit_mul(in9, t5); // Eval UnnamedPoly step coeff_7 * z^7 - let t24 = circuit_add(t22, t23); // Eval UnnamedPoly step + (coeff_7 * z^7) - let t25 = circuit_mul(in10, t6); // Eval UnnamedPoly step coeff_8 * z^8 - let t26 = circuit_add(t24, t25); // Eval UnnamedPoly step + (coeff_8 * z^8) - let t27 = circuit_mul(in11, t7); // Eval UnnamedPoly step coeff_9 * z^9 - let t28 = circuit_add(t26, t27); // Eval UnnamedPoly step + (coeff_9 * z^9) - let t29 = circuit_mul(in12, t8); // Eval UnnamedPoly step coeff_10 * z^10 - let t30 = circuit_add(t28, t29); // Eval UnnamedPoly step + (coeff_10 * z^10) - let t31 = circuit_mul(in13, t9); // Eval UnnamedPoly step coeff_11 * z^11 - let t32 = circuit_add(t30, t31); // Eval UnnamedPoly step + (coeff_11 * z^11) - let t33 = circuit_mul(in15, in50); // Eval UnnamedPoly step coeff_1 * z^1 - let t34 = circuit_add(in14, t33); // Eval UnnamedPoly step + (coeff_1 * z^1) - let t35 = circuit_mul(in16, t0); // Eval UnnamedPoly step coeff_2 * z^2 - let t36 = circuit_add(t34, t35); // Eval UnnamedPoly step + (coeff_2 * z^2) - let t37 = circuit_mul(in17, t1); // Eval UnnamedPoly step coeff_3 * z^3 - let t38 = circuit_add(t36, t37); // Eval UnnamedPoly step + (coeff_3 * z^3) - let t39 = circuit_mul(in18, t2); // Eval UnnamedPoly step coeff_4 * z^4 - let t40 = circuit_add(t38, t39); // Eval UnnamedPoly step + (coeff_4 * z^4) - let t41 = circuit_mul(in19, t3); // Eval UnnamedPoly step coeff_5 * z^5 - let t42 = circuit_add(t40, t41); // Eval UnnamedPoly step + (coeff_5 * z^5) - let t43 = circuit_mul(in20, t4); // Eval UnnamedPoly step coeff_6 * z^6 - let t44 = circuit_add(t42, t43); // Eval UnnamedPoly step + (coeff_6 * z^6) - let t45 = circuit_mul(in21, t5); // Eval UnnamedPoly step coeff_7 * z^7 - let t46 = circuit_add(t44, t45); // Eval UnnamedPoly step + (coeff_7 * z^7) - let t47 = circuit_mul(in22, t6); // Eval UnnamedPoly step coeff_8 * z^8 - let t48 = circuit_add(t46, t47); // Eval UnnamedPoly step + (coeff_8 * z^8) - let t49 = circuit_mul(in23, t7); // Eval UnnamedPoly step coeff_9 * z^9 - let t50 = circuit_add(t48, t49); // Eval UnnamedPoly step + (coeff_9 * z^9) - let t51 = circuit_mul(in24, t8); // Eval UnnamedPoly step coeff_10 * z^10 - let t52 = circuit_add(t50, t51); // Eval UnnamedPoly step + (coeff_10 * z^10) - let t53 = circuit_mul(in25, t9); // Eval UnnamedPoly step coeff_11 * z^11 - let t54 = circuit_add(t52, t53); // Eval UnnamedPoly step + (coeff_11 * z^11) - let t55 = circuit_mul(t32, t54); - let t56 = circuit_mul(in49, t55); - let t57 = circuit_mul(in49, in26); - let t58 = circuit_mul(in49, in27); - let t59 = circuit_mul(in49, in28); - let t60 = circuit_mul(in49, in29); - let t61 = circuit_mul(in49, in30); - let t62 = circuit_mul(in49, in31); - let t63 = circuit_mul(in49, in32); - let t64 = circuit_mul(in49, in33); - let t65 = circuit_mul(in49, in34); - let t66 = circuit_mul(in49, in35); - let t67 = circuit_mul(in49, in36); - let t68 = circuit_mul(in49, in37); - let t69 = circuit_mul(in39, in50); // Eval UnnamedPoly step coeff_1 * z^1 - let t70 = circuit_add(in38, t69); // Eval UnnamedPoly step + (coeff_1 * z^1) - let t71 = circuit_mul(in40, t0); // Eval UnnamedPoly step coeff_2 * z^2 - let t72 = circuit_add(t70, t71); // Eval UnnamedPoly step + (coeff_2 * z^2) - let t73 = circuit_mul(in41, t1); // Eval UnnamedPoly step coeff_3 * z^3 - let t74 = circuit_add(t72, t73); // Eval UnnamedPoly step + (coeff_3 * z^3) - let t75 = circuit_mul(in42, t2); // Eval UnnamedPoly step coeff_4 * z^4 - let t76 = circuit_add(t74, t75); // Eval UnnamedPoly step + (coeff_4 * z^4) - let t77 = circuit_mul(in43, t3); // Eval UnnamedPoly step coeff_5 * z^5 - let t78 = circuit_add(t76, t77); // Eval UnnamedPoly step + (coeff_5 * z^5) - let t79 = circuit_mul(in44, t4); // Eval UnnamedPoly step coeff_6 * z^6 - let t80 = circuit_add(t78, t79); // Eval UnnamedPoly step + (coeff_6 * z^6) - let t81 = circuit_mul(in45, t5); // Eval UnnamedPoly step coeff_7 * z^7 - let t82 = circuit_add(t80, t81); // Eval UnnamedPoly step + (coeff_7 * z^7) - let t83 = circuit_mul(in46, t6); // Eval UnnamedPoly step coeff_8 * z^8 - let t84 = circuit_add(t82, t83); // Eval UnnamedPoly step + (coeff_8 * z^8) - let t85 = circuit_mul(in47, t7); // Eval UnnamedPoly step coeff_9 * z^9 - let t86 = circuit_add(t84, t85); // Eval UnnamedPoly step + (coeff_9 * z^9) - let t87 = circuit_mul(in48, t8); // Eval UnnamedPoly step coeff_10 * z^10 - let t88 = circuit_add(t86, t87); // Eval UnnamedPoly step + (coeff_10 * z^10) - let t89 = circuit_mul(in1, t4); // Eval sparse poly UnnamedPoly step coeff_6 * z^6 - let t90 = circuit_add(in0, t89); // Eval sparse poly UnnamedPoly step + coeff_6 * z^6 - let t91 = circuit_add(t90, t10); // Eval sparse poly UnnamedPoly step + 1*z^12 - let t92 = circuit_mul(t58, in50); // Eval UnnamedPoly step coeff_1 * z^1 - let t93 = circuit_add(t57, t92); // Eval UnnamedPoly step + (coeff_1 * z^1) - let t94 = circuit_mul(t59, t0); // Eval UnnamedPoly step coeff_2 * z^2 - let t95 = circuit_add(t93, t94); // Eval UnnamedPoly step + (coeff_2 * z^2) - let t96 = circuit_mul(t60, t1); // Eval UnnamedPoly step coeff_3 * z^3 - let t97 = circuit_add(t95, t96); // Eval UnnamedPoly step + (coeff_3 * z^3) - let t98 = circuit_mul(t61, t2); // Eval UnnamedPoly step coeff_4 * z^4 - let t99 = circuit_add(t97, t98); // Eval UnnamedPoly step + (coeff_4 * z^4) - let t100 = circuit_mul(t62, t3); // Eval UnnamedPoly step coeff_5 * z^5 - let t101 = circuit_add(t99, t100); // Eval UnnamedPoly step + (coeff_5 * z^5) - let t102 = circuit_mul(t63, t4); // Eval UnnamedPoly step coeff_6 * z^6 - let t103 = circuit_add(t101, t102); // Eval UnnamedPoly step + (coeff_6 * z^6) - let t104 = circuit_mul(t64, t5); // Eval UnnamedPoly step coeff_7 * z^7 - let t105 = circuit_add(t103, t104); // Eval UnnamedPoly step + (coeff_7 * z^7) - let t106 = circuit_mul(t65, t6); // Eval UnnamedPoly step coeff_8 * z^8 - let t107 = circuit_add(t105, t106); // Eval UnnamedPoly step + (coeff_8 * z^8) - let t108 = circuit_mul(t66, t7); // Eval UnnamedPoly step coeff_9 * z^9 - let t109 = circuit_add(t107, t108); // Eval UnnamedPoly step + (coeff_9 * z^9) - let t110 = circuit_mul(t67, t8); // Eval UnnamedPoly step coeff_10 * z^10 - let t111 = circuit_add(t109, t110); // Eval UnnamedPoly step + (coeff_10 * z^10) - let t112 = circuit_mul(t68, t9); // Eval UnnamedPoly step coeff_11 * z^11 - let t113 = circuit_add(t111, t112); // Eval UnnamedPoly step + (coeff_11 * z^11) - let t114 = circuit_mul(t88, t91); - let t115 = circuit_add(t114, t113); - let t116 = circuit_sub(t115, t56); - - let modulus = TryInto::< - _, CircuitModulus - >::try_into( - [ - 54880396502181392957329877675, - 31935979117156477062286671870, - 20826981314825584179608359615, - 8047903782086192180586325942 - ] - ) - .unwrap(); - - let mut circuit_inputs = (t116,).new_inputs(); - // Prefill constants: - circuit_inputs = circuit_inputs.next([0x2, 0x0, 0x0, 0x0]); - circuit_inputs = circuit_inputs - .next( - [ - 0xb153ffffb9feffffffffaaa9, - 0x6730d2a0f6b0f6241eabfffe, - 0x434bacd764774b84f38512bf, - 0x1a0111ea397fe69a4b1ba7b6 - ] - ); - - let mut input = input; - while let Option::Some(val) = input.pop_front() { - circuit_inputs = circuit_inputs.next(val); - }; - - let outputs = match circuit_inputs.done().eval(modulus) { - Result::Ok(outputs) => { outputs }, - Result::Err(_) => { panic!("Expected success") } - }; - let res = array![outputs.get_output(t116)]; - return res; -} - fn run_BN254_FP12_MUL_ASSERT_ONE_circuit(X: E12D, Y: E12D, Q: E12DMulQuotient, z: u384) -> (u384,) { // CONSTANT stack let in0 = CE::> {}; // 0x52 @@ -547,185 +357,6 @@ fn run_BN254_FP12_MUL_ASSERT_ONE_circuit(X: E12D, Y: E12D, Q: E12DMulQuotient, z let check: u384 = outputs.get_output(t81); return (check,); } -fn run_BN254_FP12_MUL_circuit(mut input: Array) -> Array { - // CONSTANT stack - let in0 = CE::> {}; // 0x52 - let in1 = CE::> {}; // -0x12 % p - - // INPUT stack - let (in2, in3) = (CE::> {}, CE::> {}); - let (in4, in5) = (CE::> {}, CE::> {}); - let (in6, in7) = (CE::> {}, CE::> {}); - let (in8, in9) = (CE::> {}, CE::> {}); - let (in10, in11) = (CE::> {}, CE::> {}); - let (in12, in13) = (CE::> {}, CE::> {}); - let (in14, in15) = (CE::> {}, CE::> {}); - let (in16, in17) = (CE::> {}, CE::> {}); - let (in18, in19) = (CE::> {}, CE::> {}); - let (in20, in21) = (CE::> {}, CE::> {}); - let (in22, in23) = (CE::> {}, CE::> {}); - let (in24, in25) = (CE::> {}, CE::> {}); - - // COMMIT stack - let (in26, in27) = (CE::> {}, CE::> {}); - let (in28, in29) = (CE::> {}, CE::> {}); - let (in30, in31) = (CE::> {}, CE::> {}); - let (in32, in33) = (CE::> {}, CE::> {}); - let (in34, in35) = (CE::> {}, CE::> {}); - let (in36, in37) = (CE::> {}, CE::> {}); - let (in38, in39) = (CE::> {}, CE::> {}); - let (in40, in41) = (CE::> {}, CE::> {}); - let (in42, in43) = (CE::> {}, CE::> {}); - let (in44, in45) = (CE::> {}, CE::> {}); - let (in46, in47) = (CE::> {}, CE::> {}); - let in48 = CE::> {}; - - // FELT stack - let (in49, in50) = (CE::> {}, CE::> {}); - let t0 = circuit_mul(in50, in50); // Compute z^2 - let t1 = circuit_mul(t0, in50); // Compute z^3 - let t2 = circuit_mul(t1, in50); // Compute z^4 - let t3 = circuit_mul(t2, in50); // Compute z^5 - let t4 = circuit_mul(t3, in50); // Compute z^6 - let t5 = circuit_mul(t4, in50); // Compute z^7 - let t6 = circuit_mul(t5, in50); // Compute z^8 - let t7 = circuit_mul(t6, in50); // Compute z^9 - let t8 = circuit_mul(t7, in50); // Compute z^10 - let t9 = circuit_mul(t8, in50); // Compute z^11 - let t10 = circuit_mul(t9, in50); // Compute z^12 - let t11 = circuit_mul(in3, in50); // Eval UnnamedPoly step coeff_1 * z^1 - let t12 = circuit_add(in2, t11); // Eval UnnamedPoly step + (coeff_1 * z^1) - let t13 = circuit_mul(in4, t0); // Eval UnnamedPoly step coeff_2 * z^2 - let t14 = circuit_add(t12, t13); // Eval UnnamedPoly step + (coeff_2 * z^2) - let t15 = circuit_mul(in5, t1); // Eval UnnamedPoly step coeff_3 * z^3 - let t16 = circuit_add(t14, t15); // Eval UnnamedPoly step + (coeff_3 * z^3) - let t17 = circuit_mul(in6, t2); // Eval UnnamedPoly step coeff_4 * z^4 - let t18 = circuit_add(t16, t17); // Eval UnnamedPoly step + (coeff_4 * z^4) - let t19 = circuit_mul(in7, t3); // Eval UnnamedPoly step coeff_5 * z^5 - let t20 = circuit_add(t18, t19); // Eval UnnamedPoly step + (coeff_5 * z^5) - let t21 = circuit_mul(in8, t4); // Eval UnnamedPoly step coeff_6 * z^6 - let t22 = circuit_add(t20, t21); // Eval UnnamedPoly step + (coeff_6 * z^6) - let t23 = circuit_mul(in9, t5); // Eval UnnamedPoly step coeff_7 * z^7 - let t24 = circuit_add(t22, t23); // Eval UnnamedPoly step + (coeff_7 * z^7) - let t25 = circuit_mul(in10, t6); // Eval UnnamedPoly step coeff_8 * z^8 - let t26 = circuit_add(t24, t25); // Eval UnnamedPoly step + (coeff_8 * z^8) - let t27 = circuit_mul(in11, t7); // Eval UnnamedPoly step coeff_9 * z^9 - let t28 = circuit_add(t26, t27); // Eval UnnamedPoly step + (coeff_9 * z^9) - let t29 = circuit_mul(in12, t8); // Eval UnnamedPoly step coeff_10 * z^10 - let t30 = circuit_add(t28, t29); // Eval UnnamedPoly step + (coeff_10 * z^10) - let t31 = circuit_mul(in13, t9); // Eval UnnamedPoly step coeff_11 * z^11 - let t32 = circuit_add(t30, t31); // Eval UnnamedPoly step + (coeff_11 * z^11) - let t33 = circuit_mul(in15, in50); // Eval UnnamedPoly step coeff_1 * z^1 - let t34 = circuit_add(in14, t33); // Eval UnnamedPoly step + (coeff_1 * z^1) - let t35 = circuit_mul(in16, t0); // Eval UnnamedPoly step coeff_2 * z^2 - let t36 = circuit_add(t34, t35); // Eval UnnamedPoly step + (coeff_2 * z^2) - let t37 = circuit_mul(in17, t1); // Eval UnnamedPoly step coeff_3 * z^3 - let t38 = circuit_add(t36, t37); // Eval UnnamedPoly step + (coeff_3 * z^3) - let t39 = circuit_mul(in18, t2); // Eval UnnamedPoly step coeff_4 * z^4 - let t40 = circuit_add(t38, t39); // Eval UnnamedPoly step + (coeff_4 * z^4) - let t41 = circuit_mul(in19, t3); // Eval UnnamedPoly step coeff_5 * z^5 - let t42 = circuit_add(t40, t41); // Eval UnnamedPoly step + (coeff_5 * z^5) - let t43 = circuit_mul(in20, t4); // Eval UnnamedPoly step coeff_6 * z^6 - let t44 = circuit_add(t42, t43); // Eval UnnamedPoly step + (coeff_6 * z^6) - let t45 = circuit_mul(in21, t5); // Eval UnnamedPoly step coeff_7 * z^7 - let t46 = circuit_add(t44, t45); // Eval UnnamedPoly step + (coeff_7 * z^7) - let t47 = circuit_mul(in22, t6); // Eval UnnamedPoly step coeff_8 * z^8 - let t48 = circuit_add(t46, t47); // Eval UnnamedPoly step + (coeff_8 * z^8) - let t49 = circuit_mul(in23, t7); // Eval UnnamedPoly step coeff_9 * z^9 - let t50 = circuit_add(t48, t49); // Eval UnnamedPoly step + (coeff_9 * z^9) - let t51 = circuit_mul(in24, t8); // Eval UnnamedPoly step coeff_10 * z^10 - let t52 = circuit_add(t50, t51); // Eval UnnamedPoly step + (coeff_10 * z^10) - let t53 = circuit_mul(in25, t9); // Eval UnnamedPoly step coeff_11 * z^11 - let t54 = circuit_add(t52, t53); // Eval UnnamedPoly step + (coeff_11 * z^11) - let t55 = circuit_mul(t32, t54); - let t56 = circuit_mul(in49, t55); - let t57 = circuit_mul(in49, in26); - let t58 = circuit_mul(in49, in27); - let t59 = circuit_mul(in49, in28); - let t60 = circuit_mul(in49, in29); - let t61 = circuit_mul(in49, in30); - let t62 = circuit_mul(in49, in31); - let t63 = circuit_mul(in49, in32); - let t64 = circuit_mul(in49, in33); - let t65 = circuit_mul(in49, in34); - let t66 = circuit_mul(in49, in35); - let t67 = circuit_mul(in49, in36); - let t68 = circuit_mul(in49, in37); - let t69 = circuit_mul(in39, in50); // Eval UnnamedPoly step coeff_1 * z^1 - let t70 = circuit_add(in38, t69); // Eval UnnamedPoly step + (coeff_1 * z^1) - let t71 = circuit_mul(in40, t0); // Eval UnnamedPoly step coeff_2 * z^2 - let t72 = circuit_add(t70, t71); // Eval UnnamedPoly step + (coeff_2 * z^2) - let t73 = circuit_mul(in41, t1); // Eval UnnamedPoly step coeff_3 * z^3 - let t74 = circuit_add(t72, t73); // Eval UnnamedPoly step + (coeff_3 * z^3) - let t75 = circuit_mul(in42, t2); // Eval UnnamedPoly step coeff_4 * z^4 - let t76 = circuit_add(t74, t75); // Eval UnnamedPoly step + (coeff_4 * z^4) - let t77 = circuit_mul(in43, t3); // Eval UnnamedPoly step coeff_5 * z^5 - let t78 = circuit_add(t76, t77); // Eval UnnamedPoly step + (coeff_5 * z^5) - let t79 = circuit_mul(in44, t4); // Eval UnnamedPoly step coeff_6 * z^6 - let t80 = circuit_add(t78, t79); // Eval UnnamedPoly step + (coeff_6 * z^6) - let t81 = circuit_mul(in45, t5); // Eval UnnamedPoly step coeff_7 * z^7 - let t82 = circuit_add(t80, t81); // Eval UnnamedPoly step + (coeff_7 * z^7) - let t83 = circuit_mul(in46, t6); // Eval UnnamedPoly step coeff_8 * z^8 - let t84 = circuit_add(t82, t83); // Eval UnnamedPoly step + (coeff_8 * z^8) - let t85 = circuit_mul(in47, t7); // Eval UnnamedPoly step coeff_9 * z^9 - let t86 = circuit_add(t84, t85); // Eval UnnamedPoly step + (coeff_9 * z^9) - let t87 = circuit_mul(in48, t8); // Eval UnnamedPoly step coeff_10 * z^10 - let t88 = circuit_add(t86, t87); // Eval UnnamedPoly step + (coeff_10 * z^10) - let t89 = circuit_mul(in1, t4); // Eval sparse poly UnnamedPoly step coeff_6 * z^6 - let t90 = circuit_add(in0, t89); // Eval sparse poly UnnamedPoly step + coeff_6 * z^6 - let t91 = circuit_add(t90, t10); // Eval sparse poly UnnamedPoly step + 1*z^12 - let t92 = circuit_mul(t58, in50); // Eval UnnamedPoly step coeff_1 * z^1 - let t93 = circuit_add(t57, t92); // Eval UnnamedPoly step + (coeff_1 * z^1) - let t94 = circuit_mul(t59, t0); // Eval UnnamedPoly step coeff_2 * z^2 - let t95 = circuit_add(t93, t94); // Eval UnnamedPoly step + (coeff_2 * z^2) - let t96 = circuit_mul(t60, t1); // Eval UnnamedPoly step coeff_3 * z^3 - let t97 = circuit_add(t95, t96); // Eval UnnamedPoly step + (coeff_3 * z^3) - let t98 = circuit_mul(t61, t2); // Eval UnnamedPoly step coeff_4 * z^4 - let t99 = circuit_add(t97, t98); // Eval UnnamedPoly step + (coeff_4 * z^4) - let t100 = circuit_mul(t62, t3); // Eval UnnamedPoly step coeff_5 * z^5 - let t101 = circuit_add(t99, t100); // Eval UnnamedPoly step + (coeff_5 * z^5) - let t102 = circuit_mul(t63, t4); // Eval UnnamedPoly step coeff_6 * z^6 - let t103 = circuit_add(t101, t102); // Eval UnnamedPoly step + (coeff_6 * z^6) - let t104 = circuit_mul(t64, t5); // Eval UnnamedPoly step coeff_7 * z^7 - let t105 = circuit_add(t103, t104); // Eval UnnamedPoly step + (coeff_7 * z^7) - let t106 = circuit_mul(t65, t6); // Eval UnnamedPoly step coeff_8 * z^8 - let t107 = circuit_add(t105, t106); // Eval UnnamedPoly step + (coeff_8 * z^8) - let t108 = circuit_mul(t66, t7); // Eval UnnamedPoly step coeff_9 * z^9 - let t109 = circuit_add(t107, t108); // Eval UnnamedPoly step + (coeff_9 * z^9) - let t110 = circuit_mul(t67, t8); // Eval UnnamedPoly step coeff_10 * z^10 - let t111 = circuit_add(t109, t110); // Eval UnnamedPoly step + (coeff_10 * z^10) - let t112 = circuit_mul(t68, t9); // Eval UnnamedPoly step coeff_11 * z^11 - let t113 = circuit_add(t111, t112); // Eval UnnamedPoly step + (coeff_11 * z^11) - let t114 = circuit_mul(t88, t91); - let t115 = circuit_add(t114, t113); - let t116 = circuit_sub(t115, t56); - - let modulus = TryInto::< - _, CircuitModulus - >::try_into( - [32324006162389411176778628423, 57042285082623239461879769745, 3486998266802970665, 0] - ) - .unwrap(); - - let mut circuit_inputs = (t116,).new_inputs(); - // Prefill constants: - circuit_inputs = circuit_inputs.next([0x52, 0x0, 0x0, 0x0]); - circuit_inputs = circuit_inputs - .next([0x6871ca8d3c208c16d87cfd35, 0xb85045b68181585d97816a91, 0x30644e72e131a029, 0x0]); - - let mut input = input; - while let Option::Some(val) = input.pop_front() { - circuit_inputs = circuit_inputs.next(val); - }; - - let outputs = match circuit_inputs.done().eval(modulus) { - Result::Ok(outputs) => { outputs }, - Result::Err(_) => { panic!("Expected success") } - }; - let res = array![outputs.get_output(t116)]; - return res; -} - #[cfg(test)] mod tests { @@ -740,944 +371,484 @@ mod tests { G1Point, G2Point, E12D, E12DMulQuotient, G1G2Pair, BNProcessedPair, BLSProcessedPair, MillerLoopResultScalingFactor }; + use garaga::ec_ops::{SlopeInterceptOutput, FunctionFeltEvaluations, FunctionFelt}; - use super::{ - run_BLS12_381_FP12_MUL_ASSERT_ONE_circuit, run_BLS12_381_FP12_MUL_circuit, - run_BN254_FP12_MUL_ASSERT_ONE_circuit, run_BN254_FP12_MUL_circuit - }; + use super::{run_BLS12_381_FP12_MUL_ASSERT_ONE_circuit, run_BN254_FP12_MUL_ASSERT_ONE_circuit}; #[test] fn test_run_BLS12_381_FP12_MUL_ASSERT_ONE_circuit_BLS12_381() { - let X: E12D = E12D { + let X = E12D { w0: u384 { - limb0: 71029029285038535328301142941, - limb1: 51725320338008152483723565975, - limb2: 73911455883094295412141261626, - limb3: 3867164482506304348186712195 + limb0: 0x20fff2cb6857548c9e689188, + limb1: 0x30cceeb348d46113b50aea15, + limb2: 0x7d9fab3fccdbab0b13b40ac, + limb3: 0x5cdb615bd33677abff8746d }, w1: u384 { - limb0: 55464086965603394220937522799, - limb1: 31004385889608404247826647971, - limb2: 40832848433225188251344281518, - limb3: 7635521334383696381787612377 + limb0: 0x8c9965796ec59896ffcb2aa3, + limb1: 0xf2e573e2b22d888b38130ad1, + limb2: 0xe722efaacd69de05feaedd7, + limb3: 0xcbadaf824b4aaafab3a1d34 }, w2: u384 { - limb0: 34548047606004572950120704827, - limb1: 57659675347788322849285395323, - limb2: 62224349506316350971693464899, - limb3: 2236678833840831745691356571 + limb0: 0x74cac73bf14a58b3eefd1aa0, + limb1: 0x62330da619e0f5b764fbfae6, + limb2: 0xf6000f24cfe1f8acc66aefe, + limb3: 0x487867a3ab319ae45b333c7 }, w3: u384 { - limb0: 54020592794423544965142549071, - limb1: 4372972263229517496662238226, - limb2: 75965854791756086351574637739, - limb3: 3618304243774044701240765242 + limb0: 0xeab94eba93f28ab5616cd40e, + limb1: 0x526aea432c337ceea97d229a, + limb2: 0x827254df38305e4bc3d4540a, + limb3: 0xcd633bb5d88c5860fad3771 }, w4: u384 { - limb0: 76132363328362933367246505164, - limb1: 66645271661799032816669711093, - limb2: 60729027616931253880269499568, - limb3: 2011607713306819550745639738 + limb0: 0x7363cd269c45171f0d58306, + limb1: 0x5f40ec4712d527a03cc17dde, + limb2: 0x7d3e37112985c817a937cc86, + limb3: 0x11552fa7bd6337b3d5957c15 }, w5: u384 { - limb0: 3116136987019992062869560190, - limb1: 52348747740995785708738113000, - limb2: 55133474293768395616260822339, - limb3: 1057379248098252027861002035 + limb0: 0x8b2439d4b6328f01197e30de, + limb1: 0xe5961b741925b544c69d9109, + limb2: 0x5cec2965858f0cef7b0b48ed, + limb3: 0xa6944aa6d3b6c47810c040 }, w6: u384 { - limb0: 28463598373936524886581190286, - limb1: 70133890718351129300135804702, - limb2: 58258384046545676126660762566, - limb3: 353538770283163018453892822 + limb0: 0x869f6ec6da58e05a291b0b3f, + limb1: 0x700b2978e9e0cd8b2da562c6, + limb2: 0x7fca5734b32d747134f75266, + limb3: 0x98e61de6d4fda9921f6383c }, w7: u384 { - limb0: 57023601030769823013827151429, - limb1: 18894738741295778481120149032, - limb2: 4990790043678587988438046768, - limb3: 6372000652768851214212330562 + limb0: 0x62ada60321811ff0125f0449, + limb1: 0xe76419b8e79ae8b592ef181c, + limb2: 0xdf181e4f394e61fe1bbc403d, + limb3: 0xfc93d71c3629df76898a668 }, w8: u384 { - limb0: 42303088661821409746372490097, - limb1: 64315685935980079435483658002, - limb2: 78898068543092828759474425123, - limb3: 3360116953454601624664407328 + limb0: 0x23f6395130ae10926138cf93, + limb1: 0xeda12915fd209f3259c07b44, + limb2: 0x4d75fe3e7c52dc01327278c, + limb3: 0x162db8b7b03dd39f42e37126 }, w9: u384 { - limb0: 62414245446145425238212056490, - limb1: 32127642246835655563386568184, - limb2: 63945343353534451009783431867, - limb3: 5180726008387910658668279196 + limb0: 0xc46477d001f59b1c483837de, + limb1: 0xc5f87eff12d06ce5dff4e562, + limb2: 0xde9f56956cf89db398b3f261, + limb3: 0xc2a67c01151de92980b5c39 }, w10: u384 { - limb0: 53722859847507397517199786636, - limb1: 42510773771855106263438683587, - limb2: 45900496196881014460290028333, - limb3: 713385010770818366777389754 + limb0: 0x8c1d76b28e334a4986cdf496, + limb1: 0xb9452195d03ce6060b7fc161, + limb2: 0xca10725a112a21749d270596, + limb3: 0x623c85b1d665a38c24d532f }, w11: u384 { - limb0: 11217953222531294174764912797, - limb1: 1510326924841615377987810337, - limb2: 72732964440908167458194577800, - limb3: 2403411547259994768396886548 + limb0: 0x96417f0c516ee3ec675a4db5, + limb1: 0xa85e869463e55888b40dd177, + limb2: 0x8950724d7dbfd37f0107d458, + limb3: 0xf142ed15f82283e4d7a2830 } }; - let Y: E12D = E12D { + let Y = E12D { w0: u384 { - limb0: 10342265047551032619057033226, - limb1: 50124604767079605388933165102, - limb2: 24349772199378442733977472005, - limb3: 963535678478737866544117555 + limb0: 0xf2d72a3b0e3522edb63250a2, + limb1: 0xcaa9df00ded5ea11403af7af, + limb2: 0x486dd2b74be622a100ec2994, + limb3: 0x150dd1212d3f11dc3f8d692c }, w1: u384 { - limb0: 13523406597324953546234823521, - limb1: 5067244053962917478577841029, - limb2: 8424425580526610544689109559, - limb3: 5892370825357558614652018993 + limb0: 0xf3020be7f86445d74c6bf5b8, + limb1: 0xfbb2fcac8f1df6fc380320fc, + limb2: 0xafb72774fe3da5241873b82b, + limb3: 0x147ebec130b570fee209b136 }, w2: u384 { - limb0: 17475556066150465692331589443, - limb1: 16054885387459224409876200439, - limb2: 64295319946593133471433765334, - limb3: 7308088934630676479019402967 + limb0: 0x72883dfe3bef6eeff6307286, + limb1: 0xd31b6f936a73fc45df3fe737, + limb2: 0x1f33f11e54425d51df5f725, + limb3: 0x577d6202162113f8285b5e8 }, w3: u384 { - limb0: 60548371115851383859269121541, - limb1: 13741938846798337531701858131, - limb2: 9566443606626428228856943253, - limb3: 7502412695021128801671045143 + limb0: 0xcd7dd454f3841334ebbd44b7, + limb1: 0x3b99fbc3325659ab7a4883c9, + limb2: 0x2253dfc54d9f0dfa10e2e071, + limb3: 0x13b0236cc3c74f42c4b9ee85 }, w4: u384 { - limb0: 55166235635043133805092638175, - limb1: 13073132143403500775970934517, - limb2: 73339571126837961266935110114, - limb3: 1320841220536407241145517460 + limb0: 0x6cb7c5bf0e58cd63c7e470d9, + limb1: 0x4aaa3cc8dcc3339446780a81, + limb2: 0xd64d47458f8643af86e396dd, + limb3: 0x13c34c118cb10928452db5ba }, w5: u384 { - limb0: 67135307236062755756545900078, - limb1: 29800172027123290510840005017, - limb2: 1238361513404017870432949577, - limb3: 799437993886640975704439585 + limb0: 0x137a168eb782fe1ab917e104, + limb1: 0xd53fa183977b5433bec4aa17, + limb2: 0xdf93e0d5d7a6058518c8a622, + limb3: 0x41cf661114d1ad3790eefa8 }, w6: u384 { - limb0: 14214550930860201660722978887, - limb1: 55993810344993093729499172829, - limb2: 70268656884556458862703114145, - limb3: 6868126275059647322836345202 + limb0: 0xaaf50770a2081bc46f3454e0, + limb1: 0xb470b8c2e842be8d0a97b6f9, + limb2: 0x4a1f73ba3579404fb0a11815, + limb3: 0x8d66734d7eaecc0955f3565 }, w7: u384 { - limb0: 61208724092214516655378827826, - limb1: 10053453470637550528106329095, - limb2: 50692215121526672291403328155, - limb3: 4460735030049386998099932776 + limb0: 0xebcb61c01270ff80ede013c6, + limb1: 0xc99ad9bba38beec4baf239b9, + limb2: 0xbf74c16073fb7c3a93a5e78e, + limb3: 0x13613033b1db0f7729735237 }, w8: u384 { - limb0: 74323116453506673577333285524, - limb1: 54800026102147583691166006575, - limb2: 14261106391697589298440276788, - limb3: 6061447797076441252658566763 + limb0: 0x527febc215777894468bc959, + limb1: 0x2d2674be2a6ba43a0ec37460, + limb2: 0xede3739857c22aee6d7e8c63, + limb3: 0x279c5ef02af139b55966408 }, w9: u384 { - limb0: 49691241918702875942653967335, - limb1: 23863503866939148387560484295, - limb2: 362076205285380942585458279, - limb3: 1900513941960699393836719077 + limb0: 0xab2e8bc1a68f3d5525c355dd, + limb1: 0xf1173924b70918e85df4e0e8, + limb2: 0x6d63565fe1c7087e5a469d02, + limb3: 0x1667e7f45cf7f2d5067c6e85 }, w10: u384 { - limb0: 42006693876405215659581308420, - limb1: 49035969002012381740373311908, - limb2: 60302791431760153799282757719, - limb3: 5026440187166584576604487888 + limb0: 0x9219fe1dd5ee9df9101c0d4c, + limb1: 0xa6d8179a59a7a4d295dc200c, + limb2: 0x57916b319835245afe5f37d3, + limb3: 0x372184b75fc330325671f98 }, w11: u384 { - limb0: 61031931745339693587765558029, - limb1: 16488070294311780794698298854, - limb2: 15347999924141323732138583191, - limb3: 1477777684450895756770445794 + limb0: 0xbd7e1f96c55dcbc2fc3b28bf, + limb1: 0xebe36227b3e6b224cef9ae0f, + limb2: 0x9f4bb174aeb9c209bef5602e, + limb3: 0xe52e617d6846cfd8dc68e11 } }; - let Q: E12DMulQuotient = E12DMulQuotient { + let Q = E12DMulQuotient { w0: u384 { - limb0: 76738325331097784098604458616, - limb1: 39417186659492356989027551786, - limb2: 53094169080319585762352008913, - limb3: 535063529279238856852655344 + limb0: 0xbb44af62d891a86421e3aa38, + limb1: 0x7b66a9ac60e8610172421123, + limb2: 0xdbe26a9c4f0743b18ed9acf0, + limb3: 0x158745d5bf5057febbdb799e }, w1: u384 { - limb0: 22585138241466902975054453122, - limb1: 19916516860679998441664261275, - limb2: 63790846234686982641901917483, - limb3: 4487756784340157775933620637 + limb0: 0xf55aae577c63747aa71cbf0f, + limb1: 0x50da07a16c3a6e073660fc39, + limb2: 0xf6170e9c7cadab1606378948, + limb3: 0x4bccfcc688cd288d7c3ba60 }, w2: u384 { - limb0: 58661869304581898856455133892, - limb1: 42574096519912998584804297538, - limb2: 62233089377122619708039166050, - limb3: 5099359427611870068309283215 + limb0: 0xd4f75de64b4270089b4d3ac7, + limb1: 0x506dec11c8bbea21dd5d3b9b, + limb2: 0x324e04b61c4cd545369b4563, + limb3: 0x12d265dfbb5225772080dd12 }, w3: u384 { - limb0: 70915478360605433910852481281, - limb1: 35242341865846906270953282568, - limb2: 25826187497304245333665750975, - limb3: 7398788812224297161839865185 + limb0: 0xf499341a7bdfcf8ba129d91b, + limb1: 0xc5440df00080c8261b259968, + limb2: 0x5f2f25cb07b62caffafd260a, + limb3: 0xd7989874733ef7da55f50f6 }, w4: u384 { - limb0: 25803420863687201551154558281, - limb1: 8725624939389234135888653453, - limb2: 7769441528829129652241786566, - limb3: 4086147442961509392265234938 + limb0: 0x3b6803ee940d10cdaf73d31f, + limb1: 0x93f0e4b4387138d463416865, + limb2: 0x9675562f1157c073b3e19908, + limb3: 0x8b2699ca6aae7ad191fa8bc }, w5: u384 { - limb0: 29752741105515908274421030525, - limb1: 5825624154518746837927625130, - limb2: 38378733309776841093529391429, - limb3: 4316598524314752177287016219 + limb0: 0x451ad86965f5779e2b41d86, + limb1: 0xd148867a65698eaad4fae26d, + limb2: 0xd6a77153b5c7dfc64af5adf3, + limb3: 0x5e151c267d7ff805feff9a8 }, w6: u384 { - limb0: 73514791122030279584214867726, - limb1: 14107427283636357602792953436, - limb2: 10807087021979156256370725950, - limb3: 1922817208175532140301022739 + limb0: 0x9a44df106074662f5c6f76ca, + limb1: 0xb6a6668e9543cfd8edf50d02, + limb2: 0xc984fec7cf0015141faf39ed, + limb3: 0x11efae12ef58e475bd33307b }, w7: u384 { - limb0: 77291500896980713022023279320, - limb1: 26612053689119475219298956141, - limb2: 54842568267807880625876169566, - limb3: 2778968976132832092048594321 + limb0: 0x552a41d26ce38dafc2acf2c9, + limb1: 0xf9e5399e55a0fcb3422e2e95, + limb2: 0x2da2f1939e730261181a00c0, + limb3: 0x7a22b24dfe68c5171a261d8 }, w8: u384 { - limb0: 67474773117741811493881627435, - limb1: 33135105537387115517972398445, - limb2: 27220895700244848961553422705, - limb3: 2923138043952362602799583926 + limb0: 0x72add5ea1934c37730ac64c5, + limb1: 0xff8b112a183608b3519fc4, + limb2: 0x2f7acf2f9fbe505baccb54e8, + limb3: 0x17bd5418cc19b2c95b3146b6 }, w9: u384 { - limb0: 62554355123322281670832808791, - limb1: 75485435419429754335494972238, - limb2: 13463676008550633729025710814, - limb3: 5474226680247745772947227743 + limb0: 0x4e210675bd6b774d0e15c9f5, + limb1: 0x154959a9295f90503c79db9d, + limb2: 0x53a34be0bc6f12c0898122bb, + limb3: 0x29bfffa9d9f20907af94397 }, w10: u384 { - limb0: 6851202343162025005316934440, - limb1: 41338781875332116018559773462, - limb2: 78884656005785174486630078154, - limb3: 4689207862567338777032312923 + limb0: 0x537dec6395a2888492747f90, + limb1: 0xdc59e4a50a06c335079092e4, + limb2: 0x1d494ca5fc5a326352b51adc, + limb3: 0xd48b428fcc6b9501a047c3d } }; let z: u384 = u384 { - limb0: 22118195736760409498012936622, - limb1: 33918397682506047102484121175, - limb2: 19541957279868152243375454112, - limb3: 4300591001267578104706097582 + limb0: 0xd42986fae9aebe887af51c9c, + limb1: 0x61086f02d9657db2f00a2a15, + limb2: 0x46bc0d80593dc4eb93cf3e68, + limb3: 0x12262a0f92f424609a1c1c26 }; let (check_result) = run_BLS12_381_FP12_MUL_ASSERT_ONE_circuit(X, Y, Q, z); let check: u384 = u384 { - limb0: 28266221504594817035365447594, - limb1: 27464814037690403238365721240, - limb2: 17672694422257258854517063532, - limb3: 5176855091393523583744364111 + limb0: 0xd5ce849cb6cc5a029850006, + limb1: 0x7ac372440461ed78fab065f5, + limb2: 0x9974bdad58268cae48bad1b1, + limb3: 0xb33965e7715f38651980d0a }; assert_eq!(check_result, check); } - #[test] - fn test_run_BLS12_381_FP12_MUL_circuit_BLS12_381() { - let input = array![ - u384 { - limb0: 31481706122096549464913901405, - limb1: 67868759843779350247177940085, - limb2: 36298951532418126956287301854, - limb3: 122445131395547102836367213 - }, - u384 { - limb0: 49363734691025808346622681592, - limb1: 61931518654422335291235459818, - limb2: 32835509912913724709832130657, - limb3: 5611274462785060862788826525 - }, - u384 { - limb0: 60084846668691309517372316159, - limb1: 7938978354065306655951631649, - limb2: 44580400306068298829136402342, - limb3: 7781647792384042784670105029 - }, - u384 { - limb0: 42437256044111696706190270870, - limb1: 69553893877560558565201056805, - limb2: 30347830340399582238940862186, - limb3: 5665043739611039930416900669 - }, - u384 { - limb0: 2968336193316344014976643487, - limb1: 31926886704307061432180361220, - limb2: 48222637916789365455698757457, - limb3: 3978441220039978176360333433 - }, - u384 { - limb0: 70479330135208240068164429557, - limb1: 54708136242387862249369984540, - limb2: 59084388121203733450468753215, - limb3: 2659930602984709324473361979 - }, - u384 { - limb0: 7781582870615248658587257332, - limb1: 18060647040107088382910630438, - limb2: 77185614555783836617429948131, - limb3: 7665630709639008690534394922 - }, - u384 { - limb0: 58703695236318437153595959611, - limb1: 40921457806600222017082202009, - limb2: 65047699476382581548940007594, - limb3: 7838541229651537177851691326 - }, - u384 { - limb0: 24649711132791196136131160859, - limb1: 31959463879970389990593419036, - limb2: 67446565494304065918737183308, - limb3: 5631857740691152141712596740 - }, - u384 { - limb0: 15272293677032018409538790787, - limb1: 15903213564985846642707780916, - limb2: 19766655320402504719997868701, - limb3: 500714869335157671806326788 - }, - u384 { - limb0: 2421465682553396439589200302, - limb1: 38725675093600391949462775738, - limb2: 14069629701951197615903423905, - limb3: 4700035313273406223527750081 - }, - u384 { - limb0: 27710834356798301570745616575, - limb1: 66365768534034441518580806642, - limb2: 59338814344640457861156924468, - limb3: 895198274277565377987995855 - }, - u384 { - limb0: 30626887791993392103379586712, - limb1: 67646694486068026383923539548, - limb2: 76448649319326805723591966979, - limb3: 2192154911194849472310777129 - }, - u384 { - limb0: 704970819134024183709672830, - limb1: 10483002088231165148734058283, - limb2: 47627371899731550128433669234, - limb3: 2216111036432550975662029282 - }, - u384 { - limb0: 27627588965592301460380496363, - limb1: 17288302570054643574378652905, - limb2: 53653006904319436309055243647, - limb3: 6175895627598679785198880379 - }, - u384 { - limb0: 8106000001404022517624719871, - limb1: 79182953298664484961752549336, - limb2: 66811837476094140901479161969, - limb3: 5560401943914382348729286921 - }, - u384 { - limb0: 48253920679701385420901725843, - limb1: 54224795299195489880085725980, - limb2: 5057692327865246571366759693, - limb3: 2738157490462795058984169342 - }, - u384 { - limb0: 68254396481106596829350200441, - limb1: 51983150611125032858337537600, - limb2: 70701135991376745614962998732, - limb3: 1865427922302805324228624816 - }, - u384 { - limb0: 60647129510547984252479325222, - limb1: 4498152892290892512780120009, - limb2: 63569805250568050666655229469, - limb3: 4001996991071955534537953035 - }, - u384 { - limb0: 30762308298674705845589581567, - limb1: 46191896762110535052809632152, - limb2: 45321870723840521366311010763, - limb3: 3398561834045363305438402277 - }, - u384 { - limb0: 17617427117379033275285056553, - limb1: 50572412767809481294543489853, - limb2: 71822429050293948548360635255, - limb3: 3550383619517082565340011891 - }, - u384 { - limb0: 66981013715848115191440958196, - limb1: 52101602828662489289142320883, - limb2: 14351061200601853379016259167, - limb3: 4662387984672337729785523866 - }, - u384 { - limb0: 20643629126958689685053977386, - limb1: 36742902326561821771793167892, - limb2: 37279748083972798427848845144, - limb3: 6282761029441618838917334490 - }, - u384 { - limb0: 74815231909794712396130231675, - limb1: 37413097640667786778752793087, - limb2: 39651902859902868225373859126, - limb3: 6741304143114206993439277529 - } - ]; - let got = run_BLS12_381_FP12_MUL_circuit(input); - let exp = array![ - u384 { - limb0: 21448829438051705008495457586, - limb1: 57801949056943885331418910824, - limb2: 64420422200751530183481188004, - limb3: 4746202111627640384510408933 - }, - u384 { - limb0: 75713094439827553950299913705, - limb1: 50544351001940742158281332967, - limb2: 16563864662501399819357615492, - limb3: 2343832696756384558814504823 - }, - u384 { - limb0: 38486379899022802582930291757, - limb1: 22122506976201516734682403778, - limb2: 16360761498551330164648085039, - limb3: 1784580662868681574407670154 - }, - u384 { - limb0: 52534847248357128201893874109, - limb1: 9507460543240051569308928972, - limb2: 44415194869720260297351656175, - limb3: 4792690276895686225250036746 - }, - u384 { - limb0: 6871772335871622498462644239, - limb1: 10820204534046793999690617134, - limb2: 23650836244557532970681920705, - limb3: 4377810984112299838038383117 - }, - u384 { - limb0: 44409745992696063320004102203, - limb1: 43135367713761470605773198955, - limb2: 47831834609263324548637867081, - limb3: 3600538276226193125853478991 - }, - u384 { - limb0: 19545994933887640300541817987, - limb1: 76607128326895103535946946559, - limb2: 17934161436863045508172693141, - limb3: 5270868536712996673897317218 - }, - u384 { - limb0: 23523704909657058080290425644, - limb1: 18537937209798287492168040158, - limb2: 18747782112827204116580348889, - limb3: 5464130976857698063665883981 - }, - u384 { - limb0: 63897128130005262302055601080, - limb1: 9591404062633591070122883634, - limb2: 23874060901549460051868044456, - limb3: 2017388381249884752017711554 - }, - u384 { - limb0: 33541731023335788901843471202, - limb1: 8330312856367057720459799777, - limb2: 73555582291023014739080758649, - limb3: 99519497114503922571904843 - }, - u384 { - limb0: 51802679130477516547168214393, - limb1: 28939374425596397379535729688, - limb2: 15496736095748895048816664404, - limb3: 1025430698042901768881101985 - }, - u384 { - limb0: 50582671329603822972137924349, - limb1: 19796100204509190560283220892, - limb2: 34861112956119535204499684621, - limb3: 6787638201682964124680955574 - }, - u384 { limb0: 0, limb1: 0, limb2: 0, limb3: 0 } - ]; - assert_eq!(got.len(), exp.len()); - assert_eq!(got, exp); - } - - #[test] fn test_run_BN254_FP12_MUL_ASSERT_ONE_circuit_BN254() { - let X: E12D = E12D { + let X = E12D { w0: u384 { - limb0: 36232733333819267831187881540, - limb1: 61207529572384806113351989225, - limb2: 2284229624673291714, - limb3: 0 + limb0: 0x3756af5183dc01010b63983c, + limb1: 0xaac487b171db0784b71df25e, + limb2: 0x1148931e9cf52508, + limb3: 0x0 }, w1: u384 { - limb0: 8969499376599097893218605797, - limb1: 21224345759731257053133235063, - limb2: 2504635170111213235, - limb3: 0 + limb0: 0xdc8848ba6ab09995c78e0f48, + limb1: 0xf5a3f57c637c71aef9862da, + limb2: 0xff27c52c05f9874, + limb3: 0x0 }, w2: u384 { - limb0: 43286565974349949823592896197, - limb1: 33684224885911475634557836598, - limb2: 3394148779991496381, - limb3: 0 + limb0: 0x5f0099167df8b7f044a1d4d0, + limb1: 0xee1ce2b4b385492d4c6700b, + limb2: 0x10f382e0fee2f56b, + limb3: 0x0 }, w3: u384 { - limb0: 59527722920086956476939076529, - limb1: 69309576269972711353767312268, - limb2: 148636478670566545, - limb3: 0 + limb0: 0x5bf2b6a11b95cd28b2764173, + limb1: 0xeaaa5a3e31dbd1d548e003be, + limb2: 0xee2ee03572de2ff, + limb3: 0x0 }, w4: u384 { - limb0: 61451870023105400256060457677, - limb1: 16628261520090209209766376377, - limb2: 3401639472285759118, - limb3: 0 + limb0: 0xd4ae04b3fab2a7803dbe0be0, + limb1: 0xaf5f7bd63021c8ad3302a5ca, + limb2: 0x7c9974060e248c1, + limb3: 0x0 }, w5: u384 { - limb0: 27779837117219349798710292002, - limb1: 48349921116687246466292232191, - limb2: 1974572064131858823, - limb3: 0 + limb0: 0x405e342dfbe30bf988f1559e, + limb1: 0xf86040142b3c1658aa3042f9, + limb2: 0x162a6df5f61d103d, + limb3: 0x0 }, w6: u384 { - limb0: 27794465715114939498189951795, - limb1: 47287937754346425484707073506, - limb2: 776503542237936721, - limb3: 0 + limb0: 0x6e090ea64032ee1e75711fc, + limb1: 0xab46afee8898a682e0968f21, + limb2: 0x2237c0c10b320459, + limb3: 0x0 }, w7: u384 { - limb0: 78078427233016903726119976440, - limb1: 64585285632714581698908558240, - limb2: 625293452831141160, - limb3: 0 + limb0: 0x1c0989b1af56d7ba6f086f65, + limb1: 0xb58e2a1ccdf53f9b4102364b, + limb2: 0x20b73dcd33744da6, + limb3: 0x0 }, w8: u384 { - limb0: 62248857904685867220612954546, - limb1: 4697111671249175294339079849, - limb2: 1278929067580822477, - limb3: 0 + limb0: 0x8d87b7e8ac91b72f6c14b828, + limb1: 0x25bc36a32df19dfb5a5915c2, + limb2: 0x7cd5d03cc2946f5, + limb3: 0x0 }, w9: u384 { - limb0: 10053116060569092063157998764, - limb1: 10512852830014012631465111641, - limb2: 674428845728389386, - limb3: 0 + limb0: 0xd8d02c0dbb4e01c54980588c, + limb1: 0xc2411753bd3a98bdcc583f50, + limb2: 0xb22506f4b7118ac, + limb3: 0x0 }, w10: u384 { - limb0: 65639091059276963372207044870, - limb1: 66833364416817988916805091151, - limb2: 1811012549976372535, - limb3: 0 + limb0: 0xb092a5ff948c2d4389fb4504, + limb1: 0x7a440b3413e34b3d3d946990, + limb2: 0xc55d173ccfcd746, + limb3: 0x0 }, w11: u384 { - limb0: 45748363673848459401462885085, - limb1: 49740456341038515146350467234, - limb2: 1730176986552903637, - limb3: 0 + limb0: 0xfc8ba273caa7b1c81a71a203, + limb1: 0xd12ea61b76ad2cfc23f4fe14, + limb2: 0x167ab9a6a09c93de, + limb3: 0x0 } }; - let Y: E12D = E12D { + let Y = E12D { w0: u384 { - limb0: 50201163309546882248555739861, - limb1: 60917285496848173983672750279, - limb2: 1857821278612033369, - limb3: 0 + limb0: 0xd24f8f4351a2fa157b6c0adb, + limb1: 0x7bef34f04fc3489b9c14c815, + limb2: 0x12235a882415f2a3, + limb3: 0x0 }, w1: u384 { - limb0: 22043310114576972898845539990, - limb1: 69508242421211606256704821383, - limb2: 2096913536410940104, - limb3: 0 + limb0: 0xb0a1baa56921c1c00bae07a2, + limb1: 0x76ad98ba10fb5581cccb4dfb, + limb2: 0xb5c580897ec1a40, + limb3: 0x0 }, w2: u384 { - limb0: 57910393905526210430607019328, - limb1: 50297250063754204659308222327, - limb2: 3215677824510022722, - limb3: 0 + limb0: 0x1ce76bc0c34c3f471171c294, + limb1: 0x3b34252964d63e97de6ff3f1, + limb2: 0x280ca50f4ab878c7, + limb3: 0x0 }, w3: u384 { - limb0: 16784602335539274389890340634, - limb1: 25580012076337666166744261511, - limb2: 1307842245546628046, - limb3: 0 + limb0: 0xf11e71ae6ce2a4651b742111, + limb1: 0x955e988df24bfd76a07f949e, + limb2: 0x12e643b9f6714d76, + limb3: 0x0 }, w4: u384 { - limb0: 54077334749729967705748885977, - limb1: 3639973854618842972547126374, - limb2: 2887743342320138977, - limb3: 0 + limb0: 0x8615ad73699303f1bde82282, + limb1: 0xe31b328e3a3262055e26b29d, + limb2: 0xfb49e12c6950d85, + limb3: 0x0 }, w5: u384 { - limb0: 36411818698197502009182846927, - limb1: 73637258445497310788190929866, - limb2: 728570381439274546, - limb3: 0 + limb0: 0xa6db74d1a748687529bdf604, + limb1: 0x1ddde15af323e4341bbf9922, + limb2: 0x26bc799b890974e4, + limb3: 0x0 }, w6: u384 { - limb0: 21710058672518109474964576816, - limb1: 28556633235768307693973217555, - limb2: 380097610269688579, - limb3: 0 + limb0: 0x99225957ee705259262ae4c4, + limb1: 0x2fd8e8ebe14880c0994d799a, + limb2: 0x15ddb694f8c03d19, + limb3: 0x0 }, w7: u384 { - limb0: 71606434688571104041731434301, - limb1: 4103010541947587870498687894, - limb2: 2885090501209793552, - limb3: 0 + limb0: 0xa886e763c2c49a972e6f1665, + limb1: 0x55b1f1c6059251e1de0a09a6, + limb2: 0x6952b2c265a9190, + limb3: 0x0 }, w8: u384 { - limb0: 55415454367504549155731528320, - limb1: 34007178513724874568324539649, - limb2: 420582025281265987, - limb3: 0 + limb0: 0x9b3e660550835669836cd602, + limb1: 0x1a29313d3f74df9ae43bd530, + limb2: 0x2fae5a58bc16ca04, + limb3: 0x0 }, w9: u384 { - limb0: 86066182370540470378270233, - limb1: 6174942182774166670343849259, - limb2: 2737863453576830214, - limb3: 0 + limb0: 0xf856a0c38fda05f0e45d7a7c, + limb1: 0xbc7838b31a9af2a3ec6b2ea2, + limb2: 0x1e8fa641aeef4b09, + limb3: 0x0 }, w10: u384 { - limb0: 53873782153088072732807505137, - limb1: 638782431691722587747903274, - limb2: 1584456100392117998, - limb3: 0 + limb0: 0xb2b5591a9d7f542b85e2b078, + limb1: 0x7e54ed03eef42592ec1c6fe4, + limb2: 0x157302c349556582, + limb3: 0x0 }, w11: u384 { - limb0: 78289697287566290293728612021, - limb1: 54986801116415714804033864416, - limb2: 2203003535456877327, - limb3: 0 + limb0: 0x173235659dc257bde19dad46, + limb1: 0xa246b8560a94891e357245f9, + limb2: 0x19dae528ecd2742d, + limb3: 0x0 } }; - let Q: E12DMulQuotient = E12DMulQuotient { + let Q = E12DMulQuotient { w0: u384 { - limb0: 30349926683087214248120667615, - limb1: 63854479497956248880689342153, - limb2: 475933087515585238, - limb3: 0 + limb0: 0xb916751942a699a5571cf04d, + limb1: 0xb36cddb8beabdee5c8614c36, + limb2: 0x43fd37ae6ff73b5, + limb3: 0x0 }, w1: u384 { - limb0: 10548930879994947288330859291, - limb1: 53648326885857135644920141196, - limb2: 315492849180345543, - limb3: 0 + limb0: 0x733db528d4323934cda9cfae, + limb1: 0x9ca574d20979829cc898b6a, + limb2: 0x632d384abe04a61, + limb3: 0x0 }, w2: u384 { - limb0: 671437938181734446603920381, - limb1: 13002652799230472914944778672, - limb2: 1619567495594269453, - limb3: 0 + limb0: 0xb5743132ef3822707072aa51, + limb1: 0xc34920a7fcfa3a3b47f050aa, + limb2: 0x10453e8455b3b1ac, + limb3: 0x0 }, w3: u384 { - limb0: 49761627243910020748324982332, - limb1: 72881521037612513657669716986, - limb2: 2841149120367153617, - limb3: 0 + limb0: 0x5cae1234bb10d4065a55805d, + limb1: 0xe8ebbae25bc1c77afa29fad9, + limb2: 0x2df54b73f2aaaaf0, + limb3: 0x0 }, w4: u384 { - limb0: 68133250682852055712931171580, - limb1: 71035411712167048865556289785, - limb2: 645696621978850556, - limb3: 0 + limb0: 0x47595fb338b4372600cea03, + limb1: 0xa0e38dd6f700358564d06b24, + limb2: 0x2275e2ac94be4e35, + limb3: 0x0 }, w5: u384 { - limb0: 46710857834164914215498827578, - limb1: 27851522634801178442987594039, - limb2: 1980206079096092577, - limb3: 0 + limb0: 0x631d91b5073039f1e6ad906, + limb1: 0x17bcd32324b441266f1f7a15, + limb2: 0x80097e0d5d0a12d, + limb3: 0x0 }, w6: u384 { - limb0: 11078488847043997400530374639, - limb1: 51072103608314502015173455261, - limb2: 1144468390854873842, - limb3: 0 + limb0: 0xe9edc59ca80ab2000cfcbe46, + limb1: 0xf6bd16ac4ab507018e6b81a3, + limb2: 0x303e940c326e1983, + limb3: 0x0 }, w7: u384 { - limb0: 67176933111624304288558418521, - limb1: 69390179140389019312130200760, - limb2: 947451150930076693, - limb3: 0 + limb0: 0x3e0f74885c88c320a7b0a957, + limb1: 0x15362c1f90b359d9ff0a837a, + limb2: 0xe45d6bac38efb8c, + limb3: 0x0 }, w8: u384 { - limb0: 40368537015381881859003331824, - limb1: 31037713268746269798580298608, - limb2: 2979932114636022986, - limb3: 0 + limb0: 0x5140094b6ed4e645aaed8b53, + limb1: 0xb2363b7ea221c908a4edeefd, + limb2: 0x125881cea0f9986a, + limb3: 0x0 }, w9: u384 { - limb0: 71139962115052159171680550418, - limb1: 18962553627762909824947652986, - limb2: 1779583125281633834, - limb3: 0 + limb0: 0x75f98f4110a15299054efa50, + limb1: 0xf106892ba1fa46f346685cdd, + limb2: 0xdaf189a61af473d, + limb3: 0x0 }, w10: u384 { - limb0: 78188889610784037067589048559, - limb1: 25073546934847101430326685335, - limb2: 1783976531669393757, - limb3: 0 + limb0: 0xe9a28f3cb9abe19f2911cf30, + limb1: 0x28685bdd02c81d1173f19747, + limb2: 0x2b0c5edd82ab3e, + limb3: 0x0 } }; let z: u384 = u384 { - limb0: 45031733892261894151632473720, - limb1: 43286799582515793146102527599, - limb2: 796762439735921222, - limb3: 0 + limb0: 0xfdcb8a6e9265da012aad0659, + limb1: 0xcb771b1e922ba0aae055b94, + limb2: 0x17aaf63d178234e8, + limb3: 0x0 }; let (check_result) = run_BN254_FP12_MUL_ASSERT_ONE_circuit(X, Y, Q, z); let check: u384 = u384 { - limb0: 69352195828274006668473688617, - limb1: 41678845886887377055287214226, - limb2: 2472458301078632122, - limb3: 0 + limb0: 0x9e685905eb3ee138f9d93c34, + limb1: 0x7a409f0fa629cee3409d3e20, + limb2: 0x8c91ce90b6543e9, + limb3: 0x0 }; assert_eq!(check_result, check); } - - - #[test] - fn test_run_BN254_FP12_MUL_circuit_BN254() { - let input = array![ - u384 { - limb0: 24179711637078154872698072788, - limb1: 69033323171013648726746901527, - limb2: 1028053427466515130, - limb3: 0 - }, - u384 { - limb0: 15301318457210954370086002523, - limb1: 22073208276000943622353706448, - limb2: 320146711337384969, - limb3: 0 - }, - u384 { - limb0: 22114560534868413469990194000, - limb1: 40359275625242915973686933105, - limb2: 3133724186599576222, - limb3: 0 - }, - u384 { - limb0: 14147600119690206055886498978, - limb1: 77924904970046305529730533213, - limb2: 176430179553745541, - limb3: 0 - }, - u384 { - limb0: 34429688114677249373942859004, - limb1: 62307259392135261750940332868, - limb2: 2012511570471233567, - limb3: 0 - }, - u384 { - limb0: 40519109474734117827222995157, - limb1: 71266106994207255293368923737, - limb2: 876583633381180973, - limb3: 0 - }, - u384 { - limb0: 56999116716456660037505908076, - limb1: 58394141795252174366841312619, - limb2: 908664166153080643, - limb3: 0 - }, - u384 { - limb0: 5543896111964588329291062870, - limb1: 72950982944412260385931489325, - limb2: 2873797086284348751, - limb3: 0 - }, - u384 { - limb0: 67186692668466921528645961350, - limb1: 71309057108007916549270106582, - limb2: 2338689782217042832, - limb3: 0 - }, - u384 { - limb0: 32356219940895644890465912726, - limb1: 55238541489685791664213375236, - limb2: 2556776294363696928, - limb3: 0 - }, - u384 { - limb0: 33311190625122701884446338806, - limb1: 30038983821758303538297491617, - limb2: 3450161675760874860, - limb3: 0 - }, - u384 { - limb0: 22731646690559464945584085643, - limb1: 62254228244041056092578285633, - limb2: 2797732666789192166, - limb3: 0 - }, - u384 { - limb0: 36840159815284822828872550826, - limb1: 53528704665659692542594704228, - limb2: 2357373971914367642, - limb3: 0 - }, - u384 { - limb0: 71398900445303871977830922946, - limb1: 58308873271295456045776211143, - limb2: 3038412792524760357, - limb3: 0 - }, - u384 { - limb0: 40838315389252462131274918152, - limb1: 49062895761140906196185797430, - limb2: 430672426797295067, - limb3: 0 - }, - u384 { - limb0: 1935178840434513892301483496, - limb1: 77955442914431956726435850640, - limb2: 2819003629311265027, - limb3: 0 - }, - u384 { - limb0: 5770046817954911365433419997, - limb1: 70206999211031843174167750500, - limb2: 2654813442635484636, - limb3: 0 - }, - u384 { - limb0: 55170867641077938500934205932, - limb1: 31663761889710221522616740278, - limb2: 680552691678954420, - limb3: 0 - }, - u384 { - limb0: 33683551981682337331343347221, - limb1: 63708146281584045824133167367, - limb2: 3209326608523281200, - limb3: 0 - }, - u384 { - limb0: 3978710132448725972414947603, - limb1: 72689463003301296553109628281, - limb2: 559667764532122151, - limb3: 0 - }, - u384 { - limb0: 63494764767764911070010584767, - limb1: 42080603038047810901012306942, - limb2: 2577587956506592516, - limb3: 0 - }, - u384 { - limb0: 39992646296251654083222591112, - limb1: 71848434114489718999273628124, - limb2: 2056413546060797467, - limb3: 0 - }, - u384 { - limb0: 58918454144710925140404170297, - limb1: 35658200186838653936236949040, - limb2: 3466958500785709215, - limb3: 0 - }, - u384 { - limb0: 50520744070478778258648930928, - limb1: 61613748404667949331712434274, - limb2: 2234809294668425107, - limb3: 0 - } - ]; - let got = run_BN254_FP12_MUL_circuit(input); - let exp = array![ - u384 { - limb0: 70773159131707667644855018196, - limb1: 7253812458867194552267082414, - limb2: 2171836549216372770, - limb3: 0 - }, - u384 { - limb0: 17231439283064386666377119449, - limb1: 43092515804295764836028014389, - limb2: 2003106786073840848, - limb3: 0 - }, - u384 { - limb0: 43854703349027848737917815111, - limb1: 53215411737743561424052829617, - limb2: 3441945717517484241, - limb3: 0 - }, - u384 { - limb0: 67778832540775784342998288871, - limb1: 49496667918005887595302450393, - limb2: 2808915320566262546, - limb3: 0 - }, - u384 { - limb0: 43625608444910290343947208449, - limb1: 41047802985053871868132256629, - limb2: 3159702736010909197, - limb3: 0 - }, - u384 { - limb0: 67240480420936535263697774024, - limb1: 38098186420091676301906266304, - limb2: 3106853330008702245, - limb3: 0 - }, - u384 { - limb0: 12206276915900194701407578542, - limb1: 45761794288690166103826102770, - limb2: 986073357551576907, - limb3: 0 - }, - u384 { - limb0: 21692988428379961135741950639, - limb1: 38447986245408464593651432235, - limb2: 306197041157837579, - limb3: 0 - }, - u384 { - limb0: 57152108599251694963495472942, - limb1: 34468289854105400115671745405, - limb2: 1852783585180016969, - limb3: 0 - }, - u384 { - limb0: 43819573964426468505474703843, - limb1: 67533849973158749802699245288, - limb2: 3201099209362036192, - limb3: 0 - }, - u384 { - limb0: 67309836701450948781118811571, - limb1: 73482588144277828186674696310, - limb2: 1729131218028674879, - limb3: 0 - }, - u384 { - limb0: 30184641081192880425084568131, - limb1: 13465532172817448083911447270, - limb2: 2950537300086220252, - limb3: 0 - }, - u384 { limb0: 0, limb1: 0, limb2: 0, limb3: 0 } - ]; - assert_eq!(got.len(), exp.len()); - assert_eq!(got, exp); - } } diff --git a/src/fustat/definitions.cairo b/src/fustat/definitions.cairo index 5851145d..200ef091 100644 --- a/src/fustat/definitions.cairo +++ b/src/fustat/definitions.cairo @@ -33,7 +33,7 @@ namespace bls { } namespace bn { - const CURVE_ID =0; + const CURVE_ID = 0; // p = 0x30644E72E131A029B85045B68181585D97816A916871CA8D3C208C16D87CFD47 const P0 = 0x6871ca8d3c208c16d87cfd47; const P1 = 0xb85045b68181585d97816a91; diff --git a/tools/make/fustat_format_check.sh b/tools/make/fustat_format_check.sh new file mode 100755 index 00000000..43001326 --- /dev/null +++ b/tools/make/fustat_format_check.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +# Function to check a file formatting and print a message based on the outcome +format_file() { + cairo-format -c "$1" + local status=$? + if [ $status -eq 0 ]; then + echo "$(date '+%Y-%m-%d %H:%M:%S') - File $1 is formatted correctly" + else + echo "$(date '+%Y-%m-%d %H:%M:%S') - File $1 is not formatted correctly" + return $status + fi +} + +# Export the function so it's available in subshells +export -f format_file + +# Find all .cairo files under src/ and tests/ directories and format them in parallel +# Using --halt soon,fail=1 to stop at the first failure +find ./src/fustat ./tests/fustat_programs -name '*.cairo' | parallel --halt soon,fail=1 format_file + +# Capture the exit status of parallel +exit_status=$? + +# Exit with the captured status +echo "Parallel execution exited with status: $exit_status" +exit $exit_status \ No newline at end of file diff --git a/tools/make/setup.sh b/tools/make/setup.sh index 18f2254c..0e84975a 100755 --- a/tools/make/setup.sh +++ b/tools/make/setup.sh @@ -1,5 +1,44 @@ #!/bin/bash +# Function to install GNU parallel +install_parallel() { + case "$OSTYPE" in + linux-gnu*) + # Linux + if command -v apt-get >/dev/null; then + # Debian/Ubuntu + sudo apt-get update && sudo apt-get install -y parallel + elif command -v dnf >/dev/null; then + # Fedora + sudo dnf install -y parallel + else + echo "Unsupported Linux distribution for automatic parallel installation." + exit 1 + fi + ;; + darwin*) + # macOS + if command -v brew >/dev/null; then + brew install parallel + else + echo "Homebrew is not installed. Please install Homebrew and try again." + exit 1 + fi + ;; + *) + echo "Unsupported operating system for automatic parallel installation." + exit 1 + ;; + esac +} + +# Check if parallel is installed, if not, attempt to install it +if ! command -v parallel >/dev/null; then + echo "GNU parallel not found. Attempting to install..." + install_parallel +else + echo "GNU parallel is already installed." +fi python3.10 -m venv venv echo 'export PYTHONPATH="$PWD:$PYTHONPATH"' >> venv/bin/activate