Skip to content

Commit

Permalink
Str-700: Preparation work for the prover CI performance metrics (#546)
Browse files Browse the repository at this point in the history
* Define basic ProofReport struct and implement stub report generation in adapters and test provers.

* Factor out bin/prover-client/zkvm/ into a separate crate under crates/zkvm.

* Update Cargo.locks for provers/

* Minor review fixes, primarily docstrings.

* Fix link after rebase.
  • Loading branch information
evgenyzdanovich authored Dec 20, 2024
1 parent 5a42f42 commit 5bc29bf
Show file tree
Hide file tree
Showing 39 changed files with 502 additions and 404 deletions.
30 changes: 25 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ members = [
"crates/proof-impl/evm-ee-stf",
"crates/proof-impl/l1-batch",
"crates/zkvm/zkvm",
"crates/zkvm/hosts",
"crates/reth/db",
"crates/reth/evm",
"crates/reth/exex",
Expand Down Expand Up @@ -116,6 +117,7 @@ strata-tasks = { path = "crates/tasks" }
strata-test-utils = { path = "crates/test-utils" }
strata-tx-parser = { path = "crates/tx-parser" }
strata-zkvm = { path = "crates/zkvm/zkvm" }
strata-zkvm-hosts = { path = "crates/zkvm/hosts" }

# IMPORTANT: ensure alloy-* and revm packages are of the same version as inside reth dependency
# reth dependencies:
Expand Down
6 changes: 1 addition & 5 deletions bin/prover-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,13 @@ strata-common.workspace = true
strata-db.workspace = true
strata-native-zkvm-adapter.workspace = true
strata-primitives.workspace = true
strata-proofimpl-btc-blockspace.workspace = true
strata-proofimpl-checkpoint.workspace = true
strata-proofimpl-cl-agg.workspace = true
strata-proofimpl-cl-stf.workspace = true
strata-proofimpl-evm-ee-stf.workspace = true
strata-proofimpl-l1-batch.workspace = true
strata-prover-client-rpc-api.workspace = true
strata-rocksdb.workspace = true
strata-rpc-types.workspace = true
strata-state.workspace = true
strata-zkvm.workspace = true
strata-zkvm-hosts = { workspace = true, features = ["sp1"] }

alloy-rpc-types.workspace = true
anyhow.workspace = true
Expand Down
1 change: 0 additions & 1 deletion bin/prover-client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ mod prover;
mod proving_ops;
mod rpc_server;
mod task;
mod zkvm;

#[tokio::main]
async fn main() {
Expand Down
2 changes: 1 addition & 1 deletion bin/prover-client/src/primitives/prover_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use bitcoin::Block;
use serde::{Deserialize, Serialize};
use strata_primitives::params::RollupParams;
use strata_zkvm::AggregationInput;
use strata_zkvm_hosts::ProofVm;

use super::vms::ProofVm;
use crate::proving_ops::{
checkpoint_ops::CheckpointInput, cl_ops::CLProverInput, l1_batch_ops::L1BatchInput,
l2_batch_ops::L2BatchInput,
Expand Down
17 changes: 3 additions & 14 deletions bin/prover-client/src/primitives/vms.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
use std::{collections::HashMap, hash::Hash};
use std::collections::HashMap;

use strata_sp1_adapter::SP1Host;

use crate::zkvm;

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum ProofVm {
BtcProving,
ELProving,
CLProving,
CLAggregation,
L1Batch,
Checkpoint,
}
use strata_zkvm_hosts::{get_sp1_host, ProofVm};

pub struct ZkVMManager {
vms: HashMap<ProofVm, &'static SP1Host>,
Expand All @@ -28,7 +17,7 @@ impl ZkVMManager {
pub fn add_vm(&mut self, proof_vm: ProofVm) {
// The `Vm` is expected to live for the lifetime of the ProverManager, ensuring the same
// instance is reused to prove the same guest program
let vm = zkvm::get_host(proof_vm);
let vm = get_sp1_host(proof_vm);
self.vms.insert(proof_vm, vm);
}

Expand Down
3 changes: 2 additions & 1 deletion bin/prover-client/src/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use strata_proofimpl_evm_ee_stf::EvmBlockStfInput;
use strata_rocksdb::{prover::db::ProofDb, DbOpsConfig};
use strata_state::l1::L1BlockId;
use strata_zkvm::{ProofReceipt, ProofType, ZkVmHost, ZkVmInputBuilder};
use strata_zkvm_hosts::ProofVm;
use tracing::{error, info};
use uuid::Uuid;

Expand All @@ -18,7 +19,7 @@ use crate::{
primitives::{
prover_input::{ProofWithVkey, ZkVmInput},
tasks_scheduler::{ProofProcessingStatus, ProofSubmissionStatus, WitnessSubmissionStatus},
vms::{ProofVm, ZkVMManager},
vms::ZkVMManager,
},
proving_ops::btc_ops::get_pm_rollup_params,
};
Expand Down
8 changes: 0 additions & 8 deletions bin/prover-client/src/zkvm/mod.rs

This file was deleted.

59 changes: 0 additions & 59 deletions bin/prover-client/src/zkvm/native.rs

This file was deleted.

11 changes: 10 additions & 1 deletion crates/zkvm/adapters/native/src/host.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use std::{fmt, sync::Arc};

use strata_zkvm::{
Proof, ProofReceipt, ProofType, PublicValues, VerificationKey, ZkVmError, ZkVmHost, ZkVmResult,
Proof, ProofReceipt, ProofReport, ProofType, PublicValues, VerificationKey, ZkVmError,
ZkVmHost, ZkVmResult,
};

use crate::{env::NativeMachine, input::NativeMachineInputBuilder, proof::NativeProofReceipt};
Expand Down Expand Up @@ -44,6 +45,14 @@ impl ZkVmHost for NativeHost {
fn verify_inner(&self, _proof: &NativeProofReceipt) -> ZkVmResult<()> {
Ok(())
}

fn perf_report<'a>(
&self,
_input: NativeMachine,
_proof_type: ProofType,
) -> ZkVmResult<ProofReport> {
Ok(ProofReport { cycles: 0 })
}
}

impl fmt::Display for NativeHost {
Expand Down
11 changes: 10 additions & 1 deletion crates/zkvm/adapters/risc0/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use hex::encode;
use risc0_zkvm::{compute_image_id, default_prover, sha::Digest, Journal, ProverOpts};
use serde::{de::DeserializeOwned, Serialize};
use strata_zkvm::{
ProofType, PublicValues, VerificationKey, ZkVmError, ZkVmHost, ZkVmInputBuilder, ZkVmResult,
ProofReport, ProofType, PublicValues, VerificationKey, ZkVmError, ZkVmHost, ZkVmInputBuilder,
ZkVmResult,
};

use crate::{input::Risc0ProofInputBuilder, proof::Risc0ProofReceipt};
Expand Down Expand Up @@ -80,6 +81,14 @@ impl ZkVmHost for Risc0Host {
.map_err(|e| ZkVmError::ProofVerificationError(e.to_string()))?;
Ok(())
}

fn perf_report<'a>(
&self,
_input: <Self::Input<'a> as ZkVmInputBuilder<'a>>::Input,
_proof_type: ProofType,
) -> ZkVmResult<ProofReport> {
Ok(ProofReport { cycles: 0 })
}
}

impl fmt::Display for Risc0Host {
Expand Down
11 changes: 10 additions & 1 deletion crates/zkvm/adapters/sp1/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use std::fmt;
use serde::{de::DeserializeOwned, Serialize};
use sp1_sdk::{HashableKey, ProverClient, SP1ProvingKey, SP1VerifyingKey};
use strata_zkvm::{
ProofType, PublicValues, VerificationKey, ZkVmError, ZkVmHost, ZkVmInputBuilder, ZkVmResult,
ProofReport, ProofType, PublicValues, VerificationKey, ZkVmError, ZkVmHost, ZkVmInputBuilder,
ZkVmResult,
};

use crate::{input::SP1ProofInputBuilder, proof::SP1ProofReceipt};
Expand Down Expand Up @@ -101,6 +102,14 @@ impl ZkVmHost for SP1Host {

Ok(())
}

fn perf_report<'a>(
&self,
_input: <Self::Input<'a> as ZkVmInputBuilder<'a>>::Input,
_proof_type: ProofType,
) -> ZkVmResult<ProofReport> {
Ok(ProofReport { cycles: 0 })
}
}

impl fmt::Display for SP1Host {
Expand Down
35 changes: 35 additions & 0 deletions crates/zkvm/hosts/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[package]
edition = "2021"
name = "strata-zkvm-hosts"
version = "0.1.0"

[dependencies]
# sp1
strata-sp1-adapter = { workspace = true, optional = true }
strata-sp1-guest-builder = { path = "../../../provers/sp1", optional = true }

# risc0
strata-risc0-adapter = { workspace = true, optional = true }
strata-risc0-guest-builder = { path = "../../../provers/risc0", optional = true }

strata-primitives.workspace = true

# TODO: make it optional, via the native feature.
strata-native-zkvm-adapter.workspace = true
strata-proofimpl-btc-blockspace.workspace = true
strata-proofimpl-checkpoint.workspace = true
strata-proofimpl-cl-agg.workspace = true
strata-proofimpl-cl-stf.workspace = true
strata-proofimpl-evm-ee-stf.workspace = true
strata-proofimpl-l1-batch.workspace = true

bincode.workspace = true
borsh.workspace = true
cfg-if = "1.0.0"
serde.workspace = true
thiserror.workspace = true

[features]
native = []
risc0 = ["strata-risc0-adapter/prover", "strata-risc0-guest-builder/prover"]
sp1 = ["strata-sp1-adapter/prover", "strata-sp1-guest-builder/prover"]
39 changes: 39 additions & 0 deletions crates/zkvm/hosts/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// TODO figure out the cfg-if.

#[cfg(feature = "native")]
pub mod native;
#[cfg(feature = "native")]
use strata_native_zkvm_adapter::NativeHost;
#[cfg(feature = "native")]
pub fn get_native_host(vm: ProofVm) -> &'static NativeHost {
native::get_host(vm)
}

#[cfg(feature = "risc0")]
pub mod risc0;
#[cfg(feature = "risc0")]
use strata_risc0_adapter::Risc0Host;
#[cfg(feature = "risc0")]
pub fn get_risc0_host(vm: ProofVm) -> &'static Risc0Host {
risc0::get_host(vm)
}

#[cfg(feature = "sp1")]
pub mod sp1;
#[cfg(feature = "sp1")]
use strata_sp1_adapter::SP1Host;
#[cfg(feature = "sp1")]
pub fn get_sp1_host(vm: ProofVm) -> &'static SP1Host {
sp1::get_host(vm)
}

/// An identifier of different prover types.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum ProofVm {
BtcProving,
ELProving,
CLProving,
CLAggregation,
L1Batch,
Checkpoint,
}
Loading

0 comments on commit 5bc29bf

Please sign in to comment.