Skip to content

Commit 08251d1

Browse files
committed
feat: add cli commands
1 parent 1f0e534 commit 08251d1

File tree

9 files changed

+2569
-299
lines changed

9 files changed

+2569
-299
lines changed

Cargo.lock

Lines changed: 2454 additions & 285 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ edition = "2024"
66
[dependencies]
77

88
# openvm
9-
openvm-native-recursion = { git = "https://github.com/openvm-org/openvm.git", rev = "7f87e1d", default-features = false }
10-
openvm-sdk = { git = "https://github.com/openvm-org/openvm.git", rev = "7f87e1d", default-features = false, features = [
9+
openvm-native-recursion = { git = "https://github.com/openvm-org/openvm.git", rev = "2bdf9ed", default-features = false }
10+
openvm-sdk = { git = "https://github.com/openvm-org/openvm.git", rev = "2bdf9ed", default-features = false, features = [
1111
"parallel",
1212
"bench-metrics",
1313
] }
14+
openvm-stark-sdk = { git = "https://github.com/openvm-org/stark-backend.git", rev = "46f581f" }
1415

1516
# revm
1617
revm = "19.0"
@@ -22,7 +23,16 @@ snark-verifier-sdk = { git = "https://github.com/axiom-crypto/snark-verifier", b
2223
"display",
2324
] }
2425

26+
# scroll-tech/zkvm-prover
27+
scroll-zkvm-verifier = { git = "https://github.com/scroll-tech/zkvm-prover", branch = "feat/phase1-stable" }
28+
2529
# miscellaneous
30+
clap = "4"
2631
eyre = "0.6"
2732
tracing = "0.1"
2833
tracing-subscriber = "0.3"
34+
35+
[patch.crates-io]
36+
alloy-primitives = { git = "https://github.com/scroll-tech/alloy-core", branch = "v0.8.18-euclid-upgrade" }
37+
ruint = { git = "https://github.com/scroll-tech/uint.git", branch = "v1.12.3" }
38+
tiny-keccak = { git = "https://github.com/scroll-tech/tiny-keccak", branch = "scroll-patch-v2.0.2-euclid-upgrade" }

src/commands.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
use clap::Subcommand;
2+
3+
#[derive(Debug, Subcommand)]
4+
pub enum Commands {
5+
#[command(about = "")]
6+
GenerateVerifier(crate::verifier::GenerateCommand),
7+
#[command(about = "")]
8+
ComputeDigest(crate::digest::ComputeCommand),
9+
}
10+
11+
impl Commands {
12+
pub fn run(self) -> eyre::Result<()> {
13+
match self {
14+
Commands::GenerateVerifier(cmd) => cmd.run(),
15+
Commands::ComputeDigest(cmd) => cmd.run(),
16+
}
17+
}
18+
}

src/digest/compute.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
use openvm_stark_sdk::{openvm_stark_backend::p3_field::PrimeField32, p3_baby_bear::BabyBear};
2+
use snark_verifier_sdk::snark_verifier::halo2_base::halo2_proofs::halo2curves::bn256::Fr;
3+
4+
/// OpenVM's EXE and LEAF commitments are essentially 8 * Babybears each. During the generation of a
5+
/// SNARK from the OpenVM RootProof, these commitments are compressed into a BN254 scalar.
6+
pub fn compress_commitment(commitment: &[u32; 8]) -> Fr {
7+
let order = Fr::from(BabyBear::ORDER_U32 as u64);
8+
let mut base = Fr::one();
9+
let mut ret = Fr::zero();
10+
11+
for v in commitment {
12+
ret += Fr::from(*v as u64) * base;
13+
base *= order;
14+
}
15+
16+
ret
17+
}

src/digest/mod.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
use clap::Args;
2+
3+
mod compute;
4+
5+
#[derive(Debug, Args)]
6+
pub struct ComputeCommand {
7+
#[arg(long = "phase-1", help = "Compute digests for Euclid phase-1")]
8+
pub phase_1: bool,
9+
#[arg(long = "phase-2", help = "Compute digests for Euclid phase-2")]
10+
pub phase_2: bool,
11+
}
12+
13+
impl ComputeCommand {
14+
pub fn run(self) -> eyre::Result<()> {
15+
if !(self.phase_1 ^ self.phase_2) {
16+
eyre::bail!("Please pass a single flag (--phase-1 or --phase-2)")
17+
}
18+
19+
let (exe, leaf) = if self.phase_1 {
20+
(
21+
scroll_zkvm_verifier::commitments::bundle_legacy::EXE_COMMIT,
22+
scroll_zkvm_verifier::commitments::bundle_legacy::LEAF_COMMIT,
23+
)
24+
} else {
25+
(
26+
scroll_zkvm_verifier::commitments::bundle::EXE_COMMIT,
27+
scroll_zkvm_verifier::commitments::bundle::LEAF_COMMIT,
28+
)
29+
};
30+
31+
let _digest_1 = compute::compress_commitment(&exe);
32+
let _digest_2 = compute::compress_commitment(&leaf);
33+
34+
Ok(())
35+
}
36+
}

src/main.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
1-
mod generate;
1+
use clap::Parser;
22

3-
mod utils;
3+
mod commands;
44

5-
fn main() -> eyre::Result<()> {
6-
// Generate the initialisation code for the EVM PLONK verifier.
7-
let init_code = generate::generate()?;
5+
mod digest;
6+
7+
mod verifier;
88

9-
// Get the deployed code and codehash of the EVM PLONK verifier contract.
10-
let (deployed_code, codehash) = utils::deploy(&init_code)?;
9+
#[derive(Parser)]
10+
struct Cli {
11+
#[command(subcommand)]
12+
commands: commands::Commands,
13+
}
14+
15+
fn main() -> eyre::Result<()> {
16+
let cmd = Cli::parse();
1117

12-
println!(
13-
"verifier contract bytecode size = {:?}",
14-
deployed_code.len()
15-
);
16-
println!("verifier contract codehash = {:?}", codehash);
18+
cmd.commands.run()?;
1719

1820
Ok(())
1921
}
File renamed without changes.
File renamed without changes.

src/verifier/mod.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
use clap::Args;
2+
3+
mod deploy;
4+
5+
mod generate;
6+
7+
#[derive(Debug, Args)]
8+
pub struct GenerateCommand;
9+
10+
impl GenerateCommand {
11+
pub fn run(self) -> eyre::Result<()> {
12+
let init_code = generate::generate()?;
13+
14+
let (_deployed_code, _codehash) = deploy::deploy(&init_code)?;
15+
16+
Ok(())
17+
}
18+
}

0 commit comments

Comments
 (0)