Skip to content

Commit

Permalink
change to use output struct
Browse files Browse the repository at this point in the history
  • Loading branch information
S1nus committed Dec 24, 2024
1 parent d04492d commit c2879ef
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 35 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ members = [
resolver = "2"

[workspace.dependencies]
serde = { version = "1.0.200", default-features = false, features = ["derive"] }
alloy-sol-types = "0.7.7"
rsp-client-executor = {git = "https://github.com/succinctlabs/rsp.git", rev="c01149568a2ed4d3e766756e8b847c870a0b1e4e"}
reth-primitives = { git = "https://github.com/sp1-patches/reth", tag = "rsp-20240830", default-features = false, features = [
Expand Down
3 changes: 2 additions & 1 deletion blevm-mock/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ name = "blevm-mock"
edition = "2021"

[dependencies]
sp1-zkvm = "3.0.0-rc4"
sp1-zkvm = "3.0.0-rc4"
blevm-common = { path = "../common" }
22 changes: 14 additions & 8 deletions blevm-mock/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#![no_main]
sp1_zkvm::entrypoint!(main);

use blevm_common::BlevmOutput;

pub fn main() {
let blob_commitment = sp1_zkvm::io::read::<Vec<u8>>();
let header_hash = sp1_zkvm::io::read::<Vec<u8>>();
Expand All @@ -15,12 +17,16 @@ pub fn main() {
let state_root = sp1_zkvm::io::read::<Vec<u8>>();
let celestia_header_hash = sp1_zkvm::io::read::<Vec<u8>>();

sp1_zkvm::io::commit_slice(&blob_commitment);
sp1_zkvm::io::commit_slice(&header_hash);
sp1_zkvm::io::commit_slice(&prev_header_hash);
sp1_zkvm::io::commit(&height);
sp1_zkvm::io::commit(&gas_used);
sp1_zkvm::io::commit_slice(&beneficiary);
sp1_zkvm::io::commit_slice(&state_root);
sp1_zkvm::io::commit(&celestia_header_hash);
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(),
};

sp1_zkvm::io::commit(&output);
}
3 changes: 2 additions & 1 deletion blevm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ reth-primitives = {workspace=true}
tendermint = {workspace=true}
tendermint-proto = {workspace=true}
bincode = {workspace=true}
hex = "0.4.3"
hex = "0.4.3"
blevm-common = {path = "../common"}
37 changes: 13 additions & 24 deletions blevm/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ use celestia_types::{
ExtendedHeader,
};
use nmt_rs::simple_merkle::tree::MerkleHash;
use std::io::Read;
//use nmt_rs::{simple_merkle::proof::Proof, TmSha2Hasher};
use blevm_common::BlevmOutput;
use nmt_rs::{simple_merkle::proof::Proof, NamespacedHash, TmSha2Hasher};
use reth_primitives::Block;
use rsp_client_executor::{
Expand Down Expand Up @@ -93,31 +95,18 @@ pub fn main() {
"cycle-tracker-start: hashing the block header, and commiting fields as public values"
);

// Commit the Celestia blob commitment for this block
let blob_commitment = blob.commitment.0;
sp1_zkvm::io::commit_slice(&blob_commitment);
let header_hash: Vec<u8> = header.hash_slow().to_vec();
sp1_zkvm::io::commit_slice(&header_hash);
let output = BlevmOutput {
blob_commitment: blob.commitment.0,
header_hash: header.hash_slow().into(),
prev_header_hash: header.parent_hash.into(),
height: header.number,
gas_used: header.gas_used,
beneficiary: header.beneficiary.into(),
state_root: header.state_root.into(),
celestia_header_hash: celestia_header_hash.as_bytes().try_into().unwrap(),
};
sp1_zkvm::io::commit(&output);

// Commit the prev header hash, so we can form a blockchain
let prev_header_hash: Vec<u8> = header.parent_hash.to_vec();
sp1_zkvm::io::commit_slice(&prev_header_hash);

let height: u64 = header.number;
sp1_zkvm::io::commit(&height);

let gas_used: u64 = header.gas_used;
sp1_zkvm::io::commit(&gas_used);

// beneficiary is the address of the person who collects the fees
// usually the proposer
let beneficiary = header.beneficiary.as_slice();
sp1_zkvm::io::commit_slice(&beneficiary);

let state_root = header.state_root.as_slice();
sp1_zkvm::io::commit_slice(&state_root);

sp1_zkvm::io::commit(&celestia_header_hash);
println!(
"cycle-tracker-end: hashing the block header, and commiting its fields as public values"
);
Expand Down
2 changes: 1 addition & 1 deletion common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ name = "blevm-common"
edition = "2021"

[dependencies]
serde = { version = "1.0.200", default-features = false, features = ["derive"] }
serde = { workspace = true }
bincode = { workspace = true }
3 changes: 3 additions & 0 deletions common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize)]
pub struct BlevmOutput {
pub blob_commitment: [u8; 32],
pub header_hash: [u8; 32],
Expand Down
Binary file modified elf/riscv32im-succinct-zkvm-elf
Binary file not shown.

0 comments on commit c2879ef

Please sign in to comment.