Skip to content

Commit

Permalink
fix conv
Browse files Browse the repository at this point in the history
  • Loading branch information
lightsing committed Nov 19, 2024
1 parent 6c26082 commit dd31b7b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 19 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

45 changes: 27 additions & 18 deletions crates/primitives/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,22 +320,27 @@ impl<'de> Deserialize<'de> for StorageTrace {
}
}

impl From<StorageTrace> for StorageTrace<ArchivedNodeBytes> {
fn from(trace: StorageTrace) -> Self {
impl StorageTrace {
/// turn the proofs to archived
fn to_archived(self, hash_scheme: HashSchemeKind) -> StorageTrace<ArchivedNodeBytes> {
StorageTrace {
root_before: trace.root_before,
root_after: trace.root_after,
flatten_proofs: trace
root_before: self.root_before,
root_after: self.root_after,
flatten_proofs: self
.flatten_proofs
.into_iter()
.filter(|proof| proof.as_ref() != MAGIC_NODE_BYTES)
.map(|proof| {
ArchivedNodeBytes(
Node::<Poseidon>::try_from(proof.as_ref())
ArchivedNodeBytes(match hash_scheme {
HashSchemeKind::Poseidon => Node::<Poseidon>::try_from(proof.as_ref())
.expect("invalid node")
.archived()
.to_vec(),
HashSchemeKind::Keccak => Node::<Keccak>::try_from(proof.as_ref())
.expect("invalid node")
.archived()
.to_vec(),
)
})
})
.collect(),
}
Expand Down Expand Up @@ -363,17 +368,21 @@ impl From<LegacyStorageTrace> for StorageTrace {
}
}

impl From<BlockTrace> for BlockTrace<StorageTrace<ArchivedNodeBytes>> {
fn from(trace: BlockTrace) -> Self {
impl BlockTrace {
/// turn the proofs to archived
pub fn to_archived_nodes(
self: BlockTrace,
hash_scheme: HashSchemeKind,
) -> BlockTrace<StorageTrace<ArchivedNodeBytes>> {
BlockTrace {
chain_id: trace.chain_id,
coinbase: trace.coinbase,
header: trace.header,
transactions: trace.transactions,
codes: trace.codes,
storage_trace: trace.storage_trace.into(),
start_l1_queue_index: trace.start_l1_queue_index,
withdraw_trie_root: trace.withdraw_trie_root,
chain_id: self.chain_id,
coinbase: self.coinbase,
header: self.header,
transactions: self.transactions,
codes: self.codes,
storage_trace: self.storage_trace.to_archived(hash_scheme),
start_l1_queue_index: self.start_l1_queue_index,
withdraw_trie_root: self.withdraw_trie_root,
}
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/stateful/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ anyhow.workspace = true
clap = { workspace = true, features = ["derive"] }
bincode.workspace = true
revm.workspace = true
rkyv.workspace = true
sled.workspace = true
serde = { workspace = true, features = ["derive"] }
serde_json.workspace = true
Expand Down
8 changes: 7 additions & 1 deletion crates/stateful/src/bin/tracer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//! trace dumper
use clap::Parser;
use rkyv::rancor;
use sbv::core::{EvmExecutorBuilder, HardforkConfig};
use sbv::primitives::alloy_primitives::Bytes;
use sbv::primitives::types::{BlockTrace, BytecodeTrace, StorageTrace};
use stateful_block_verifier::Metadata;
use std::path::PathBuf;
Expand All @@ -9,6 +11,7 @@ use zktrie_ng::db::NodeDb;
use zktrie_ng::hash::keccak::Keccak;
use zktrie_ng::hash::poseidon::Poseidon;
use zktrie_ng::hash::HashSchemeKind;
use zktrie_ng::trie::ArchivedNode;

#[derive(Parser)]
struct Cli {
Expand Down Expand Up @@ -103,7 +106,10 @@ fn main() -> anyhow::Result<()> {
.into_inner()
.take_read_items()
.into_iter()
.map(|(_, v)| v.into())
.map(|(_, v)| {
let node = rkyv::access::<ArchivedNode, rancor::Error>(v.as_ref()).unwrap();
Bytes::from(node.canonical_value(false))
})
.collect(),
},
&block,
Expand Down

0 comments on commit dd31b7b

Please sign in to comment.