Skip to content

Commit

Permalink
Merge pull request #50 from zksecurity/dynamic-layout
Browse files Browse the repository at this point in the history
WIP: Support for Dynamic Layout
  • Loading branch information
mellowcroc authored Feb 7, 2025
2 parents d5caef3 + 8462dd5 commit a5937a6
Show file tree
Hide file tree
Showing 13 changed files with 2,901 additions and 461 deletions.
1,804 changes: 1,494 additions & 310 deletions Cargo.lock

Large diffs are not rendered by default.

38 changes: 33 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ anyhow = "1.0.86"
bincode = { version = "2.0.0-rc.3", default-features = false, features = [
"serde",
] }
cairo-bootloader = { git = "https://github.com/zksecurity/cairo-bootloader", rev = "ca1435a6cf52c7cea6d98e1c4edecff8424b4bae" }
cairo-bootloader = { git = "https://github.com/zksecurity/cairo-bootloader", rev = "91e8121221140317f0f4d6ba7a59b16ec7ff2d7d" }
cairo-felt = "0.9.1"
cairo1-run = { git = "https://github.com/zksecurity/cairo-vm", package = "cairo1-run", features = ["mod_builtin"], rev = "ac8b81b79f65f5017fe0929bf4025be4a0e9c73c" }
cairo-vm = { git = "https://github.com/zksecurity/cairo-vm", features = [
"extensive_hints",
], rev = "3cfcd1d035a4f6951337e6f4cc26014a0aa7e47e" }
"extensive_hints", "mod_builtin"
], rev = "ac8b81b79f65f5017fe0929bf4025be4a0e9c73c" }
cairo-lang-compiler = { version = "=2.10.0-rc.0", default-features = false }
cairo-lang-filesystem = { version = "=2.10.0-rc.0", default-features = false }
clap = { version = "4.3.10", features = ["derive"] }
itertools = "0.13.0"
num-bigint = "0.4.6"
Expand All @@ -27,14 +30,39 @@ swiftness_proof_parser = { git = "https://github.com/zksecurity/integrity-callda
swiftness_stark = { git = "https://github.com/zksecurity/integrity-calldata-generator", rev = "6f2dd268274e40e5ea75e2f17aff6b8e53f8f499" }
swiftness = { git = "https://github.com/zksecurity/integrity-calldata-generator", rev = "6f2dd268274e40e5ea75e2f17aff6b8e53f8f499" }
starknet-crypto = "0.7.2"
tempfile = "3.10.1"
tempfile = "3.10.1"
thiserror = "1.0.61"


# reqwest = { git = "https://github.com/seanmonstar/reqwest.git", rev = "28d25bd0a6437cdd8dbec22619f2675b7f97d172", features = [
# "json",
# "blocking",
# "rustls-tls",
# ] }
uuid = "1.9.1"
log = "0.4.25"
rpassword = "7.3.1"
rustls-pemfile = "2.2.0"
rustls-pki-types = "1.10.1"
pkcs8 = { version = "0.10.2", features = [
"encryption",
"3des",
"des-insecure",
"pem",
"alloc",
"pkcs5",
] }
rustls = "0.23.21"
curl = "0.4.47"

[build-dependencies]
reqwest = { version = "0.12", features = [
"json",
"blocking",
"rustls-tls",
], default-features = false }
flate2 = "1.0.30"
once_cell = "1.18"
reqwest = { version = "0.12.5", features = ["blocking"] }
serde = { version = "1.0", features = ["derive"], default-features = false }
serde_json = "1"
sha256 = "1.5.0"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ Here are the specific steps for the above process:
## Common issues

```bash
Error: Failed to run cairo1: cairo1-run failed with error: Error: VirtualMachine(Memory(AddressNotRelocatable))
Error: Failed to run cairo1: Memory addresses must be relocatable
```

This error occurs when the program uses a builtin that is not supported by the layout. Refer to the [List of supported builtins per layout](#list-of-supported-builtins-per-layout) to find the right layout for theprogram.
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ fn download_corelib_repo(config: &Config, tmp_dir_path: &Path) {
return;
}

let url = "https://github.com/starkware-libs/cairo/releases/download/v2.9.0-dev.0/release-x86_64-unknown-linux-musl.tar.gz";
let url = "https://github.com/starkware-libs/cairo/releases/download/v2.10.0-rc.1/release-x86_64-unknown-linux-musl.tar.gz";
let tmp_download_file_path = tmp_dir_path.join("release-x86_64-unknown-linux-musl.tar.gz");
download_from_url(url, &tmp_download_file_path);
unzip_file(&tmp_download_file_path, tmp_dir_path);
Expand Down
134 changes: 121 additions & 13 deletions src/args.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::define_enum;
pub use crate::prover;
use crate::utils::{process_args, FuncArgs};

use clap::{Args, Parser, ValueHint};
use prover::config::{ProverConfig, ProverParametersConfig};
Expand Down Expand Up @@ -33,20 +34,54 @@ pub struct ProveArgs {

#[clap(
long = "program_input",
help = "Arguments should be spaced, with array elements placed between brackets, e.g. '1 2 [1 2 3]'"
default_value = "",
value_parser = process_args,
help = "Arguments should be spaced, with array elements placed between brackets, e.g. '1 2 [1 2 3]'",
conflicts_with = "program_input_file"
)]
pub program_input: Option<String>,
pub program_input: FuncArgs,

#[clap(long = "program_input_file", value_hint=ValueHint::FilePath, conflicts_with="program_input")]
#[clap(
long = "program_input_file",
value_hint=ValueHint::FilePath,
conflicts_with="program_input"
)]
pub program_input_file: Option<PathBuf>,

#[clap(long = "layout", default_value = "recursive", value_enum)]
pub layout: LayoutName,

#[clap(long = "prover_config_file", conflicts_with_all = ["store_full_lde", "use_fft_for_eval", "constraint_polynomial_task_size", "n_out_of_memory_merkle_layers", "table_prover_n_tasks_per_segment"])]
#[clap(
long = "prover_config_file",
conflicts_with_all = [
"store_full_lde",
"use_fft_for_eval",
"constraint_polynomial_task_size",
"n_out_of_memory_merkle_layers",
"table_prover_n_tasks_per_segment"
]
)]
pub prover_config_file: Option<PathBuf>,

#[clap(long = "parameter_file", conflicts_with_all = ["field", "channel_hash", "commitment_hash", "n_verifier_friendly_commitment_layers", "pow_hash", "page_hash", "fri_step_list", "last_layer_degree_bound", "n_queries", "proof_of_work_bits", "log_n_cosets", "use_extension_field", "verifier_friendly_channel_updates", "verifier_friendly_commitment_hash"])]
#[clap(
long = "parameter_file",
conflicts_with_all = [
"field",
"channel_hash",
"commitment_hash",
"n_verifier_friendly_commitment_layers",
"pow_hash",
"page_hash",
"fri_step_list",
"last_layer_degree_bound",
"n_queries",
"proof_of_work_bits",
"log_n_cosets",
"use_extension_field",
"verifier_friendly_channel_updates",
"verifier_friendly_commitment_hash"
]
)]
pub parameter_file: Option<PathBuf>,

#[clap(long = "output", default_value = "./proof.json")]
Expand All @@ -67,25 +102,67 @@ pub struct ProveArgs {

#[derive(Args, Debug)]
pub struct ProveBootloaderArgs {
#[clap(long = "cairo_programs", value_hint=ValueHint::FilePath, value_delimiter = ' ', num_args = 1..)]
#[clap(
long = "cairo_programs",
value_hint=ValueHint::FilePath,
value_delimiter = ' ',
num_args = 1..
)]
pub cairo_programs: Option<Vec<PathBuf>>,

#[clap(long = "cairo_pies", value_hint=ValueHint::FilePath, value_delimiter = ' ', num_args = 1..)]
#[clap(
long = "cairo_pies",
value_hint=ValueHint::FilePath,
value_delimiter = ' ',
num_args = 1..
)]
pub cairo_pies: Option<Vec<PathBuf>>,

#[clap(long = "layout", default_value = "starknet", value_enum)]
pub layout: LayoutName,

#[clap(long = "prover_config_file", conflicts_with_all = ["store_full_lde", "use_fft_for_eval", "constraint_polynomial_task_size", "n_out_of_memory_merkle_layers", "table_prover_n_tasks_per_segment"])]
#[clap(
long = "prover_config_file",
conflicts_with_all = [
"store_full_lde",
"use_fft_for_eval",
"constraint_polynomial_task_size",
"n_out_of_memory_merkle_layers",
"table_prover_n_tasks_per_segment"
]
)]
pub prover_config_file: Option<PathBuf>,

#[clap(long = "parameter_file", conflicts_with_all = ["field", "channel_hash", "commitment_hash", "n_verifier_friendly_commitment_layers", "pow_hash", "page_hash", "fri_step_list", "last_layer_degree_bound", "n_queries", "proof_of_work_bits", "log_n_cosets", "use_extension_field", "verifier_friendly_channel_updates", "verifier_friendly_commitment_hash"])]
#[clap(
long = "parameter_file",
conflicts_with_all = [
"field",
"channel_hash",
"commitment_hash",
"n_verifier_friendly_commitment_layers",
"pow_hash",
"page_hash",
"fri_step_list",
"last_layer_degree_bound",
"n_queries",
"proof_of_work_bits",
"log_n_cosets",
"use_extension_field",
"verifier_friendly_channel_updates",
"verifier_friendly_commitment_hash"
]
)]
pub parameter_file: Option<PathBuf>,

#[clap(long = "output", default_value = "./bootloader_proof.json")]
pub output: PathBuf,

#[clap(long = "fact_topologies_output", default_value = "./fact_topologies.json", value_hint=ValueHint::FilePath, help = "Output of bootloader required along with bootloader_proof.json to split proofs for Ethereum")]
#[clap(
long = "fact_topologies_output",
default_value = "./fact_topologies.json",
value_hint=ValueHint::FilePath,
help = "Output of bootloader required along with bootloader_proof.json to split proofs for Ethereum"
)]
pub fact_topologies_output: PathBuf,

#[clap(flatten)]
Expand All @@ -109,10 +186,18 @@ pub struct VerifyArgs {
#[clap(long = "proof", value_parser)]
pub proof: PathBuf,

#[clap(long = "annotation_file", value_hint=ValueHint::FilePath, help = "Path to the output file that will contain elements generated from the interaction between the prover and verifier")]
#[clap(
long = "annotation_file",
value_hint=ValueHint::FilePath,
help = "Path to the output file that will contain elements generated from the interaction between the prover and verifier"
)]
pub annotation_file: Option<PathBuf>,

#[clap(long = "extra_output_file", value_hint=ValueHint::FilePath, help = "Path to the output file that will contain additional interaction elements necessary for generating split proofs")]
#[clap(
long = "extra_output_file",
value_hint=ValueHint::FilePath,
help = "Path to the output file that will contain additional interaction elements necessary for generating split proofs"
)]
pub extra_output_file: Option<PathBuf>,

#[clap(long = "stone_version", default_value = "v6", value_enum)]
Expand All @@ -137,7 +222,27 @@ define_enum! {
recursive_with_poseidon => "recursive_with_poseidon",
all_solidity => "all_solidity",
all_cairo => "all_cairo",
dynamic => "all_cairo",
dynamic => "dynamic",
automatic => "automatic",
}

impl LayoutName {
pub fn to_stone_layout(&self) -> &'static str {
match self {
LayoutName::plain => "plain",
LayoutName::small => "small",
LayoutName::dex => "dex",
LayoutName::recursive => "recursive",
LayoutName::starknet => "starknet",
LayoutName::starknet_with_keccak => "starknet_with_keccak",
LayoutName::recursive_large_output => "recursive_large_output",
LayoutName::recursive_with_poseidon => "recursive_with_poseidon",
LayoutName::all_solidity => "all_solidity",
LayoutName::all_cairo => "all_cairo",
LayoutName::dynamic => "dynamic",
LayoutName::automatic => "dynamic",
}
}
}

impl fmt::Display for LayoutName {
Expand All @@ -162,6 +267,7 @@ impl std::str::FromStr for LayoutName {
"all_solidity" => Ok(LayoutName::all_solidity),
"all_cairo" => Ok(LayoutName::all_cairo),
"dynamic" => Ok(LayoutName::dynamic),
"automatic" => Ok(LayoutName::automatic),
_ => Err(()),
}
}
Expand All @@ -187,6 +293,8 @@ impl LayoutName {
LayoutName::all_solidity => cairo_vm::types::layout_name::LayoutName::all_solidity,
LayoutName::all_cairo => cairo_vm::types::layout_name::LayoutName::all_cairo,
LayoutName::dynamic => cairo_vm::types::layout_name::LayoutName::dynamic,
// uses the SHARP API to determine the dynamic layout parameters
LayoutName::automatic => cairo_vm::types::layout_name::LayoutName::dynamic,
}
}
}
Expand Down
Loading

0 comments on commit a5937a6

Please sign in to comment.