Skip to content

Commit

Permalink
Merge branch 'main' into feat/fact_registry_bootloader
Browse files Browse the repository at this point in the history
  • Loading branch information
Okm165 committed Mar 25, 2024
2 parents c2e7279 + 3ea4a22 commit 3579746
Show file tree
Hide file tree
Showing 57 changed files with 8,041 additions and 5,581 deletions.
13 changes: 0 additions & 13 deletions .github/workflows/ci.yml

This file was deleted.

47 changes: 47 additions & 0 deletions .github/workflows/proof_verification_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Continuous Integration - proof verification tests

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
verify-proof:
runs-on: ubuntu-latest
strategy:
matrix:
layout: ["dex", "recursive", "recursive_with_poseidon", "small", "starknet"]
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup Scarb
uses: software-mansion/setup-scarb@v1

- name: Setup Rust toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1

- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: '3.10'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Configure layout
run: python configure.py -l ${{ matrix.layout }} -s keccak

- name: Build project
run: scarb build

- name: Test project
run: scarb test

- name: Run verification
run: cargo run --release --bin runner -- target/dev/cairo_verifier.sierra.json < examples/proofs/${{ matrix.layout }}/example_proof.json
21 changes: 21 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Continuous Integration - tests

on:
push:
pull_request:

jobs:
formatting-and-testing:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup Scarb
uses: software-mansion/setup-scarb@v1

- name: Format code
run: scarb fmt --check

- name: Run tests
run: scarb test
3 changes: 2 additions & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
scarb 2.6.0
scarb nightly-2024-03-16
starknet-foundry 0.20.0
12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ version = "0.1.0"
[workspace.dependencies]
anyhow = "1"
cairo-felt = "0.9"
cairo-lang-casm = "=2.6.0"
cairo-lang-runner = "=2.6.0"
cairo-lang-sierra = "=2.6.0"
cairo-lang-utils = "=2.6.0"
cairo-proof-parser = { git = "https://github.com/Okm165/cairo-proof-parser" }
cairo-vm = "=0.9.2"
cairo-lang-casm = { git = "https://github.com/starkware-libs/cairo/", rev = "4471a55923663eb8150ea6cd636d5c1038b137d1"}
cairo-lang-runner = { git = "https://github.com/starkware-libs/cairo/", rev = "4471a55923663eb8150ea6cd636d5c1038b137d1"}
cairo-lang-sierra = { git = "https://github.com/starkware-libs/cairo/", rev = "4471a55923663eb8150ea6cd636d5c1038b137d1"}
cairo-lang-utils = { git = "https://github.com/starkware-libs/cairo/", rev = "4471a55923663eb8150ea6cd636d5c1038b137d1"}
cairo-proof-parser = { git = "https://github.com/Okm165/cairo-proof-parser", rev = "97a04bbee07330311b38d6f4cecfed3acb237626"}
cairo-vm = "0.9.2"
clap = { version = "4.5.2", features = ["derive"] }
itertools = "0.12.0"
num-bigint = "0.4.4"
Expand Down
51 changes: 21 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ scarb build
scarb test
```

## Running the Verifier
## Running the Verifier on Example Proof

### Local Proof Verification

Expand All @@ -27,7 +27,7 @@ For local proof verification, follow these steps:
1. Run the verifier locally on example proof using the following command:

```bash
cargo run --release --bin runner -- target/dev/cairo_verifier.sierra.json < examples/proofs/example_proof.json
cargo run --release --bin runner -- target/dev/cairo_verifier.sierra.json < examples/proofs/recursive/example_proof.json
```

### Starknet Proof Verification
Expand All @@ -37,16 +37,29 @@ To verify proofs on Starknet, proceed with the following steps:
1. Prepare calldata of example proof for sncast:

```bash
cargo run --release --bin snfoundry_proof_serializer < examples/proofs/example_proof.json > examples/starknet/calldata
cargo run --release --bin snfoundry_proof_serializer < examples/proofs/recursive/example_proof.json > examples/starknet/calldata
```

2. Call the function with calldata on the Starknet contract:

```bash
cd examples/starknet
./call_contract.sh calldata
./1-verify-proof.sh 0x069df5a99fa42c37c946c58da0953d721b928078e740fef14da44e0f8c01f0f6 calldata
```

[List of deployed Verifier Contracts](deployed_contracts.md)

## Configure Verifier

By default, the verifier is configured for recursive layout and keccak hash for verifier unfriendly commitment layers. You can easily change that by using the configure python script (this script is in Experimental stage):

```bash
python configure.py -l recursive -s keccak
```

layout types: [dex, recursive, recursive_with_poseidon, small, starknet]
hash types: [keccak, blake2s]

## Creating a Proof

To create a proof, perform the following steps:
Expand Down Expand Up @@ -94,42 +107,20 @@ cairo-run \

```bash
./cpu_air_prover \
--out_file=../proofs/fibonacci_proof.json \
--out_file=../proofs/recursive/fibonacci_proof.json \
--private_input_file=fibonacci_private_input.json \
--public_input_file=fibonacci_public_input.json \
--prover_config_file=cpu_air_prover_config.json \
--parameter_file=cpu_air_params.json \
--generate_annotations
```

You can `verify` this the proof `locally` or on the `Starknet Cairo verifier` contract by specifying the path `examples/proofs/fibonacci_proof.json` to the newly generated proof.
You can verify this proof locally or on the Starknet Cairo verifier contract by specifying the path examples/proofs/recursive/fibonacci_proof.json to the newly generated proof.

## Benchmarking

In order to launch benchmarking just run this:
In order to launch benchmarking, just run this (it requires recursive layout configuration):

```bash
cargo run --release --bin benches -- target/dev/cairo_verifier.sierra.json
```

## Changing the Hasher

By default, the verifier uses Pedersen for verifier-friendly layers and Keccak for unfriendly layers. To change the hasher for unfriendly layers, use the provided Python script:

### Change to Blake2s

To change the hasher for unfriendly layers to Blake2s, run the following command:

```bash
python3 change_hasher.py -t blake
```

### Change to Keccak256

To change the hasher for unfriendly layers to Keccak256, run the following command:

```bash
python3 change_hasher.py -t keccak
```

---
```
88 changes: 0 additions & 88 deletions change_hasher.py

This file was deleted.

50 changes: 50 additions & 0 deletions configure.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import argparse
import sys
import inquirer
from pathlib import Path
from utils import process_file

LAYOUT_TYPES = ("dex", "recursive", "recursive_with_poseidon", "small", "starknet")
HASH_TYPES = ("keccak", "blake2s")


def select_types() -> str:
"""Prompts the user to select a type."""
questions = [
inquirer.List("layout_type", message="Select layout", choices=LAYOUT_TYPES),
inquirer.List("hash_type", message="Select hash", choices=HASH_TYPES),
]
answers = inquirer.prompt(questions)
return (answers["layout_type"], answers["hash_type"])


def main(layout_type=None, hash_type=None):
"""Main function for processing files."""
if layout_type is None or hash_type is None:
layout_type, hash_type = select_types()

if layout_type.lower() not in LAYOUT_TYPES:
print(f"Invalid layout type: {layout_type}")
sys.exit(1)

if hash_type.lower() not in HASH_TYPES:
print(f"Invalid hash type: {hash_type}")
sys.exit(1)

current_directory = Path("src")
for file_path in current_directory.rglob("*.cairo"):
if file_path.is_file():
process_file(file_path, [layout_type.upper(), hash_type.upper()])


if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Process files based on block type.")
parser.add_argument(
"-l", "--layout_type", type=str, help=f"Type of layouts {LAYOUT_TYPES}"
)
parser.add_argument(
"-s", "--hash_type", type=str, help=f"Type of hashes {HASH_TYPES}"
)
args = parser.parse_args()

main(args.layout_type, args.hash_type)
14 changes: 14 additions & 0 deletions deployed_contracts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
| Contract Address | Network | Layout |
|-----------------------------------------------------------------------------------------------------|-----------------------|--------------------------------|
| | **Mainnet** | **dex** |
| | **Mainnet** | **recursive** |
| | **Mainnet** | **recursive_with_poseidon** |
| | **Mainnet** | **small** |
| | **Mainnet** | **starknet** |
| | **Mainnet** | **starknet_with_keccak** |
| | **Sepolia Testnet** | **dex** |
|[0x069df5a99fa42c37c946c58da0953d721b928078e740fef14da44e0f8c01f0f6](https://sepolia.starkscan.co/contract/0x069df5a99fa42c37c946c58da0953d721b928078e740fef14da44e0f8c01f0f6) | **Sepolia Testnet** | **recursive** |
| | **Sepolia Testnet** | **recursive_with_poseidon** |
| | **Sepolia Testnet** | **small** |
| | **Sepolia Testnet** | **starknet** |
| | **Sepolia Testnet** | **starknet_with_keccak** |
Loading

0 comments on commit 3579746

Please sign in to comment.