Skip to content

Commit

Permalink
pip install garaga==0.13.2, garaga (#166)
Browse files Browse the repository at this point in the history
- adds garaga cli
- adds devnet declare - deploy - invoke tests in CI 
- remove cairo-lang dependency and cairo zero code, moved to https://github.com/feltroidprime/garaga-zero , dependent on the garaga pip package for the hints
- remove kkt endpoint contract as the work will be done in kkrt repo directly
- uses only pyproject.toml for dependencies (splitted in normal and dev dependencies), no more requirements.txt
- uses uv at setup instead of pip which resolves and installs much quicker
- update to cairo 2.7.1. The ECIP class hash has changed due to it. 
- changes bn_bits encoding in the miller loop to save one iteration
  • Loading branch information
feltroidprime authored Aug 24, 2024
1 parent aed2291 commit 1d75c78
Show file tree
Hide file tree
Showing 131 changed files with 6,150 additions and 432,735 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/cairo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- uses: actions/checkout@v3
- uses: software-mansion/setup-scarb@v1
with:
scarb-version: "2.7.0"
scarb-version: "2.7.1"
- run: scarb fmt --check
working-directory: src/cairo
- run: cd src/cairo && scarb test
working-directory: src/
- run: cd src/ && scarb test
29 changes: 15 additions & 14 deletions .github/workflows/fustat.yml → .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Cairo Zero (Fustat) tests
name: E2E-devnet

on:
push:
Expand All @@ -18,10 +18,11 @@ jobs:
with:
concurrent_skipping: 'same_content_newer'

test-fustat:
devnet-test:
needs: pre_job
if: needs.pre_job.outputs.should_skip != 'true'
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10.14
Expand All @@ -33,16 +34,16 @@ jobs:
with:
toolchain: stable
override: true
components: rustfmt, clippy

- name: Setup repo
profile: minimal
- name: Setup Scarb
uses: software-mansion/setup-scarb@v1
with:
scarb-version: "2.7.1"
- name: Install dependencies
run: make setup
- 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 clean && ./tools/make/build.sh tests
- name: Run fustat programs
run: |
source venv/bin/activate
pytest tests/fustat_programs/test_fustat.py -n auto -s

- name: Install devnet
run: ./tests/contracts_e2e/install_devnet.sh

- name: Run tests
run: source venv/bin/activate && pytest -s -x tests/contracts_e2e/e2e_test.py
23 changes: 10 additions & 13 deletions .github/workflows/hydra.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,28 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Set up Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
profile: minimal

- 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/hydra/:$PYTHONPATH"' >> venv/bin/activate
pip install -r tools/make/requirements.txt
run: make setup

- name: Check Black formatting
run: source venv/bin/activate && black --check .
- name: Set up Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
components: rustfmt, clippy

- name: Compile Rust bindings with maturin
- name: Test garaga_rs
run: |
source venv/bin/activate
(cd tools/garaga_rs && cargo fmt --check && cargo test)
maturin develop --release
- name: Run pytest
run: |
source venv/bin/activate
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@ venv
*.so
*.html
*.sage.py
*.idea
*.secrets

tools/garaga_rs/target/
tools/garaga_rs/Cargo.lock
tools/make/requirements.txt

src/cairo/target/
*target*

tests/contracts_e2e/devnet/*

!hydra/garaga/starknet/groth16_contract_generator/examples/*.json
18 changes: 13 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
repos:
- repo: https://github.com/myint/autoflake
rev: v1.4
hooks:
- id: autoflake
args: ["--in-place", "--remove-all-unused-imports"]
files: \.py$
- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
args: ["--profile", "black"]
files: \.py$
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
Expand All @@ -11,8 +23,4 @@ repos:
rev: 24.4.2
hooks:
- id: black
- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
args: ["--profile", "black"]
files: \.py$
7 changes: 7 additions & 0 deletions .secrets.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
SEPOLIA_RPC_URL="https://free-rpc.nethermind.io/sepolia-juno"
SEPOLIA_ACCOUNT_PRIVATE_KEY=0x1
SEPOLIA_ACCOUNT_ADDRESS=0x2

MAINNET_RPC_URL="https://"
MAINNET_ACCOUNT_PRIVATE_KEY=0x3
MAINNET_ACCOUNT_ADDRESS=0x4
29 changes: 2 additions & 27 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
.PHONY: build test coverage run run-profile
cairo_files = $(shell find ./tests/cairo_programs -name "*.cairo")

build:
$(MAKE) clean
./tools/make/build.sh

setup:
./tools/make/setup.sh
Expand All @@ -17,32 +15,9 @@ rewrite:
steps:
./tools/make/steps.sh

ci-e2e:
./tools/make/ci_e2e.sh

profile:
@echo "A script to select, run & profile one Cairo file."
@echo "Thank you for trying to improve Garaga's speed!"
./tools/make/launch_cairo_files.py -profile

profile-no-compile:
@echo "A script to select, run & profile one Cairo file. File must be already compiled."
@echo "Thank you for trying to improve Garaga's speed!"
./tools/make/launch_cairo_files.py -profile -no_compile
run:
@echo "A script to select, compile & run one Cairo file"
@echo "Total number of steps will be shown at the end of the run."
@echo "Thank you for testing Garaga!"
./tools/make/launch_cairo_files.py

run-no-compile:
@echo "A script to select, run one Cairo file without compiling it"
@echo "Thank you for testing Garaga!"
./tools/make/launch_cairo_files.py -no_compile

run-pie:
@echo "A script to select, compile & run one Cairo file with pie mode enabled"
@echo "Total number of steps will be shown at the end of the run."
@echo "Thank you for proving Garaga!"
./tools/make/launch_cairo_files.py -pie
clean:
rm -rf build/compiled_cairo_files
mkdir -p build
Expand Down
23 changes: 15 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,25 +49,32 @@ Garaga consists of a Pythonic backend with Rust bindings and CairoZero / Cairo l
It also handles witnesses generation for the non-deterministic computations, smart contract contract generation for a given proof system and elliptic curve, and calldata generation from a given proof.
- The CairoZero / Starknet interfaces are responsible for composing and calling the circuits, as well as adding all the extra logic needed to make the algorithms work (Fiat-Shamir heuristic, SNARKS verifiers algorithms, etc).

## Deploying SNARKS verifier on Starknet
## Quickstart : deploying a SNARK verifier on Starknet

Docs and CLI incoming.
Checkout `hydra/garaga/starknet/groth16_contract_generator/generator.py` in the meantime.
Currently, only Groth16 on BN254 and BLS12_381 is supported with automatic support for json files coming from SnarkJS and Gnark.

## Verify a proof against a specific SNARK verifier contract
1. Create a new directory for you project, and bring the jsons files for verification key, proof file and public inputs inside it.
2. Install the garaga pip package with `pip install garaga`. Python3.10 is mandatory and a virtual environment is recommended. Enter `garaga` in your terminal to get started.
3. Run the `garaga gen` command in your terminal to generate the code for the SNARK verifier given your verification key.
4. Edit the generated smart contract to fit the needs of your dapp.

Docs, CLI and browser support incoming.
Checkout `hydra/garaga/starknet/groth16_contract_generator/calldata.py` in the meantime.
5. Create an environment file `.secrets` following the `.secrets.template` file in the root of this repository, containing the Starkner RPC url, your account address, and the private key.
6. Run the `garaga declare` command in your terminal to declare the smart contract on Starknet and obtain its class hash. Note that this is an expensive operation.
7. Run the `garaga deploy` command in your terminal using the class hash obtained in the previous step to get the contract address.

## Development setup
7. Run the `garaga verify-onchain` command in your terminal using the contract address, the verification key, the proof and the public inputs to verify the proof against the SNARK verifier contract.

For more details, please refer to the [documentation](https://felt.gitbook.io/garaga/).

## Developer setup

To get started with Garaga, you'll need to have some tools and dependencies installed. Here's everything you need:

### Prerequisites

Ensure you have the following installed:
- [Python 3.10](https://www.python.org/downloads/) - /!\ Make sure `python3.10` is a valid command in your terminal. The core language used for development. Make sure you have the correct dependencies installed (in particular, GMP) for the `fastecdsa` python package. See [here](https://pypi.org/project/fastecdsa/#installing) for linux and [here](https://github.com/AntonKueltz/fastecdsa/issues/74) for macos.
- [Scarb 2.7.0](https://docs.swmansion.com/scarb/download.html) - The Cairo package manager. Comes with Cairo inside. Requires [Rust](https://www.rust-lang.org/tools/install).
- [Scarb 2.7.1](https://docs.swmansion.com/scarb/download.html) - The Cairo package manager. Comes with Cairo inside. Requires [Rust](https://www.rust-lang.org/tools/install).

##### Optionally :

Expand Down
Loading

0 comments on commit 1d75c78

Please sign in to comment.