Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Str-796: ZkVMs prover performance metrics #555

Merged
merged 26 commits into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
5b3c14a
Introduce stub perf metrics for provers.
evgenyzdanovich Dec 17, 2024
4d74e8e
Abolish provers/tests/provers as this is the only module in this crate.
evgenyzdanovich Dec 20, 2024
22fa96d
Convenient re-exports for provers/tests
evgenyzdanovich Dec 20, 2024
9a248cf
Temporary disable risc0, requires installation of its toolchain.
evgenyzdanovich Dec 20, 2024
2d72c15
Minor fixes
evgenyzdanovich Dec 20, 2024
6fdeb14
Prettify cargo files, move code parts where they should belong.
evgenyzdanovich Dec 21, 2024
b679cf7
Install risc0 toolchain in the prover CI workflow.
evgenyzdanovich Dec 22, 2024
106909a
Enable risc0 compilation in perf.
evgenyzdanovich Dec 22, 2024
c697a43
Remove native host perf stats, add the rest of provers, prettify the …
evgenyzdanovich Dec 22, 2024
3a51a7f
disable risc0
evgenyzdanovich Dec 22, 2024
ecbc004
Minor cleanup in provers/tests
evgenyzdanovich Dec 23, 2024
b22f0a5
Remove unused provers/test-util
evgenyzdanovich Dec 23, 2024
4c4e984
re-enable half of provers.
evgenyzdanovich Dec 23, 2024
9315916
Extend gen_proof_report with program name.
evgenyzdanovich Dec 23, 2024
75614df
Allow provers/perf to be invoked locally.
evgenyzdanovich Dec 23, 2024
fb2b74c
Remove build step in the prover workflow because perf eval oncludes it.
evgenyzdanovich Dec 23, 2024
1a1512b
Add provers/perf as a separate binary under root Cargo.toml.
evgenyzdanovich Dec 23, 2024
dc34249
Minor cleanup of gitignore.
evgenyzdanovich Dec 23, 2024
c6e61f7
Small adjustments.
evgenyzdanovich Dec 23, 2024
2b68a85
Use mocked proofs in the perf.
evgenyzdanovich Dec 23, 2024
18ef0fa
Remove risc0 from perf for now.
evgenyzdanovich Dec 24, 2024
e0cfc16
Reformat tomls.
evgenyzdanovich Dec 24, 2024
a37b220
Fix zizmor for perf.
evgenyzdanovich Dec 24, 2024
a58c1a5
Bring back default native feature for prover tests.
evgenyzdanovich Dec 24, 2024
2108dc5
Include provers/perf into the workspace.
evgenyzdanovich Dec 24, 2024
eee2e9c
Disable executing some prover unit tests that were previously enabled…
evgenyzdanovich Dec 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions .github/workflows/prover.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ on:
branches: [main]

jobs:
build:
eval_perf:
permissions:
# Needed to install the toolchain.
contents: write
# Needed to post the performance report comments.
issues: write
runs-on: ubuntu-latest

steps:
Expand Down Expand Up @@ -44,8 +49,14 @@ jobs:
with:
persist-credentials: false

- name: Build prover guest code
run: cargo build --profile prover-ci -F "prover"
working-directory: provers/sp1
- name: Run performance evaluation
run: |
cargo run --profile prover-ci -- \
--post-to-gh \
--github-token "${{ secrets.GITHUB_TOKEN }}" \
--pr-number "${{ github.event.pull_request.number }}" \
--commit-hash "${{ github.sha }}" \
working-directory: provers/perf
env:
RUSTFLAGS: "-C link-arg=-fuse-ld=lld"
RUSTFLAGS: "-C target-cpu=native -C link-arg=-fuse-ld=lld"

2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,4 @@ provers/**/*.id
provers/**/*.proof

proving_keys/
provers/test-util/el/el_proofs/
provers/test-util/cl/cl_proofs/
provers/sp1/proofs/
50 changes: 36 additions & 14 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 @@ -56,6 +56,7 @@ members = [
"bin/strata-client",
"bin/strata-reth",
"bin/prover-client",
"provers/perf",

# integration tests
"tests",
Expand Down Expand Up @@ -189,6 +190,7 @@ bincode = "1.3"
bitcoin = { version = "=0.32.5", features = ["serde"] }
borsh = { version = "1.5.0", features = ["derive"] }
bytes = "1.6.0"
cfg-if = "1.0.0"
chrono = "0.4.38"
clap = "4"
digest = "0.10"
Expand Down
11 changes: 1 addition & 10 deletions crates/zkvm/adapters/native/src/host.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use std::{fmt, sync::Arc};

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

use crate::{env::NativeMachine, input::NativeMachineInputBuilder, proof::NativeProofReceipt};
Expand Down Expand Up @@ -45,14 +44,6 @@ 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
18 changes: 8 additions & 10 deletions crates/zkvm/adapters/risc0/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
use risc0_zkvm::{compute_image_id, default_prover, sha::Digest, Journal, ProverOpts};
use serde::{de::DeserializeOwned, Serialize};
use strata_zkvm::{
ProofReport, ProofType, PublicValues, VerificationKey, ZkVmError, ZkVmHost, ZkVmInputBuilder,
ZkVmResult,
ProofType, PublicValues, VerificationKey, ZkVmError, ZkVmHost, ZkVmInputBuilder, ZkVmResult,
};

use crate::{input::Risc0ProofInputBuilder, proof::Risc0ProofReceipt};
Expand All @@ -26,6 +25,11 @@
id,
}
}

// TODO: consider moving to ZkVkHost trait.
pub fn get_elf(&self) -> &[u8] {
&self.elf
}

Check warning on line 32 in crates/zkvm/adapters/risc0/src/host.rs

View check run for this annotation

Codecov / codecov/patch

crates/zkvm/adapters/risc0/src/host.rs#L30-L32

Added lines #L30 - L32 were not covered by tests
}

impl ZkVmHost for Risc0Host {
Expand Down Expand Up @@ -81,14 +85,6 @@
.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 All @@ -113,6 +109,7 @@
const TEST_ELF: &[u8] = include_bytes!("../tests/elf/risc0-zkvm-elf");

#[test]
#[ignore]
fn test_mock_prover() {
let input: u32 = 1;
let host = Risc0Host::init(TEST_ELF);
Expand All @@ -137,6 +134,7 @@
}

#[test]
#[ignore]
fn test_mock_prover_with_public_param() {
let input: u32 = 1;
let zkvm = Risc0Host::init(TEST_ELF);
Expand Down
16 changes: 6 additions & 10 deletions crates/zkvm/adapters/sp1/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
use serde::{de::DeserializeOwned, Serialize};
use sp1_sdk::{HashableKey, ProverClient, SP1ProvingKey, SP1VerifyingKey};
use strata_zkvm::{
ProofReport, ProofType, PublicValues, VerificationKey, ZkVmError, ZkVmHost, ZkVmInputBuilder,
ZkVmResult,
ProofType, PublicValues, VerificationKey, ZkVmError, ZkVmHost, ZkVmInputBuilder, ZkVmResult,
};

use crate::{input::SP1ProofInputBuilder, proof::SP1ProofReceipt};
Expand Down Expand Up @@ -49,6 +48,11 @@
verifying_key,
}
}

// TODO: consider moving to ZkVkHost trait.
pub fn get_elf(&self) -> &[u8] {
&self.elf
}

Check warning on line 55 in crates/zkvm/adapters/sp1/src/host.rs

View check run for this annotation

Codecov / codecov/patch

crates/zkvm/adapters/sp1/src/host.rs#L53-L55

Added lines #L53 - L55 were not covered by tests
}

impl ZkVmHost for SP1Host {
Expand Down Expand Up @@ -102,14 +106,6 @@

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
11 changes: 6 additions & 5 deletions crates/zkvm/hosts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ strata-sp1-guest-builder = { path = "../../../provers/sp1", optional = true }
strata-risc0-adapter = { workspace = true, optional = true }
strata-risc0-guest-builder = { path = "../../../provers/risc0", optional = true }

strata-primitives.workspace = true
# native
strata-native-zkvm-adapter = { workspace = true, optional = true }

# TODO: make it optional, via the native feature.
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
Expand All @@ -25,11 +25,12 @@ strata-proofimpl-l1-batch.workspace = true

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

[features]
native = []
default = []
native = ["strata-native-zkvm-adapter"]
risc0 = ["strata-risc0-adapter/prover", "strata-risc0-guest-builder/prover"]
sp1 = ["strata-sp1-adapter/prover", "strata-sp1-guest-builder/prover"]
51 changes: 29 additions & 22 deletions crates/zkvm/hosts/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,37 @@
// TODO figure out the cfg-if.
#[macro_use]
extern crate 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_if! {
if #[cfg(feature = "native")] {
pub mod native;
use strata_native_zkvm_adapter::NativeHost;

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_if! {
if #[cfg(feature = "risc0")] {
pub mod risc0;
use strata_risc0_adapter::Risc0Host;

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)
cfg_if! {
if #[cfg(feature = "sp1")] {
pub mod sp1;
use strata_sp1_adapter::SP1Host;

pub fn get_sp1_host(vm: ProofVm) -> &'static SP1Host {
sp1::get_host(vm)
}

Check warning on line 33 in crates/zkvm/hosts/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

crates/zkvm/hosts/src/lib.rs#L31-L33

Added lines #L31 - L33 were not covered by tests
}
}

/// An identifier of different prover types.
Expand Down
Loading
Loading