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

Add a benchmark/profiler to count cycles in demo-prover #577

Merged
merged 51 commits into from
Aug 16, 2023
Merged
Changes from 49 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
7a7f7de
extract data_gen into its own function
Jul 7, 2023
9a76147
Merge branch 'main' into dub/prover_bench
Jul 10, 2023
cec4f57
temp push
Jul 11, 2023
d5ee9d4
add prover cycles
Jul 11, 2023
0d26271
include multiple transactions
Jul 11, 2023
bfcf224
reduce txns
Jul 11, 2023
bfea7de
temp switch
Jul 13, 2023
4b24b1b
cycle tracker macro
Jul 20, 2023
e80fc78
another temp commit
Jul 26, 2023
8d3cac5
Merge branch 'main' into dub/prover_bench
Jul 26, 2023
d1e0008
Merge branch 'nightly' into dub/prover_bench
Jul 26, 2023
b9bd4d6
merge main and nightly
Jul 27, 2023
4bf1528
use run_without_prover for bench/profile
Jul 27, 2023
2fe0041
working metrics
Jul 28, 2023
f6193e4
add zk-cycle-utils. missed it
Jul 28, 2023
d2e080d
temporary commit
Jul 31, 2023
994912b
pass features to risc0 vm
Aug 1, 2023
aba3917
feature gate all the bench things
Aug 1, 2023
3ce4624
cleanup and testing
Aug 1, 2023
12ecf07
check in readme
Aug 1, 2023
b70e58e
checking some cargo locks in prep for merge
Aug 2, 2023
367d93d
Merge branch 'nightly' into dub/prover_bench
Aug 3, 2023
e5627d0
some fixes
Aug 3, 2023
2a9c7b1
revert rollup config toml
Aug 3, 2023
1818c58
working merge
Aug 3, 2023
0b4dbf7
cleanup and documentation
Aug 3, 2023
1011680
Merge branch 'nightly' into dub/prover_bench
Aug 3, 2023
26aa682
simplify the macro for generating the wrapped function
Aug 3, 2023
4c6ec0e
format fixes
Aug 4, 2023
7190a9a
README changes
Aug 4, 2023
92dc766
simplify code as per lint
Aug 4, 2023
d2bdff5
lint fix
Aug 4, 2023
2d9c6d5
add profiler to analyze trace
Aug 10, 2023
9ef3cc7
Merge branch 'nightly' into dub/prover_bench
Aug 10, 2023
cb641ef
fix cargo lock
Aug 10, 2023
3c54d90
really fix Cargo.lock
Aug 10, 2023
0eacdae
trace options
Aug 11, 2023
768eb77
cargo fmt
Aug 11, 2023
a07cd15
fix log error
Aug 11, 2023
f4fad22
Merge branch 'nightly' into dub/prover_bench
Aug 14, 2023
e8aae75
Merge branch 'nightly' into dub/prover_bench
Aug 14, 2023
87681d2
fix prover bench
Aug 14, 2023
4e94af8
fix nightly merge conflict
Aug 14, 2023
e31f995
add docs and address comments
Aug 14, 2023
993851e
prover bench readme
Aug 16, 2023
b11f60c
add a skip proving option to demo-prover
Aug 16, 2023
f708bb6
add tests for macros
Aug 16, 2023
c708fcf
demo prover format
Aug 16, 2023
817aaf5
Merge branch 'nightly' into dub/prover_bench
Aug 16, 2023
6d4b7be
remove commented code
Aug 16, 2023
2a3369f
formatting
Aug 16, 2023
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
46 changes: 46 additions & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -11,7 +11,10 @@ members = [
"examples/demo-nft-module",
"full-node/db/sov-db",
"full-node/sov-sequencer",
"utils/zk-cycle-macros",
"utils/zk-cycle-utils",
"full-node/sov-ethereum",

"full-node/sov-stf-runner",

"module-system/sov-cli",
6 changes: 6 additions & 0 deletions adapters/celestia/Cargo.toml
Original file line number Diff line number Diff line change
@@ -27,19 +27,25 @@ serde_json = { workspace = true }
tokio = { workspace = true, optional = true }
thiserror = { workspace = true }
tracing = { workspace = true }
zk-cycle-macros = {path = "../../utils/zk-cycle-macros", optional=true}
risc0-zkvm = { version = "0.16", default-features = false, features = ["std"], optional=true}
risc0-zkvm-platform = { version = "0.16", optional=true}

sov-rollup-interface = { path = "../../rollup-interface" }
nmt-rs = { git = "https://github.com/Sovereign-Labs/nmt-rs.git", rev = "dd37588444fca72825d11fe4a46838f66525c49f", features = ["serde", "borsh"] }


[dev-dependencies]
postcard = { version = "1", features = ["use-std"] }
proptest = { version = "1.2" }
wiremock = "0.5"


[build-dependencies]
prost-build = { version = "0.11" }

[features]
default = ["native"]
native = ["dep:tokio", "dep:jsonrpsee"]
bench = ["zk-cycle-macros/bench","risc0-zkvm","risc0-zkvm-platform"]
verifier = []
4 changes: 4 additions & 0 deletions adapters/celestia/src/verifier/mod.rs
Original file line number Diff line number Diff line change
@@ -13,6 +13,8 @@ pub mod address;
pub mod proofs;

use proofs::*;
#[cfg(all(target_os = "zkvm", feature = "bench"))]
use zk_cycle_macros::cycle_tracker;

use self::address::CelestiaAddress;
use crate::share_commit::recreate_commitment;
@@ -151,6 +153,7 @@ impl da::DaVerifier for CelestiaVerifier {
}
}

#[cfg_attr(all(target_os = "zkvm", feature = "bench"), cycle_tracker)]
fn verify_relevant_tx_list<H: Digest>(
&self,
block_header: &<Self::Spec as DaSpec>::BlockHeader,
@@ -248,6 +251,7 @@ impl da::DaVerifier for CelestiaVerifier {
let mut blob_iter = blob_ref.data();
let mut blob_data = vec![0; blob_iter.remaining()];
blob_iter.copy_to_slice(blob_data.as_mut_slice());

let tx_data = tx.data().accumulator();

match tx_data {
8 changes: 6 additions & 2 deletions adapters/risc0/Cargo.toml
Original file line number Diff line number Diff line change
@@ -15,13 +15,17 @@ readme = "README.md"
anyhow = { workspace = true }
bincode = { workspace = true }
risc0-zkvm = { version = "0.16", default-features = false, features = ['std'] }
risc0-zkvm-platform = { version = "0.16" }
risc0-zkp = { version = "0.16", optional = true }
risc0-circuit-rv32im = { version = "0.16", optional = true }
serde = { workspace = true }

bytemuck = "1.13.1"
once_cell = { version = "1.7.2", optional = true}
parking_lot = { version = "0.11.1", optional = true}
zk-cycle-utils = { path = "../../utils/zk-cycle-utils"}
sov-rollup-interface = { path = "../../rollup-interface" }


[features]
default = ["native"]
native = ["risc0-zkvm/prove", "dep:risc0-zkp", "dep:risc0-circuit-rv32im"]
bench = ["once_cell","parking_lot"]
25 changes: 24 additions & 1 deletion adapters/risc0/src/host.rs
Original file line number Diff line number Diff line change
@@ -7,7 +7,11 @@ use risc0_zkvm::{
};
use sov_rollup_interface::zk::{Zkvm, ZkvmHost};
use sov_rollup_interface::AddressTrait;
#[cfg(feature = "bench")]
use zk_cycle_utils::{cycle_count_callback, get_syscall_name, get_syscall_name_cycles};

#[cfg(feature = "bench")]
use crate::metrics::metrics_callback;
use crate::Risc0MethodId;

pub struct Risc0Host<'a> {
@@ -16,9 +20,28 @@ pub struct Risc0Host<'a> {
}

impl<'a> Risc0Host<'a> {
#[cfg(not(feature = "bench"))]
pub fn new(elf: &'a [u8]) -> Self {
let default_env = ExecutorEnvBuilder::default();

Self {
env: RefCell::new(default_env),
elf,
}
}

#[cfg(feature = "bench")]
pub fn new(elf: &'a [u8]) -> Self {
let mut default_env = ExecutorEnvBuilder::default();

let metrics_syscall_name = get_syscall_name();
default_env.io_callback(metrics_syscall_name, metrics_callback);

let cycles_syscall_name = get_syscall_name_cycles();
default_env.io_callback(cycles_syscall_name, cycle_count_callback);

Self {
env: RefCell::new(ExecutorEnvBuilder::default()),
env: RefCell::new(default_env),
elf,
}
}
3 changes: 3 additions & 0 deletions adapters/risc0/src/lib.rs
Original file line number Diff line number Diff line change
@@ -6,6 +6,9 @@ pub mod guest;
#[cfg(feature = "native")]
pub mod host;

#[cfg(feature = "bench")]
pub mod metrics;

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Risc0MethodId([u32; 8]);

33 changes: 33 additions & 0 deletions adapters/risc0/src/metrics.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use std::collections::HashMap;

use once_cell::sync::Lazy;
use parking_lot::Mutex;

pub static GLOBAL_HASHMAP: Lazy<Mutex<HashMap<String, (u64, u64)>>> =
Lazy::new(|| Mutex::new(HashMap::new()));

pub fn add_value(metric: String, value: u64) {
let mut hashmap = GLOBAL_HASHMAP.lock();
hashmap
.entry(metric)
.and_modify(|(sum, count)| {
*sum += value;
*count += 1;
})
.or_insert((value, 1));
}

pub fn deserialize_custom(serialized: &[u8]) -> (String, u64) {
let null_pos = serialized.iter().position(|&b| b == 0).unwrap();
let (string_bytes, size_bytes_with_null) = serialized.split_at(null_pos);
let size_bytes = &size_bytes_with_null[1..]; // Skip the null terminator
let string = String::from_utf8(string_bytes.to_vec()).unwrap();
let size = u64::from_ne_bytes(size_bytes.try_into().unwrap()); // Convert bytes back into usize
(string, size)
}

pub fn metrics_callback(input: &[u8]) -> Vec<u8> {
let met_tuple = deserialize_custom(input);
add_value(met_tuple.0, met_tuple.1);
vec![]
}
Loading