Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support the new integrity calldata parser #13

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
409 changes: 296 additions & 113 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,21 @@ bincode = { version = "2.0.0-rc.3", default-features = false, features = [
] }
cairo-bootloader = { git = "https://github.com/zksecurity/cairo-bootloader" }
cairo-felt = "0.9.1"
cairo-proof-parser = { git = "https://github.com/Okm165/cairo-proof-parser", rev = "97a04bbee07330311b38d6f4cecfed3acb237626"}
cairo-vm = { git = "https://github.com/zksecurity/cairo-vm", features = ["extensive_hints"] }
clap = { version = "4.3.10", features = ["derive"] }
itertools = "0.13.0"
num-bigint = "0.4.6"
num-traits = "0.2.19"
rstest = "0.21.0"
serde = { version = "1.0", features = ["derive"], default-features = false }
serde_json = "1"
stark_evm_adapter = { git = "https://github.com/zksecurity/stark-evm-adapter.git", branch = "add-build-configs" }
stone-prover-sdk = { git = "https://github.com/zksecurity/stone-prover-sdk" }
swiftness_air = { git = "https://github.com/zksecurity/integrity-calldata-generator" }
swiftness_fri = { git = "https://github.com/zksecurity/integrity-calldata-generator" }
swiftness_proof_parser = { git = "https://github.com/zksecurity/integrity-calldata-generator" }
swiftness_stark = { git = "https://github.com/zksecurity/integrity-calldata-generator" }
starknet-crypto = "0.7.2"
tempfile = "3.10.1"
thiserror = "1.0.61"
uuid = "1.9.1"
Expand Down
48 changes: 29 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,19 @@ Currently, only `linux/amd64` with `AVX` is supported.
- `--annotation_file`
- `--extra_output_file`

### Serialize Proof

- Serialize a proof to a file
- `stone-cli serialize-proof --proof <proof-path> --network <network> --output <output-path>`
- Additional args:
- `--annotation_file`
- `--extra_output_file`
`--annotation_file` and `--extra_output_file` arguments are required when serializing a proof for Ethereum.

Using `--network starknet` serializes the Cairo proof into a format that can be verified on the Cairo verifier deployed on Starknet. Please refer to the [integrity documentation](https://github.com/HerodotusDev/integrity) for more information on how to use the calldata to send a transaction to Starknet.
### Serialize Proof

Using `--network ethereum` serializes the Cairo proof into a format that can be verified on the Solidity verifier deployed on Ethereum. Please refer to the [the next section](#how-to-create-proofs-and-verify-them-on-ethereum) for more information on how to create proofs that can be verified on Ethereum.
- Serialize a proof to be verified on Starknet or Ethereum
- Ethereum
- `stone-cli serialize-proof --proof <proof-path> --network ethereum --annotation_file <annotation-path> --extra_output_file <extra-output-path> --output <output-path>`
- Starknet
- [integrity](https://github.com/HerodotusDev/integrity) provides two types of serializations for Starknet
- monolith type (supports only `recursive` layout)
- `stone-cli serialize-proof --proof <proof-path> --network starknet --serialization_type monolith --output <output-path>`
- split type (supports `dex`, `small`, `recursive`, `recursive_with_poseidon`, `starknet`, and `starknet_with_keccak` layouts)
- `stone-cli serialize-proof --proof <proof-path> --network starknet --serialization_type split --output_dir <output-dir> --layout starknet`

### How to create proofs and verify them on Ethereum

Expand All @@ -90,6 +92,14 @@ Here are the specific steps for the above process:

4. Verify on Ethereum with the [evm-adapter CLI](https://github.com/zksecurity/stark-evm-adapter/tree/add-build-configs?tab=readme-ov-file#using-existing-proof) using the `bootloader_serialized_proof.json` and `fact_topologies.json` files as inputs

### How to create proofs and verify them on Starknet

1. Call `stone-cli prove --cairo_program <program-path> --layout <layout>` with a layout that is supported by either the `monolith` or `split` serialization types

2. Call `stone-cli serialize-proof --proof <proof-path> --network starknet --serialization_type monolith --output <output-path>` or `stone-cli serialize-proof --proof <proof-path> --network starknet --serialization_type split --output_dir <output-dir> --layout <layout>`

3. Verify on Starknet with [integrity](https://github.com/HerodotusDev/integrity) using the `output` file or files in the `output_dir` as input

#### Notes

- Cairo 0 programs that use hints are not supported
Expand All @@ -100,13 +110,13 @@ Here are the specific steps for the above process:

### List of supported builtins per layout

| Layout | dex | recursive | recursive_with_poseidon | small | starknet | starknet_with_keccak |
| ----------- | :-: | :-------: | :---------------------: | :---: | :------: | :------------------: |
| output | O | O | O | O | O | O |
| pedersen | O | O | O | O | O | O |
| range_check | O | O | O | O | O | O |
| bitwise | O | O | O | | O | O |
| ecdsa | O | | | | O | O |
| poseidon | | | O | | | |
| ec_op | | | | | O | O |
| keccak | | | | | | O |
| | small | recursive | dex | recursive_with_poseidon | starknet | starknet_with_keccak |
| ----------- | :---: | :-------: | :-: | :---------------------: | :------: | :------------------: |
| output | O | O | O | O | O | O |
| pedersen | O | O | O | O | O | O |
| range_check | O | O | O | O | O | O |
| bitwise | | O | | O | O | O |
| ecdsa | | | O | | O | O |
| poseidon | | | | O | O | O |
| ec_op | | | | | O | O |
| keccak | | | | | | O |
4 changes: 2 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ fn download_executables(config: &Config) {
let download_file_path = download_dir.join(download_file_name);
download_from_url(url, &download_file_path);
unzip_file(&download_file_path, &download_dir);
move_files(&download_dir, &download_file_name, &config.file_names);
move_files(&download_dir, download_file_name, &config.file_names);
remove_file(&download_file_path).expect("Failed to remove tar file");

let sha256_sums = &dist.sha256_sums;
validate_unpacked_files(&download_dir, &config.file_names, &sha256_sums);
validate_unpacked_files(&download_dir, &config.file_names, sha256_sums);
set_execute_permissions(config);
}

Expand Down
46 changes: 40 additions & 6 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pub use crate::prover;
use clap::{Args, Parser, ValueHint};
use prover::config::{ProverConfig, ProverParametersConfig};
use serde::{Deserialize, Serialize};
use std::fmt;
use std::path::PathBuf;

#[derive(Parser, Debug)]
Expand Down Expand Up @@ -121,6 +122,12 @@ define_enum! {
dynamic => "all_cairo",
}

impl fmt::Display for LayoutName {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{:?}", self)
}
}

impl std::str::FromStr for LayoutName {
type Err = ();

Expand Down Expand Up @@ -174,26 +181,53 @@ pub struct SerializeArgs {
#[clap(long = "network", value_enum)]
pub network: Network,

#[clap(long = "output")]
pub output: PathBuf,
#[clap(long = "output", value_hint=ValueHint::FilePath, required_if_eq_any([("serialization_type", "monolith"), ("network", "ethereum")]))]
pub output: Option<PathBuf>,

#[clap(long = "output_dir", value_hint=ValueHint::DirPath, help="Output directory for storing split proof files. Required for creating split proofs for Starknet", required_if_eq("serialization_type", "split"))]
pub output_dir: Option<PathBuf>,

#[clap(
long = "layout",
help = "Only required for creating split proofs for Starknet",
value_enum,
required_if_eq("serialization_type", "split")
)]
pub layout: Option<LayoutName>,

#[clap(
long = "annotation_file",
help = "Path to the file containing elements generated from the interaction between the prover and verifier",
value_hint=ValueHint::FilePath
help = "Path to the file containing elements generated from the interaction between the prover and verifier. Required to verify on Ethereum",
value_hint=ValueHint::FilePath,
required_if_eq("network", "ethereum")
)]
pub annotation_file: Option<PathBuf>,

#[clap(
long = "extra_output_file",
help = "Path to the file containing additional interaction elements necessary for generating split proofs",
value_hint=ValueHint::FilePath
help = "Path to the file containing additional interaction elements necessary for generating split proofs. Required to verify on Ethereum",
value_hint=ValueHint::FilePath,
required_if_eq("network", "ethereum")
)]
pub extra_output_file: Option<PathBuf>,

#[clap(
long = "serialization_type",
help = "Whether to split the proof or not to verify on Starknet. See https://github.com/HerodotusDev/integrity for more details",
value_enum,
required_if_eq("network", "starknet")
)]
pub serialization_type: Option<SerializationType>,
}

define_enum! {
Network,
starknet => "starknet",
ethereum => "ethereum",
}

define_enum! {
SerializationType,
monolith => "monolith",
split => "split",
}
Loading
Loading