Skip to content

Commit c6207ba

Browse files
chore: feature gate revm and alloy imports (#1572)
Previously we were very sloppy with enabling of features: `openvm-native-recursion` was always enabling the `snark-verifier` feature "revm" which imports a fixed version of revm only used for testing purposes. Since revm version changes rather frequently, this can cause Cargo dependency conflicts if someone wants to use the SDK with another version of revm. I've added new features "evm-prove" and "evm-verify" to `openvm-native-recursion`, `openvm-sdk`, `cargo-openvm` so that - "evm-prove" allows for generation of EVM halo2 proofs, which just enables some additional features in `snark-verifier` but no additional other dependencies. - "evm-verify" allows for revm simulation of EVM contract calls to verify halo2 proofs. This includes imports of `revm` and some `alloy` crates, with fixed versions. If you enable this feature (on by default), the revm and alloy versions will be fixed in the cargo tree. Also added some re-exported features to SDK and CLI, and switched default memory allocator to `jemalloc` since that's what we mostly use.
1 parent e4e180c commit c6207ba

File tree

23 files changed

+226
-161
lines changed

23 files changed

+226
-161
lines changed

.github/workflows/lints.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ jobs:
4545
run: |
4646
# list of features generated using:
4747
# echo -e "\033[1;32mAll unique features across workspace:\033[0m" && cargo metadata --format-version=1 --no-deps | jq -r '.packages[].features | to_entries[] | .key' | sort -u | sed 's/^/• /'
48-
cargo clippy --all-targets --all --tests --features "aggregation bench-metrics bls12_381 bn254 default entrypoint export-getrandom export-libm function-span getrandom halo2-compiler halo2curves heap-embedded-alloc k256 mimalloc nightly-features panic-handler parallel rust-runtime static-verifier std test-utils unstable" -- -D warnings
49-
cargo clippy --all-targets --all --tests --no-default-features --features "jemalloc jemalloc-prof" -- -D warnings
48+
cargo clippy --all-targets --all --tests --features "aggregation bench-metrics bls12_381 bn254 default entrypoint evm-prove evm-verify export-getrandom export-libm function-span getrandom halo2-compiler halo2curves heap-embedded-alloc k256 jemalloc jemalloc-prof nightly-features panic-handler parallel rust-runtime static-verifier std test-utils unstable" -- -D warnings
49+
cargo clippy --all-targets --all --tests --no-default-features --features "mimalloc" -- -D warnings
5050
5151
- name: Run fmt, clippy for guest
5252
run: |

benchmarks/execute/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@ tracing-subscriber = { version = "0.3.17", features = ["std", "env-filter"] }
3030
criterion = { version = "0.5", features = ["html_reports"] }
3131

3232
[features]
33-
default = ["mimalloc"]
33+
default = ["jemalloc"]
3434
profiling = ["openvm-sdk/profiling"]
35-
aggregation = []
3635
mimalloc = ["openvm-circuit/mimalloc"]
3736
jemalloc = ["openvm-circuit/jemalloc"]
3837
jemalloc-prof = ["openvm-circuit/jemalloc-prof"]

benchmarks/prove/Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ license.workspace = true
1010
[dependencies]
1111
openvm-benchmarks-utils.workspace = true
1212
openvm-circuit.workspace = true
13-
openvm-sdk.workspace = true
13+
openvm-sdk = { workspace = true, features = ["evm-verify"] }
1414
openvm-stark-backend.workspace = true
1515
openvm-stark-sdk.workspace = true
1616
openvm-transpiler.workspace = true
@@ -43,11 +43,10 @@ tracing.workspace = true
4343
[dev-dependencies]
4444

4545
[features]
46-
default = ["parallel", "mimalloc", "bench-metrics"]
46+
default = ["parallel", "jemalloc", "bench-metrics"]
4747
bench-metrics = ["openvm-native-recursion/bench-metrics"]
4848
profiling = ["openvm-sdk/profiling"]
4949
aggregation = []
50-
static-verifier = ["openvm-native-recursion/static-verifier"]
5150
parallel = ["openvm-native-recursion/parallel"]
5251
mimalloc = ["openvm-circuit/mimalloc"]
5352
jemalloc = ["openvm-circuit/jemalloc"]

benchmarks/prove/src/bin/fib_e2e.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use openvm_rv32im_transpiler::{
1010
Rv32ITranspilerExtension, Rv32IoTranspilerExtension, Rv32MTranspilerExtension,
1111
};
1212
use openvm_sdk::{
13-
commit::commit_app_exe, prover::ContinuationProver, DefaultStaticVerifierPvHandler, Sdk, StdIn,
13+
commit::commit_app_exe, prover::EvmHalo2Prover, DefaultStaticVerifierPvHandler, Sdk, StdIn,
1414
};
1515
use openvm_stark_sdk::{
1616
bench::run_with_metric_collection, config::baby_bear_poseidon2::BabyBearPoseidon2Engine,
@@ -58,7 +58,7 @@ async fn main() -> Result<()> {
5858
let mut stdin = StdIn::default();
5959
stdin.write(&n);
6060
run_with_metric_collection("OUTPUT_PATH", || {
61-
let mut e2e_prover = ContinuationProver::<_, BabyBearPoseidon2Engine>::new(
61+
let mut e2e_prover = EvmHalo2Prover::<_, BabyBearPoseidon2Engine>::new(
6262
&halo2_params_reader,
6363
app_pk,
6464
app_committed_exe,

benchmarks/prove/src/bin/kitchen_sink.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use openvm_ecc_circuit::{WeierstrassExtension, P256_CONFIG, SECP256K1_CONFIG};
1010
use openvm_native_recursion::halo2::utils::{CacheHalo2ParamsReader, DEFAULT_PARAMS_DIR};
1111
use openvm_pairing_circuit::{PairingCurve, PairingExtension};
1212
use openvm_sdk::{
13-
commit::commit_app_exe, config::SdkVmConfig, prover::ContinuationProver,
13+
commit::commit_app_exe, config::SdkVmConfig, prover::EvmHalo2Prover,
1414
DefaultStaticVerifierPvHandler, Sdk, StdIn,
1515
};
1616
use openvm_stark_sdk::{
@@ -80,7 +80,7 @@ fn main() -> Result<()> {
8080
)?;
8181

8282
run_with_metric_collection("OUTPUT_PATH", || -> Result<()> {
83-
let mut prover = ContinuationProver::<_, BabyBearPoseidon2Engine>::new(
83+
let mut prover = EvmHalo2Prover::<_, BabyBearPoseidon2Engine>::new(
8484
&halo2_params_reader,
8585
app_pk,
8686
app_committed_exe,

crates/cli/Cargo.toml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ vergen = { version = "8", default-features = false, features = [
1919
[dependencies]
2020
openvm-build = { workspace = true }
2121
openvm-transpiler = { workspace = true }
22-
openvm-native-recursion = { workspace = true, features = ["static-verifier"] }
22+
openvm-native-recursion = { workspace = true }
2323
openvm-sdk = { workspace = true }
2424
openvm-stark-sdk.workspace = true
2525
openvm-stark-backend.workspace = true
@@ -39,5 +39,16 @@ toml = { workspace = true }
3939
bitcode.workspace = true
4040

4141
[features]
42-
default = []
42+
default = ["parallel", "jemalloc", "evm-verify", "bench-metrics"]
43+
evm-prove = ["openvm-sdk/evm-prove"]
44+
evm-verify = ["evm-prove", "openvm-sdk/evm-verify"]
4345
bench-metrics = ["openvm-sdk/bench-metrics"]
46+
# for guest profiling:
47+
profiling = ["openvm-sdk/profiling"]
48+
# performance features:
49+
# (rayon is always imported because of halo2, so "parallel" feature is redundant)
50+
parallel = ["openvm-sdk/parallel"]
51+
mimalloc = ["openvm-sdk/mimalloc"]
52+
jemalloc = ["openvm-sdk/jemalloc"]
53+
jemalloc-prof = ["openvm-sdk/jemalloc-prof"]
54+
nightly-features = ["openvm-sdk/nightly-features"]

crates/cli/src/bin/cargo-openvm.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
use cargo_openvm::{
2-
commands::{BuildCmd, EvmProvingSetupCmd, KeygenCmd, ProveCmd, RunCmd, VerifyCmd},
3-
OPENVM_VERSION_MESSAGE,
4-
};
1+
use cargo_openvm::{commands::*, OPENVM_VERSION_MESSAGE};
52
use clap::{Parser, Subcommand};
63
use eyre::Result;
74
use openvm_stark_sdk::config::setup_tracing_with_log_level;
@@ -27,6 +24,7 @@ pub enum VmCliCommands {
2724
Keygen(KeygenCmd),
2825
Prove(ProveCmd),
2926
Run(RunCmd),
27+
#[cfg(feature = "evm-verify")]
3028
Setup(EvmProvingSetupCmd),
3129
Verify(VerifyCmd),
3230
}
@@ -41,6 +39,7 @@ async fn main() -> Result<()> {
4139
VmCliCommands::Run(cmd) => cmd.run(),
4240
VmCliCommands::Keygen(cmd) => cmd.run(),
4341
VmCliCommands::Prove(cmd) => cmd.run(),
42+
#[cfg(feature = "evm-verify")]
4443
VmCliCommands::Setup(cmd) => cmd.run().await,
4544
VmCliCommands::Verify(cmd) => cmd.run(),
4645
}

crates/cli/src/commands/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ pub use prove::*;
1010
mod run;
1111
pub use run::*;
1212

13+
#[cfg(feature = "evm-verify")]
1314
mod setup;
15+
#[cfg(feature = "evm-verify")]
1416
pub use setup::*;
1517

1618
mod verify;

crates/cli/src/commands/prove.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,21 @@ use std::{path::PathBuf, sync::Arc};
22

33
use clap::Parser;
44
use eyre::Result;
5-
use openvm_native_recursion::halo2::utils::CacheHalo2ParamsReader;
65
use openvm_sdk::{
76
commit::AppExecutionCommit,
8-
config::{AggregationTreeConfig, SdkVmConfig},
9-
fs::{
10-
read_agg_pk_from_file, read_app_pk_from_file, read_exe_from_file, write_app_proof_to_file,
11-
write_evm_proof_to_file,
12-
},
7+
config::SdkVmConfig,
8+
fs::{read_app_pk_from_file, read_exe_from_file, write_app_proof_to_file},
139
keygen::AppProvingKey,
1410
NonRootCommittedExe, Sdk, StdIn,
1511
};
12+
#[cfg(feature = "evm-prove")]
13+
use openvm_sdk::{
14+
config::AggregationTreeConfig,
15+
fs::{read_agg_pk_from_file, write_evm_proof_to_file},
16+
};
1617

1718
use crate::{
18-
default::{
19-
DEFAULT_AGG_PK_PATH, DEFAULT_APP_EXE_PATH, DEFAULT_APP_PK_PATH, DEFAULT_APP_PROOF_PATH,
20-
DEFAULT_EVM_PROOF_PATH, DEFAULT_PARAMS_DIR,
21-
},
19+
default::*,
2220
input::{read_to_stdin, Input},
2321
};
2422

@@ -44,6 +42,7 @@ enum ProveSubCommand {
4442
#[arg(long, action, help = "Path to output proof", default_value = DEFAULT_APP_PROOF_PATH)]
4543
output: PathBuf,
4644
},
45+
#[cfg(feature = "evm-prove")]
4746
Evm {
4847
#[arg(long, action, help = "Path to app proving key", default_value = DEFAULT_APP_PK_PATH)]
4948
app_pk: PathBuf,
@@ -64,7 +63,7 @@ enum ProveSubCommand {
6463

6564
impl ProveCmd {
6665
pub fn run(&self) -> Result<()> {
67-
let mut sdk = Sdk::new();
66+
let sdk = Sdk::new();
6867
match &self.command {
6968
ProveSubCommand::App {
7069
app_pk,
@@ -77,13 +76,17 @@ impl ProveCmd {
7776
let app_proof = sdk.generate_app_proof(app_pk, committed_exe, input)?;
7877
write_app_proof_to_file(app_proof, output)?;
7978
}
79+
#[cfg(feature = "evm-prove")]
8080
ProveSubCommand::Evm {
8181
app_pk,
8282
exe,
8383
input,
8484
output,
8585
agg_tree_config,
8686
} => {
87+
use openvm_native_recursion::halo2::utils::CacheHalo2ParamsReader;
88+
89+
let mut sdk = sdk;
8790
sdk.set_agg_tree_config(*agg_tree_config);
8891
let params_reader = CacheHalo2ParamsReader::new(DEFAULT_PARAMS_DIR);
8992
let (app_pk, committed_exe, input) =

crates/cli/src/commands/verify.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,11 @@ use std::path::PathBuf;
33
use clap::Parser;
44
use eyre::Result;
55
use openvm_sdk::{
6-
fs::{
7-
read_app_proof_from_file, read_app_vk_from_file, read_evm_halo2_verifier_from_folder,
8-
read_evm_proof_from_file,
9-
},
6+
fs::{read_app_proof_from_file, read_app_vk_from_file},
107
Sdk,
118
};
129

13-
use crate::default::{
14-
DEFAULT_APP_PROOF_PATH, DEFAULT_APP_VK_PATH, DEFAULT_EVM_HALO2_VERIFIER_PATH,
15-
DEFAULT_EVM_PROOF_PATH,
16-
};
10+
use crate::default::*;
1711

1812
#[derive(Parser)]
1913
#[command(name = "verify", about = "Verify a proof")]
@@ -31,6 +25,7 @@ enum VerifySubCommand {
3125
#[arg(long, action, help = "Path to app proof", default_value = DEFAULT_APP_PROOF_PATH)]
3226
proof: PathBuf,
3327
},
28+
#[cfg(feature = "evm-verify")]
3429
Evm {
3530
#[arg(long, action, help = "Path to EVM proof", default_value = DEFAULT_EVM_PROOF_PATH)]
3631
proof: PathBuf,
@@ -46,7 +41,12 @@ impl VerifyCmd {
4641
let app_proof = read_app_proof_from_file(proof)?;
4742
sdk.verify_app_proof(&app_vk, &app_proof)?;
4843
}
44+
#[cfg(feature = "evm-verify")]
4945
VerifySubCommand::Evm { proof } => {
46+
use openvm_sdk::fs::{
47+
read_evm_halo2_verifier_from_folder, read_evm_proof_from_file,
48+
};
49+
5050
let evm_verifier = read_evm_halo2_verifier_from_folder(DEFAULT_EVM_HALO2_VERIFIER_PATH).map_err(|e| {
5151
eyre::eyre!("Failed to read EVM verifier: {}\nPlease run 'cargo openvm evm-proving-setup' first", e)
5252
})?;

0 commit comments

Comments
 (0)