Skip to content

Commit 1c4a696

Browse files
feat: Add feature gating for halo2 imports in SDK and CLI crates (#1731)
## Feature Gating for Halo2 Imports - INT-4112 This PR implements feature gating for all halo2 imports in the openvm-sdk and openvm-cli crates, making EVM proving/verification capabilities optional. This allows users who only need STARK functionality to compile without pulling in halo2 dependencies, improving compile times and reducing binary size. ### Changes Made #### SDK Dependencies (crates/sdk/Cargo.toml) - Made `snark-verifier` and `snark-verifier-sdk` optional dependencies - Removed forced `static-verifier` feature from `openvm-native-recursion` - Updated `evm-prove` feature definition to properly include halo2 dependencies: - `openvm-native-recursion/evm-prove` - `openvm-native-recursion/static-verifier` - `dep:snark-verifier` - `dep:snark-verifier-sdk` #### Feature Gating in SDK Source Files - **lib.rs**: Added `#[cfg(any(feature = "evm-prove", feature = "evm-verify"))]` to `agg_keygen` function - **keygen/mod.rs**: Feature-gated `Halo2ProvingKey` struct and related imports, added conditional compilation to `AggProvingKey.halo2_pk` field - **keygen/static_verifier.rs**: Feature-gated entire module with halo2-related functionality - **types.rs**: Added feature gates to all EVM-related types (`EvmHalo2Verifier`, `EvmProof`, etc.) - **fs.rs**: Feature-gated halo2 file I/O functions and imports #### CLI Updates (crates/cli/Cargo.toml) - Removed `evm-verify` from default features - Default features now: `["parallel", "jemalloc", "bench-metrics"]` #### CLI Source Updates (crates/cli/src/util.rs) - Feature-gated `read_agg_halo2_pk_from_file` import - Feature-gated `read_default_agg_pk()` function ### Verification All compilation scenarios have been tested and pass successfully: **SDK Crate:** - ✅ `cargo check --no-default-features` (STARK-only compilation) - ✅ `cargo check --features evm-prove` (EVM proving enabled) - ✅ `cargo check --features evm-verify` (EVM verification enabled) **CLI Crate:** - ✅ `cargo check --no-default-features` (STARK-only compilation) - ✅ `cargo check --features evm-verify` (EVM verification enabled) ### Impact - **STARK-only users**: Can now compile without halo2 dependencies, resulting in faster compile times and smaller binaries - **EVM users**: No breaking changes - existing functionality remains available when EVM features are enabled - **Backward compatibility**: Maintained through proper feature flag design ### Link to Devin run https://app.devin.ai/sessions/8bb6a0cf896e4b98972d872fffcb68bd **Requested by:** Jonathan Wang --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Jonathan Wang <[email protected]> Co-authored-by: Jonathan Wang <[email protected]>
1 parent a4fef23 commit 1c4a696

File tree

15 files changed

+166
-102
lines changed

15 files changed

+166
-102
lines changed

.github/workflows/benchmarks.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ jobs:
8282
else
8383
RUN_E2E=${{ github.event.inputs.run-benchmark-e2e || 'false' }}
8484
fi
85+
if [[ "$RUN_E2E" == "true" ]]; then
86+
FEATURE_FLAGS="evm,${FEATURE_FLAGS}"
87+
fi
8588
if [[ "${{ github.event.inputs.aggregation }}" == "true" ]]; then
8689
FEATURE_FLAGS="aggregation,${FEATURE_FLAGS}"
8790
fi

.github/workflows/sdk.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,5 +96,4 @@ jobs:
9696
working-directory: crates/sdk
9797
run: |
9898
export RUST_BACKTRACE=1
99-
cargo nextest run --cargo-profile=fast --test-threads=2 --features parallel
100-
99+
cargo nextest run --cargo-profile=fast --test-threads=2 --features parallel,evm-verify

benchmarks/guest/kitchen-sink/Cargo.toml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,16 @@ openvm = { path = "../../../crates/toolchain/openvm", default-features = false,
99
"std",
1010
] }
1111
openvm-algebra-guest = { path = "../../../extensions/algebra/guest", default-features = false }
12-
openvm-ecc-guest = { path = "../../../extensions/ecc/guest", default-features = false, features = [
13-
"k256",
14-
"p256",
15-
] }
16-
openvm-pairing-guest = { path = "../../../extensions/pairing/guest", default-features = false, features = [
12+
openvm-ecc-guest = { path = "../../../extensions/ecc/guest", default-features = false }
13+
openvm-pairing = { path = "../../../guest-libs/pairing/", features = [
1714
"bn254",
1815
"bls12_381",
1916
] }
20-
openvm-pairing = { path = "../../../guest-libs/pairing/", features = ["bn254", "bls12_381"] }
2117
openvm-keccak256 = { path = "../../../guest-libs/keccak256/", default-features = false }
2218
openvm-sha2 = { path = "../../../guest-libs/sha2/", default-features = false }
23-
openvm-ruint = { path = "../../../guest-libs/ruint/", default-features = false }
19+
openvm-k256 = { path = "../../../guest-libs/k256/", package = "k256" }
20+
openvm-p256 = { path = "../../../guest-libs/p256/", package = "p256" }
21+
openvm-ruint = { path = "../../../guest-libs/ruint/", package = "ruint", default-features = false }
2422
hex = { version = "0.4.3", default-features = false, features = ["alloc"] }
2523
serde = "1.0"
2624

benchmarks/guest/kitchen-sink/src/main.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
extern crate alloc;
2+
13
use std::hint::black_box;
24

35
use openvm_algebra_guest::IntMod;
@@ -6,20 +8,17 @@ use openvm_ruint::aliases::U256;
68
use openvm_sha2::sha256;
79
#[allow(unused_imports)]
810
use {
9-
openvm_ecc_guest::{
10-
k256::{Secp256k1Coord, Secp256k1Point, Secp256k1Scalar},
11-
p256::{P256Coord, P256Point, P256Scalar},
12-
weierstrass::WeierstrassPoint,
13-
CyclicGroup,
14-
},
11+
openvm_ecc_guest::{weierstrass::WeierstrassPoint, CyclicGroup},
12+
openvm_k256::{Secp256k1Coord, Secp256k1Point, Secp256k1Scalar},
13+
openvm_p256::{P256Coord, P256Point, P256Scalar},
1514
openvm_pairing::{
1615
bls12_381::{
1716
Bls12_381Fp, Bls12_381Fp2, Bls12_381G1Affine, Bls12_381Scalar,
1817
G2Affine as Bls12_381G2Affine,
1918
},
2019
bn254::{Bn254, Bn254Fp, Bn254Fp2, Bn254G1Affine, Bn254Scalar, G2Affine as Bn254G2Affine},
20+
PairingCheck,
2121
},
22-
openvm_pairing_guest::pairing::PairingCheck,
2322
};
2423

2524
// Note: these will all currently be represented as bytes32 even though they could be smaller

benchmarks/prove/Cargo.toml

Lines changed: 21 additions & 8 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, features = ["evm-verify"] }
13+
openvm-sdk.workspace = true
1414
openvm-stark-backend.workspace = true
1515
openvm-stark-sdk.workspace = true
1616
openvm-transpiler.workspace = true
@@ -44,14 +44,27 @@ tracing.workspace = true
4444

4545
[features]
4646
default = ["parallel", "jemalloc", "bench-metrics"]
47-
bench-metrics = ["openvm-native-recursion/bench-metrics"]
47+
bench-metrics = ["openvm-sdk/bench-metrics"]
4848
profiling = ["openvm-sdk/profiling"]
49-
aggregation = []
50-
parallel = ["openvm-native-recursion/parallel"]
51-
mimalloc = ["openvm-circuit/mimalloc"]
52-
jemalloc = ["openvm-circuit/jemalloc"]
53-
jemalloc-prof = ["openvm-circuit/jemalloc-prof"]
54-
nightly-features = ["openvm-circuit/nightly-features"]
49+
aggregation = [] # runs leaf aggregation benchmarks
50+
evm = ["openvm-sdk/evm-verify"]
51+
parallel = ["openvm-sdk/parallel"]
52+
mimalloc = ["openvm-sdk/mimalloc"]
53+
jemalloc = ["openvm-sdk/jemalloc"]
54+
jemalloc-prof = ["openvm-sdk/jemalloc-prof"]
55+
nightly-features = ["openvm-sdk/nightly-features"]
5556

5657
[package.metadata.cargo-shear]
5758
ignored = ["derive_more"]
59+
60+
[[bin]]
61+
name = "fib_e2e"
62+
path = "src/bin/fib_e2e.rs"
63+
# TODO: cfg run benchmark with prove stark if no evm feature
64+
required-features = ["evm"]
65+
66+
[[bin]]
67+
name = "kitchen_sink"
68+
path = "src/bin/kitchen_sink.rs"
69+
# TODO: cfg run benchmark with prove stark if no evm feature
70+
required-features = ["evm"]

ci/scripts/bench.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def run_cargo_command(
1717
):
1818
# Command to run (for best performance but slower builds, use --profile maxperf)
1919
command = [
20-
"cargo", "run", "--no-default-features", "--bin", bin_name, "--profile", profile, "--features", ",".join(feature_flags), "--"
20+
"cargo", "run", "--no-default-features", "-p", "openvm-benchmarks-prove", "--bin", bin_name, "--profile", profile, "--features", ",".join(feature_flags), "--"
2121
]
2222

2323
if app_log_blowup is not None:

crates/cli/src/util.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,14 @@ use std::{
55

66
use eyre::Result;
77
use openvm_build::{get_in_scope_packages, get_workspace_packages};
8-
use openvm_sdk::{
9-
config::{AppConfig, SdkVmConfig},
10-
fs::{read_agg_halo2_pk_from_file, read_agg_stark_pk_from_file},
11-
keygen::AggProvingKey,
12-
};
8+
use openvm_sdk::config::{AppConfig, SdkVmConfig};
9+
#[cfg(feature = "evm-prove")]
10+
use openvm_sdk::{fs::read_agg_stark_pk_from_file, keygen::AggProvingKey};
1311
use serde::de::DeserializeOwned;
1412

1513
use crate::{
1614
commands::RunCargoArgs,
17-
default::{
18-
default_agg_halo2_pk_path, default_agg_stark_pk_path, default_app_config,
19-
DEFAULT_APP_PK_NAME, DEFAULT_APP_VK_NAME,
20-
},
15+
default::{default_app_config, DEFAULT_APP_PK_NAME, DEFAULT_APP_VK_NAME},
2116
};
2217

2318
pub(crate) fn read_to_struct_toml<T: DeserializeOwned>(path: impl AsRef<Path>) -> Result<T> {
@@ -38,9 +33,11 @@ pub fn read_config_toml_or_default(config: impl AsRef<Path>) -> Result<AppConfig
3833
}
3934
}
4035

36+
#[cfg(feature = "evm-prove")]
4137
pub fn read_default_agg_pk() -> Result<AggProvingKey> {
42-
let agg_stark_pk = read_agg_stark_pk_from_file(default_agg_stark_pk_path())?;
43-
let halo2_pk = read_agg_halo2_pk_from_file(default_agg_halo2_pk_path())?;
38+
let agg_stark_pk = read_agg_stark_pk_from_file(crate::default::default_agg_stark_pk_path())?;
39+
let halo2_pk =
40+
openvm_sdk::fs::read_agg_halo2_pk_from_file(crate::default::default_agg_halo2_pk_path())?;
4441
Ok(AggProvingKey {
4542
agg_stark_pk,
4643
halo2_pk,

crates/continuations/Cargo.toml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,18 @@ repository.workspace = true
88
license.workspace = true
99

1010
[dependencies]
11-
openvm-native-compiler = { workspace = true }
12-
openvm-native-recursion = { workspace = true, features = ["static-verifier"] }
13-
openvm-stark-backend = { workspace = true }
14-
openvm-stark-sdk = { workspace = true }
15-
openvm-circuit = { workspace = true }
11+
openvm-native-compiler.workspace = true
12+
openvm-native-recursion.workspace = true
13+
openvm-stark-backend.workspace = true
14+
openvm-stark-sdk.workspace = true
15+
openvm-circuit.workspace = true
1616

17-
derivative = { workspace = true }
18-
serde = { workspace = true }
17+
derivative.workspace = true
18+
serde.workspace = true
1919
static_assertions.workspace = true
2020

2121
[features]
2222
default = ["parallel"]
2323
parallel = ["openvm-circuit/parallel"]
24+
static-verifier = ["openvm-native-recursion/static-verifier"]
2425
test-utils = ["openvm-circuit/test-utils"]

crates/continuations/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use openvm_stark_sdk::{
77
p3_baby_bear::BabyBear,
88
};
99

10+
#[cfg(feature = "static-verifier")]
1011
pub mod static_verifier;
1112
pub mod verifier;
1213

crates/sdk/Cargo.toml

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ openvm-pairing-circuit = { workspace = true }
2424
openvm-pairing-transpiler = { workspace = true }
2525
openvm-native-circuit = { workspace = true }
2626
openvm-native-compiler = { workspace = true }
27-
openvm-native-recursion = { workspace = true, features = ["static-verifier"] }
27+
openvm-native-recursion = { workspace = true }
2828
openvm-native-transpiler = { workspace = true }
2929
openvm-rv32im-circuit = { workspace = true }
3030
openvm-rv32im-transpiler = { workspace = true }
@@ -51,17 +51,22 @@ clap = { workspace = true, features = ["derive"] }
5151
serde_with = { workspace = true, features = ["hex"] }
5252
serde_json.workspace = true
5353
thiserror.workspace = true
54-
snark-verifier = { workspace = true }
55-
snark-verifier-sdk.workspace = true
54+
snark-verifier = { workspace = true, optional = true }
55+
snark-verifier-sdk = { workspace = true, optional = true }
5656
tempfile.workspace = true
5757
hex.workspace = true
5858
forge-fmt = { workspace = true, optional = true }
5959
rrs-lib = { workspace = true }
6060
num-bigint = { workspace = true }
6161

6262
[features]
63-
default = ["parallel", "jemalloc", "evm-verify"]
64-
evm-prove = ["openvm-native-recursion/evm-prove"]
63+
default = ["parallel", "jemalloc"]
64+
evm-prove = [
65+
"openvm-continuations/static-verifier",
66+
"openvm-native-recursion/evm-prove",
67+
"dep:snark-verifier",
68+
"dep:snark-verifier-sdk",
69+
]
6570
evm-verify = [
6671
"evm-prove",
6772
"openvm-native-recursion/evm-verify",
@@ -83,3 +88,8 @@ mimalloc = ["openvm-circuit/mimalloc"]
8388
jemalloc = ["openvm-circuit/jemalloc"]
8489
jemalloc-prof = ["openvm-circuit/jemalloc-prof"]
8590
nightly-features = ["openvm-circuit/nightly-features"]
91+
92+
[[example]]
93+
name = "sdk_evm"
94+
path = "examples/sdk_evm.rs"
95+
required-features = ["evm-verify"]

0 commit comments

Comments
 (0)