From 27477993a5de78bf743cf3e7cc7bf7a4cebeeb44 Mon Sep 17 00:00:00 2001 From: feltroidprime Date: Sat, 24 Aug 2024 00:26:01 +0200 Subject: [PATCH] Repo updates. --- .github/workflows/fustat.yml | 8 +-- .gitignore | 1 + .secrets.template | 2 + Makefile | 13 +--- pyproject.toml | 44 ++++++++++++ src/README.md | 1 - tools/make/fustat_format_check.sh | 2 +- tools/make/poseidon_utils.patch | 112 ------------------------------ tools/make/requirements.txt | 9 --- tools/make/rewrite.sh | 3 - tools/make/setup.sh | 6 +- 11 files changed, 55 insertions(+), 146 deletions(-) create mode 100644 .secrets.template create mode 100644 pyproject.toml delete mode 100644 src/README.md delete mode 100644 tools/make/poseidon_utils.patch delete mode 100644 tools/make/requirements.txt delete mode 100755 tools/make/rewrite.sh diff --git a/.github/workflows/fustat.yml b/.github/workflows/fustat.yml index fe84b35..cee771a 100644 --- a/.github/workflows/fustat.yml +++ b/.github/workflows/fustat.yml @@ -28,12 +28,6 @@ jobs: uses: actions/setup-python@v2 with: python-version: 3.10.14 - - name: Set up Rust - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - override: true - - name: Setup repo run: make setup - name: Check cairo Formatting @@ -44,4 +38,4 @@ jobs: - name: Run fustat programs run: | source venv/bin/activate - pytest tests/fustat_programs/test_fustat.py -n auto -s + pytest tests/fustat_programs/test_fustat.py -n auto -s -x diff --git a/.gitignore b/.gitignore index 9cbb44e..c003096 100644 --- a/.gitignore +++ b/.gitignore @@ -177,3 +177,4 @@ venv *.sage.py *.idea *.secrets +tools/make/requirements.txt diff --git a/.secrets.template b/.secrets.template new file mode 100644 index 0000000..7be3e81 --- /dev/null +++ b/.secrets.template @@ -0,0 +1,2 @@ +# Read only to download artifacts in local CI. +GITHUB_TOKEN=ghp_ diff --git a/Makefile b/Makefile index b3413f6..923c789 100644 --- a/Makefile +++ b/Makefile @@ -8,17 +8,8 @@ build: setup: ./tools/make/setup.sh -bytecode-check: - ./tools/make/bytecode_check.sh - -rewrite: - ./tools/make/rewrite.sh - -steps: - ./tools/make/steps.sh - -ci-e2e: - ./tools/make/ci_e2e.sh +ci-fustat: + ./tools/make/ci_fustat.sh profile: @echo "A script to select, run & profile one Cairo file." diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..421ec3b --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,44 @@ +[project] +name = "garaga-zero" +version = "0.0.1" +requires-python = ">=3.10,<3.11" + +dependencies = [ +"garaga>=0.13.2a0", +"cairo-lang==0.13.2a0", +"protobuf==3.20.3", +"inquirer", +"pandas", +"tabulate", +"pytest", +"pre-commit", +] + + +[tool.isort] +profile = "black" + +[tool.pytest.ini_options] +cache_dir = "build/.pytest_cache" +testpaths = ["tests/hydra"] +# addopts = "--tb=short --showlocals" +asyncio_default_fixture_loop_scope = "function" # Explicitly set the loop scope + +[tool.black] +line-length = 88 +target-version = ['py310'] +include = '\.pyi?$' +extend-exclude = ''' +/( + # directories + \.eggs + | \.git + | \.hg + | \.mypy_cache + | \.tox + | \.venv + | \venv + | build + | dist +)/ +''' diff --git a/src/README.md b/src/README.md deleted file mode 100644 index 9cb10a7..0000000 --- a/src/README.md +++ /dev/null @@ -1 +0,0 @@ -Fustat directory contains CairoZero source code only. diff --git a/tools/make/fustat_format_check.sh b/tools/make/fustat_format_check.sh index d7cf2c8..3814300 100755 --- a/tools/make/fustat_format_check.sh +++ b/tools/make/fustat_format_check.sh @@ -17,7 +17,7 @@ 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 +find ./src ./tests/fustat_programs -name '*.cairo' | parallel --halt soon,fail=1 format_file # Capture the exit status of parallel exit_status=$? diff --git a/tools/make/poseidon_utils.patch b/tools/make/poseidon_utils.patch deleted file mode 100644 index 374eaeb..0000000 --- a/tools/make/poseidon_utils.patch +++ /dev/null @@ -1,112 +0,0 @@ ---- venv/lib/python3.9/site-packages/starkware/cairo/common/poseidon_utils.py 2023-08-11 11:27:27.000000000 +0200 -+++ tools/make/poseidon_patch.py 2023-09-10 20:25:03.298128497 +0200 -@@ -4,12 +4,10 @@ - """ - - import hashlib --from typing import Iterable, List, Optional, Type -- --import numpy as np -+from typing import List, Optional, Type - - from starkware.cairo.lang.cairo_constants import DEFAULT_PRIME --from starkware.python.math_utils import pow_mod, safe_div -+from starkware.python.math_utils import safe_div - - - def generate_round_constant(fn_name: str, field_prime: int, idx: int) -> int: -@@ -39,9 +37,7 @@ - - poseidon_small_params: Optional["PoseidonParams"] = None - -- def __init__( -- self, field_prime: int, r: int, c: int, r_f: int, r_p: int, mds: Iterable[Iterable[int]] -- ): -+ def __init__(self, field_prime: int, r: int, c: int, r_f: int, r_p: int): - self.field_prime = field_prime - self.r = r - self.c = c -@@ -53,22 +49,16 @@ - self.output_size = c - assert self.output_size <= r - # A list of r_f + r_p vectors for the Add-Round Key phase. -- self.ark = np.array( -- [ -- [generate_round_constant("Hades", field_prime, m * i + j) for j in range(m)] -- for i in range(n_rounds) -- ], -- dtype=object, -- ) -- -- # The MDS matrix for the MixLayer phase. -- self.mds = np.array(mds, dtype=object) -+ self.ark = [ -+ [generate_round_constant("Hades", field_prime, m * i + j) for j in range(m)] -+ for i in range(n_rounds) -+ ] - - @classmethod - def get_default_poseidon_params(cls: Type["PoseidonParams"]): - if cls.poseidon_small_params is None: - cls.poseidon_small_params = cls( -- field_prime=DEFAULT_PRIME, r=2, c=1, r_f=8, r_p=83, mds=SmallMds -+ field_prime=DEFAULT_PRIME, r=2, c=1, r_f=8, r_p=83 - ) - - return cls.poseidon_small_params -@@ -76,22 +66,22 @@ - - def hades_round(values, params: PoseidonParams, is_full_round: bool, round_idx: int): - # Add-Round Key. -- values = (values + params.ark[round_idx]) % params.field_prime -- -+ values = [ -+ (val + ark) % params.field_prime -+ for val, ark in zip(values, params.ark[round_idx]) -+ ] - # SubWords. - if is_full_round: -- values = pow_mod(values, 3, params.field_prime) -+ values = [pow(val, 3, params.field_prime) for val in values] - else: -- values[-1:] = pow_mod(values[-1:], 3, params.field_prime) -+ values[-1] = pow(values[-1], 3, params.field_prime) - - # MixLayer. -- values = params.mds.dot(values) % params.field_prime -+ values = mds_mul(values, params.field_prime) - return values - - - def hades_permutation(values: List[int], params: PoseidonParams) -> List[int]: -- assert len(values) == params.m -- values = np.array(values, dtype=object) - round_idx = 0 - # Apply r_f/2 full rounds. - for _ in range(safe_div(params.r_f, 2)): -@@ -105,9 +95,22 @@ - for _ in range(safe_div(params.r_f, 2)): - values = hades_round(values, params, True, round_idx) - round_idx += 1 -- assert round_idx == params.n_rounds -- return list(values) -+ return values -+ -+ -+def mds_mul(vector, field): -+ """ -+ Multiplies a vector by the SmallMds matrix. -+ [3, 1, 1] [r0] [3* r0 + r1 + r2 ] -+ [1, -1, 1] * [r1] = [r0 - r1 + r2 ] -+ [1, 1, -2] [r2] [r0 + r1 - 2 * r2] -+ """ -+ return [ -+ (3 * vector[0] + vector[1] + vector[2]) % field, -+ (vector[0] - vector[1] + vector[2]) % field, -+ (vector[0] + vector[1] - 2 * vector[2]) % field, -+ ] - - - # The actual config to be in use, with extremely small MDS coefficients. --SmallMds = [[3, 1, 1], [1, -1, 1], [1, 1, -2]] -+# SmallMds = [[3, 1, 1], [1, -1, 1], [1, 1, -2]] diff --git a/tools/make/requirements.txt b/tools/make/requirements.txt deleted file mode 100644 index ea34e83..0000000 --- a/tools/make/requirements.txt +++ /dev/null @@ -1,9 +0,0 @@ -cairo-lang==0.13.2a0 -protobuf==3.20.3 -inquirer -pandas -tabulate -pyarrow -pytest -pre-commit -garaga==0.13.2a0 diff --git a/tools/make/rewrite.sh b/tools/make/rewrite.sh deleted file mode 100755 index 6328216..0000000 --- a/tools/make/rewrite.sh +++ /dev/null @@ -1,3 +0,0 @@ -rm -rf src/cairo/src/tests/ -python hydra/garaga/precompiled_circuits/all_circuits.py -python hydra/garaga/starknet/tests_and_calldata_generators/test_writer.py diff --git a/tools/make/setup.sh b/tools/make/setup.sh index 70226e0..cbbd2a3 100755 --- a/tools/make/setup.sh +++ b/tools/make/setup.sh @@ -7,7 +7,7 @@ install_parallel() { # Linux if command -v apt-get >/dev/null; then # Debian/Ubuntu - sudo apt-get install -y parallel + sudo apt-get update && sudo apt-get install -y parallel elif command -v dnf >/dev/null; then # Fedora sudo dnf install -y parallel @@ -87,7 +87,9 @@ echo 'export PYTHONPYCACHEPREFIX="$PWD/venv/build/__pycache__"' >> venv/bin/acti echo "PROJECT_ROOT=$PWD" > .env echo "PYTHONPATH=$PWD/hydra" >> .env # For vscode python path when running in integrated terminal. source venv/bin/activate -pip install -r tools/make/requirements.txt +pip install uv +uv pip compile pyproject.toml --output-file tools/make/requirements.txt -q +uv pip install -r tools/make/requirements.txt # Install the commit hooks (black, isort) pre-commit install