From 29da7d744a52f9d77d27cc78705dc30e265f20bf Mon Sep 17 00:00:00 2001 From: Arsenii Kulikov Date: Thu, 7 Nov 2024 23:31:17 +0400 Subject: [PATCH] fix: `eth_getProof` response (#12370) --- crates/rpc/rpc-eth-api/src/helpers/state.rs | 2 +- crates/rpc/rpc-types-compat/src/proof.rs | 25 ++++++++++++++------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/crates/rpc/rpc-eth-api/src/helpers/state.rs b/crates/rpc/rpc-eth-api/src/helpers/state.rs index f3796b4b9b..6a34967058 100644 --- a/crates/rpc/rpc-eth-api/src/helpers/state.rs +++ b/crates/rpc/rpc-eth-api/src/helpers/state.rs @@ -122,7 +122,7 @@ pub trait EthState: LoadState + SpawnBlocking { let proof = state .proof(Default::default(), address, &storage_keys) .map_err(Self::Error::from_eth_err)?; - Ok(from_primitive_account_proof(proof)) + Ok(from_primitive_account_proof(proof, keys)) }) .await }) diff --git a/crates/rpc/rpc-types-compat/src/proof.rs b/crates/rpc/rpc-types-compat/src/proof.rs index 7bdf629e96..34128801f8 100644 --- a/crates/rpc/rpc-types-compat/src/proof.rs +++ b/crates/rpc/rpc-types-compat/src/proof.rs @@ -5,16 +5,18 @@ use alloy_rpc_types_eth::{EIP1186AccountProofResponse, EIP1186StorageProof}; use reth_trie_common::{AccountProof, StorageProof}; /// Creates a new rpc storage proof from a primitive storage proof type. -pub fn from_primitive_storage_proof(proof: StorageProof) -> EIP1186StorageProof { - EIP1186StorageProof { - key: JsonStorageKey::Hash(proof.key), - value: proof.value, - proof: proof.proof, - } +pub fn from_primitive_storage_proof( + proof: StorageProof, + slot: JsonStorageKey, +) -> EIP1186StorageProof { + EIP1186StorageProof { key: slot, value: proof.value, proof: proof.proof } } /// Creates a new rpc account proof from a primitive account proof type. -pub fn from_primitive_account_proof(proof: AccountProof) -> EIP1186AccountProofResponse { +pub fn from_primitive_account_proof( + proof: AccountProof, + slots: Vec, +) -> EIP1186AccountProofResponse { let info = proof.info.unwrap_or_default(); EIP1186AccountProofResponse { address: proof.address, @@ -23,6 +25,13 @@ pub fn from_primitive_account_proof(proof: AccountProof) -> EIP1186AccountProofR nonce: info.nonce, storage_hash: proof.storage_root, account_proof: proof.proof, - storage_proof: proof.storage_proofs.into_iter().map(from_primitive_storage_proof).collect(), + storage_proof: proof + .storage_proofs + .into_iter() + .filter_map(|proof| { + let input_slot = slots.iter().find(|s| s.as_b256() == proof.key)?; + Some(from_primitive_storage_proof(proof, *input_slot)) + }) + .collect(), } }