Skip to content

Commit

Permalink
CI: cairoZero format, scarb test
Browse files Browse the repository at this point in the history
  • Loading branch information
feltroidprime committed Jul 27, 2024
1 parent 08bda3d commit ab83bb7
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 25 deletions.
1 change: 1 addition & 0 deletions .github/workflows/cairo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
30 changes: 30 additions & 0 deletions .github/workflows/fustat.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 0 additions & 1 deletion hydra/algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions hydra/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]
)


Expand Down Expand Up @@ -1017,5 +1016,6 @@ def replace_consecutive_zeros(lst):
i += 1
return result


if __name__ == "__main__":
pass
62 changes: 41 additions & 21 deletions hydra/precompiled_circuits/all_circuits.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/fustat/definitions.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace bls {
}

namespace bn {
const CURVE_ID =0;
const CURVE_ID = 0;
// p = 0x30644E72E131A029B85045B68181585D97816A916871CA8D3C208C16D87CFD47
const P0 = 0x6871ca8d3c208c16d87cfd47;
const P1 = 0xb85045b68181585d97816a91;
Expand Down
27 changes: 27 additions & 0 deletions tools/make/fustat_format_check.sh
Original file line number Diff line number Diff line change
@@ -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
39 changes: 39 additions & 0 deletions tools/make/setup.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit ab83bb7

Please sign in to comment.