Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Commit

Permalink
feat: add transaction hash to zero trace (#103)
Browse files Browse the repository at this point in the history
* feat: add txHash to ZeroTrace

Retrieve block witness with a separate rpc call

* fix: update zk_evm dependency to develop branch

* fix: comments

* fix: use zk_evm v0.4.0
  • Loading branch information
atanmarko authored Jun 12, 2024
1 parent 1648e70 commit 146242d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 33 deletions.
16 changes: 8 additions & 8 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ alloy = { git = "https://github.com/alloy-rs/alloy", features = [

# zk-evm dependencies
plonky2 = "0.2.2"
evm_arithmetization = { git = "https://github.com/0xPolygonZero/zk_evm.git", tag = "v0.3.1" }
trace_decoder = { git = "https://github.com/0xPolygonZero/zk_evm.git", tag = "v0.3.1" }
proof_gen = { git = "https://github.com/0xPolygonZero/zk_evm.git", tag = "v0.3.1" }
evm_arithmetization = { git = "https://github.com/0xPolygonZero/zk_evm.git", tag = "v0.4.0" }
trace_decoder = { git = "https://github.com/0xPolygonZero/zk_evm.git", tag = "v0.4.0" }
proof_gen = { git = "https://github.com/0xPolygonZero/zk_evm.git", tag = "v0.4.0" }

[workspace.package]
edition = "2021"
Expand Down
46 changes: 24 additions & 22 deletions rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,28 @@ use anyhow::Context as _;
use common::block_interval::BlockInterval;
use evm_arithmetization::proof::{BlockHashes, BlockMetadata};
use futures::{StreamExt as _, TryStreamExt as _};
use itertools::{Either, Itertools as _};
use prover::{BlockProverInput, ProverInput};
use serde::Deserialize;
use serde_json::json;
use trace_decoder::{
trace_protocol::{BlockTrace, BlockTraceTriePreImages, TxnInfo},
trace_protocol::{
BlockTrace, BlockTraceTriePreImages, CombinedPreImages, TrieCompact, TxnInfo,
},
types::{BlockLevelData, OtherBlockData},
};

#[derive(Deserialize, Debug)]
#[serde(rename_all = "snake_case")]
#[allow(clippy::large_enum_variant)]
enum ZeroTrace {
Result(TxnInfo),
BlockWitness(BlockTraceTriePreImages),
/// Transaction traces retrieved from Erigon zeroTracer.
#[derive(Debug, Deserialize)]
pub struct ZeroTxResult {
#[serde(rename(deserialize = "txHash"))]
pub tx_hash: alloy::primitives::TxHash,
pub result: TxnInfo,
}

/// Block witness retrieved from Erigon zeroTracer.
#[derive(Debug, Deserialize)]
pub struct ZeroBlockWitness(TrieCompact);

/// When [fetching a block over RPC](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_getblockbynumber),
/// we can choose the transaction format, between:
/// - Full JSON.
Expand Down Expand Up @@ -60,24 +65,19 @@ where
TransportT: Transport + Clone,
{
// Grab trace information
/////////////////////////
let traces = provider
.raw_request::<_, Vec<ZeroTrace>>(
let tx_results = provider
.raw_request::<_, Vec<ZeroTxResult>>(
"debug_traceBlockByNumber".into(),
(target_block_id, json!({"tracer": "zeroTracer"})),
)
.await?;

let (txn_info, mut pre_images) =
traces
.into_iter()
.partition_map::<Vec<_>, Vec<_>, _, _, _>(|it| match it {
ZeroTrace::Result(it) => Either::Left(it),
ZeroTrace::BlockWitness(it) => Either::Right(it),
});
// Grab block witness info (packed as combined trie pre-images)
let block_witness = provider
.raw_request::<_, ZeroBlockWitness>("eth_getWitness".into(), vec![target_block_id])
.await?;

// Grab block info
//////////////////
let target_block = provider
.get_block(target_block_id, BLOCK_WITH_FULL_TRANSACTIONS)
.await?
Expand Down Expand Up @@ -116,11 +116,13 @@ where
.context("couldn't fill previous hashes")?;

// Assemble
///////////
Ok(BlockProverInput {
block_trace: BlockTrace {
trie_pre_images: pre_images.pop().context("trace had no BlockWitness")?,
txn_info,
trie_pre_images: BlockTraceTriePreImages::Combined(CombinedPreImages {
compact: block_witness.0,
}),
txn_info: tx_results.into_iter().map(|it| it.result).collect(),
code_db: Default::default(),
},
other_data: OtherBlockData {
b_data: BlockLevelData {
Expand Down

0 comments on commit 146242d

Please sign in to comment.