Skip to content

Commit

Permalink
make mock runnable
Browse files Browse the repository at this point in the history
  • Loading branch information
rootulp committed Feb 4, 2025
1 parent a9e8a70 commit 69306ea
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 20 deletions.
10 changes: 10 additions & 0 deletions provers/blevm/Cargo.lock

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

9 changes: 9 additions & 0 deletions provers/blevm/blevm-mock/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,12 @@ edition = "2021"
[dependencies]
sp1-zkvm = { workspace = true }
blevm-common = { path = "../common" }
alloy-sol-types = { workspace = true }
rsp-client-executor = {workspace=true}
celestia-types = {workspace=true}
nmt-rs = "*"
reth-primitives = {workspace=true}
tendermint = {workspace=true}
tendermint-proto = {workspace=true}
bincode = {workspace=true}
hex = "0.4.3"
60 changes: 44 additions & 16 deletions provers/blevm/blevm-mock/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,55 @@
sp1_zkvm::entrypoint!(main);

use blevm_common::BlevmOutput;
use celestia_types::nmt::{NamespaceProof, NamespacedHashExt};
use celestia_types::{nmt::Namespace, AppVersion, Blob};
use nmt_rs::simple_merkle::tree::MerkleHash;
use nmt_rs::{simple_merkle::proof::Proof, NamespacedHash, TmSha2Hasher};
use rsp_client_executor::{io::ClientExecutorInput, ClientExecutor, EthereumVariant};
use tendermint::Hash as TmHash;
use tendermint_proto::Protobuf;

pub fn main() {
let blob_commitment = sp1_zkvm::io::read::<Vec<u8>>();
let header_hash = sp1_zkvm::io::read::<Vec<u8>>();
let prev_header_hash = sp1_zkvm::io::read::<Vec<u8>>();
let height = sp1_zkvm::io::read::<u64>();
let gas_used = sp1_zkvm::io::read::<u64>();
let beneficiary = sp1_zkvm::io::read::<Vec<u8>>();
let state_root = sp1_zkvm::io::read::<Vec<u8>>();
// Read all the input values.
let input: ClientExecutorInput = sp1_zkvm::io::read();
let namespace: Namespace = sp1_zkvm::io::read();
let celestia_header_hash = sp1_zkvm::io::read::<Vec<u8>>();
let data_hash_bytes: Vec<u8> = sp1_zkvm::io::read_vec();
let data_hash_proof: Proof<TmSha2Hasher> = sp1_zkvm::io::read();
let row_root_multiproof: Proof<TmSha2Hasher> = sp1_zkvm::io::read();
let nmt_multiproofs: Vec<NamespaceProof> = sp1_zkvm::io::read();
let row_roots: Vec<NamespacedHash<29>> = sp1_zkvm::io::read();

// since this is a mock proof, we can hard-code all the output values to be the same as a valid
// execution of blevm.
let output = BlevmOutput {
blob_commitment: blob_commitment.try_into().unwrap(),
header_hash: header_hash.try_into().unwrap(),
prev_header_hash: prev_header_hash.try_into().unwrap(),
height,
gas_used,
beneficiary: beneficiary.try_into().unwrap(),
state_root: state_root.try_into().unwrap(),
celestia_header_hash: celestia_header_hash.try_into().unwrap(),
blob_commitment: [
196, 0, 0, 0, 0, 0, 0, 0, 121, 70, 207, 82, 142, 221, 116, 94, 251, 37, 32, 18, 70,
230, 71, 213, 170, 202, 63, 181, 43, 240, 246, 6,
],
header_hash: [
182, 149, 180, 171, 11, 211, 63, 76, 133, 106, 134, 184, 20, 76, 104, 254, 40, 136, 41,
140, 238, 199, 193, 86, 163, 56, 170, 193, 61, 146, 213, 227,
],
prev_header_hash: [
194, 70, 12, 164, 151, 147, 237, 105, 187, 154, 187, 153, 78, 140, 25, 59, 84, 254,
152, 25, 224, 239, 83, 45, 145, 73, 226, 110, 100, 51, 95, 167,
],
height: 14900876081506838043,
gas_used: 18884864,
beneficiary: [
4, 26, 65, 0, 0, 0, 0, 0, 149, 34, 34, 144, 221, 114, 120, 170, 61, 221, 56, 156,
],
state_root: [
193, 225, 209, 101, 204, 75, 175, 229, 27, 56, 213, 58, 25, 68, 72, 76, 140, 126, 48,
23, 127, 212, 219, 222, 63, 98, 45, 102, 165, 88, 255, 220,
],
celestia_header_hash: [
120, 107, 54, 46, 182, 50, 89, 93, 115, 224, 125, 214, 72, 215, 109, 67, 90, 48, 217,
144, 215, 85, 206, 228, 192, 183, 123, 79, 244, 136, 195, 212,
],
};

sp1_zkvm::io::commit(&output);
let serialized_output = bincode::serialize(&output).unwrap();
sp1_zkvm::io::commit(&serialized_output);
}
3 changes: 2 additions & 1 deletion provers/blevm/blevm/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ pub fn main() {
state_root: header.state_root.into(),
celestia_header_hash: celestia_header_hash.as_bytes().try_into().unwrap(),
};
sp1_zkvm::io::commit(&output);
let serialized_output = bincode::serialize(&output).unwrap();
sp1_zkvm::io::commit(&serialized_output);

println!(
"cycle-tracker-end: hashing the block header, and commiting its fields as public values"
Expand Down
2 changes: 1 addition & 1 deletion provers/blevm/common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize)]
#[derive(Serialize, Deserialize, Debug)]
pub struct BlevmOutput {
pub blob_commitment: [u8; 32],
pub header_hash: [u8; 32],
Expand Down
4 changes: 3 additions & 1 deletion provers/blevm/script/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ bincode = { workspace = true }
rsp-client-executor = { workspace = true }
nmt-rs = { workspace = true }
tokio = { version = "1", features = ["full"] }
blevm-prover = { path = "../blevm-prover" }
dotenv = "0.15.0"

blevm-prover = { path = "../blevm-prover" }
blevm-common = {path = "../common"}

[build-dependencies]
sp1-helper = { workspace = true }
sp1-build = { workspace = true }
5 changes: 4 additions & 1 deletion provers/blevm/script/src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
//! ```shell
//! RUST_LOG=info cargo run --release -- --prove --mock
//! ```
use blevm_common::BlevmOutput;
use blevm_prover::{BlockProver, BlockProverInput, CelestiaClient, CelestiaConfig, ProverConfig};
use celestia_types::nmt::Namespace;
use clap::Parser;
Expand Down Expand Up @@ -84,7 +85,9 @@ async fn main() -> Result<(), Box<dyn Error>> {
println!("Executing...");
let (public_values, execution_report) = prover.execute(input).await?;
println!("Program executed successfully.");
println!("Public values: {:?}", public_values);

let output: BlevmOutput = bincode::deserialize(public_values.as_slice()).unwrap();
println!("{:?}", output);
println!(
"Number of cycles: {}",
execution_report.total_instruction_count()
Expand Down

0 comments on commit 69306ea

Please sign in to comment.