From ade0466a60727ff5ca865b72b13a3e4dba4fe41c Mon Sep 17 00:00:00 2001 From: Marko Atanasievski Date: Wed, 12 Jun 2024 23:32:15 +0200 Subject: [PATCH] feat: add transaction hash to zero trace (#103) * 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 --- zero_bin/Cargo.lock | 16 +++++++------- zero_bin/Cargo.toml | 6 +++--- zero_bin/rpc/src/lib.rs | 46 +++++++++++++++++++++-------------------- 3 files changed, 35 insertions(+), 33 deletions(-) diff --git a/zero_bin/Cargo.lock b/zero_bin/Cargo.lock index f8aef11f4..9217b8715 100644 --- a/zero_bin/Cargo.lock +++ b/zero_bin/Cargo.lock @@ -1737,8 +1737,8 @@ dependencies = [ [[package]] name = "evm_arithmetization" -version = "0.1.3" -source = "git+https://github.com/0xPolygonZero/zk_evm.git?tag=v0.3.1#c55f9e05f571b1b8658315e6de83427fe1d4efa3" +version = "0.2.0" +source = "git+https://github.com/0xPolygonZero/zk_evm.git?tag=v0.4.0#46eb449a5a97438ade3f22e2555d7f266b54b290" dependencies = [ "anyhow", "bytes", @@ -2742,8 +2742,8 @@ dependencies = [ [[package]] name = "mpt_trie" -version = "0.2.1" -source = "git+https://github.com/0xPolygonZero/zk_evm.git?tag=v0.3.1#c55f9e05f571b1b8658315e6de83427fe1d4efa3" +version = "0.3.0" +source = "git+https://github.com/0xPolygonZero/zk_evm.git?tag=v0.4.0#46eb449a5a97438ade3f22e2555d7f266b54b290" dependencies = [ "bytes", "enum-as-inner", @@ -3394,8 +3394,8 @@ dependencies = [ [[package]] name = "proof_gen" -version = "0.1.3" -source = "git+https://github.com/0xPolygonZero/zk_evm.git?tag=v0.3.1#c55f9e05f571b1b8658315e6de83427fe1d4efa3" +version = "0.2.0" +source = "git+https://github.com/0xPolygonZero/zk_evm.git?tag=v0.4.0#46eb449a5a97438ade3f22e2555d7f266b54b290" dependencies = [ "ethereum-types", "evm_arithmetization", @@ -4567,8 +4567,8 @@ checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" [[package]] name = "trace_decoder" -version = "0.3.1" -source = "git+https://github.com/0xPolygonZero/zk_evm.git?tag=v0.3.1#c55f9e05f571b1b8658315e6de83427fe1d4efa3" +version = "0.4.0" +source = "git+https://github.com/0xPolygonZero/zk_evm.git?tag=v0.4.0#46eb449a5a97438ade3f22e2555d7f266b54b290" dependencies = [ "bytes", "ciborium", diff --git a/zero_bin/Cargo.toml b/zero_bin/Cargo.toml index a34224fdf..8433d3326 100644 --- a/zero_bin/Cargo.toml +++ b/zero_bin/Cargo.toml @@ -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" diff --git a/zero_bin/rpc/src/lib.rs b/zero_bin/rpc/src/lib.rs index 0d7fcb78b..9fbbe122e 100644 --- a/zero_bin/rpc/src/lib.rs +++ b/zero_bin/rpc/src/lib.rs @@ -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. @@ -60,24 +65,19 @@ where TransportT: Transport + Clone, { // Grab trace information - ///////////////////////// - let traces = provider - .raw_request::<_, Vec>( + let tx_results = provider + .raw_request::<_, Vec>( "debug_traceBlockByNumber".into(), (target_block_id, json!({"tracer": "zeroTracer"})), ) .await?; - let (txn_info, mut pre_images) = - traces - .into_iter() - .partition_map::, 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? @@ -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 {