Skip to content

Commit ef975f1

Browse files
shekhirinrkrasiuk
andauthored
feat(rpc): add preimages to execution witness response (#10456)
Co-authored-by: Roman Krasiuk <[email protected]>
1 parent d59854f commit ef975f1

File tree

6 files changed

+46
-8
lines changed

6 files changed

+46
-8
lines changed

Cargo.lock

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,7 @@ alloy-rpc-types = { version = "0.3.0", features = [
430430
alloy-rpc-types-admin = { version = "0.3.0", default-features = false }
431431
alloy-rpc-types-anvil = { version = "0.3.0", default-features = false }
432432
alloy-rpc-types-beacon = { version = "0.3.0", default-features = false }
433+
alloy-rpc-types-debug = { version = "0.3.0", default-features = false }
433434
alloy-rpc-types-engine = { version = "0.3.0", default-features = false }
434435
alloy-rpc-types-eth = { version = "0.3.0", default-features = false }
435436
alloy-rpc-types-mev = { version = "0.3.0", default-features = false }

crates/rpc/rpc-api/src/debug.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
use jsonrpsee::{core::RpcResult, proc_macros::rpc};
22
use reth_primitives::{Address, BlockId, BlockNumberOrTag, Bytes, B256};
33
use reth_rpc_types::{
4+
debug::ExecutionWitness,
45
trace::geth::{
56
BlockTraceResult, GethDebugTracingCallOptions, GethDebugTracingOptions, GethTrace,
67
TraceResult,
78
},
89
Block, Bundle, StateContext, TransactionRequest,
910
};
10-
use std::collections::HashMap;
1111

1212
/// Debug rpc interface.
1313
#[cfg_attr(not(feature = "client"), rpc(server, namespace = "debug"))]
@@ -138,12 +138,14 @@ pub trait DebugApi {
138138
/// to their preimages that were required during the execution of the block, including during
139139
/// state root recomputation.
140140
///
141-
/// The first and only argument is the block number or block hash.
141+
/// The first argument is the block number or block hash. The second argument is a boolean
142+
/// indicating whether to include the preimages of keys in the response.
142143
#[method(name = "executionWitness")]
143144
async fn debug_execution_witness(
144145
&self,
145146
block: BlockNumberOrTag,
146-
) -> RpcResult<HashMap<B256, Bytes>>;
147+
include_preimages: bool,
148+
) -> RpcResult<ExecutionWitness>;
147149

148150
/// Sets the logging backtrace location. When a backtrace location is set and a log message is
149151
/// emitted at that location, the stack of the goroutine executing the log statement will

crates/rpc/rpc-types/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ alloy-rpc-types-beacon = { workspace = true, optional = true }
2222
alloy-rpc-types-mev.workspace = true
2323
alloy-rpc-types-trace.workspace = true
2424
alloy-rpc-types-txpool.workspace = true
25+
alloy-rpc-types-debug.workspace = true
2526
alloy-serde.workspace = true
2627
alloy-rpc-types-engine = { workspace = true, features = ["jsonrpsee-types"], optional = true }
2728

crates/rpc/rpc-types/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ pub use alloy_rpc_types_beacon as beacon;
4646
// re-export txpool
4747
pub use alloy_rpc_types_txpool as txpool;
4848

49+
// re-export debug
50+
pub use alloy_rpc_types_debug as debug;
51+
4952
// Ethereum specific rpc types related to typed transaction requests and the engine API.
5053
#[cfg(feature = "jsonrpsee-types")]
5154
pub use eth::error::ToRpcError;

crates/rpc/rpc/src/debug.rs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use reth_rpc_eth_api::{
2222
use reth_rpc_eth_types::{EthApiError, StateCacheDb};
2323
use reth_rpc_server_types::{result::internal_rpc_err, ToRpcResult};
2424
use reth_rpc_types::{
25+
debug::ExecutionWitness,
2526
state::EvmOverrides,
2627
trace::geth::{
2728
BlockTraceResult, FourByteFrame, GethDebugBuiltInTracerType, GethDebugTracerType,
@@ -567,7 +568,8 @@ where
567568
pub async fn debug_execution_witness(
568569
&self,
569570
block_id: BlockNumberOrTag,
570-
) -> Result<HashMap<B256, Bytes>, Eth::Error> {
571+
include_preimages: bool,
572+
) -> Result<ExecutionWitness, Eth::Error> {
571573
let ((cfg, block_env, _), maybe_block) = futures::try_join!(
572574
self.inner.eth_api.evm_env_at(block_id.into()),
573575
self.inner.eth_api.block_with_senders(block_id.into()),
@@ -628,6 +630,9 @@ where
628630
// Take the bundle state
629631
let bundle_state = db.take_bundle();
630632

633+
// Initialize a map of preimages.
634+
let mut state_preimages = HashMap::new();
635+
631636
// Grab all account proofs for the data accessed during block execution.
632637
//
633638
// Note: We grab *all* accounts in the cache here, as the `BundleState` prunes
@@ -646,9 +651,19 @@ where
646651
.or_insert_with(|| HashedStorage::new(account.status.was_destroyed()));
647652

648653
if let Some(account) = account.account {
654+
if include_preimages {
655+
state_preimages
656+
.insert(hashed_address, alloy_rlp::encode(address).into());
657+
}
658+
649659
for (slot, value) in account.storage {
650-
let hashed_slot = keccak256(B256::from(slot));
660+
let slot = B256::from(slot);
661+
let hashed_slot = keccak256(slot);
651662
storage.storage.insert(hashed_slot, value);
663+
664+
if include_preimages {
665+
state_preimages.insert(hashed_slot, alloy_rlp::encode(slot).into());
666+
}
652667
}
653668
}
654669
}
@@ -659,7 +674,11 @@ where
659674
let witness = state_provider
660675
.witness(HashedPostState::default(), hashed_state)
661676
.map_err(Into::into)?;
662-
Ok(witness)
677+
678+
Ok(ExecutionWitness {
679+
witness,
680+
state_preimages: include_preimages.then_some(state_preimages),
681+
})
663682
})
664683
.await
665684
}
@@ -931,9 +950,10 @@ where
931950
async fn debug_execution_witness(
932951
&self,
933952
block: BlockNumberOrTag,
934-
) -> RpcResult<HashMap<B256, Bytes>> {
953+
include_preimages: bool,
954+
) -> RpcResult<ExecutionWitness> {
935955
let _permit = self.acquire_trace_permit().await;
936-
Self::debug_execution_witness(self, block).await.map_err(Into::into)
956+
Self::debug_execution_witness(self, block, include_preimages).await.map_err(Into::into)
937957
}
938958

939959
/// Handler for `debug_traceCall`

0 commit comments

Comments
 (0)