Skip to content

Commit

Permalink
Merge pull request #13 from zksecurity/support-new-integrity-calldata…
Browse files Browse the repository at this point in the history
…-parser

Support the new integrity calldata parser
  • Loading branch information
mellowcroc authored Oct 9, 2024
2 parents c17c7ae + 620e5f9 commit 41fddfa
Show file tree
Hide file tree
Showing 17 changed files with 4,295 additions and 188 deletions.
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,16 +110,16 @@ 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 |

### Commands diagram

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

0 comments on commit 41fddfa

Please sign in to comment.