From 12928b980f4924d35bd05a5a69cabc22556447a2 Mon Sep 17 00:00:00 2001 From: feltroidprime Date: Sat, 27 Jul 2024 17:49:20 +0200 Subject: [PATCH] CI: cairoZero format, scarb test --- .github/workflows/cairo.yml | 2 + .github/workflows/fustat.yml | 30 +++++++++++ hydra/algebra.py | 1 - hydra/definitions.py | 4 +- hydra/precompiled_circuits/all_circuits.py | 62 ++++++++++++++-------- tools/make/fustat_format_check.sh | 27 ++++++++++ 6 files changed, 102 insertions(+), 24 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 2dd9f62a4..a85608549 100644 --- a/.github/workflows/cairo.yml +++ b/.github/workflows/cairo.yml @@ -15,3 +15,5 @@ jobs: scarb-version: "2.7.0-rc.3" - run: scarb fmt --check working-directory: src/cairo + - run: 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 000000000..4eb662787 --- /dev/null +++ b/.github/workflows/fustat.yml @@ -0,0 +1,30 @@ +name: Cairo Zero (Fustat) tests + +on: + push: + merge_group: + pull_request: + +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/hydra/algebra.py b/hydra/algebra.py index 4386902a5..aba6e641b 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 e60667c9c..836b3e83e 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 c53f8f026..591c34bbb 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/tools/make/fustat_format_check.sh b/tools/make/fustat_format_check.sh new file mode 100755 index 000000000..430013260 --- /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