Skip to content

Commit

Permalink
fix: eth_getProof response (paradigmxyz#12370)
Browse files Browse the repository at this point in the history
  • Loading branch information
klkvr authored Nov 7, 2024
1 parent d0baf92 commit 29da7d7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
2 changes: 1 addition & 1 deletion crates/rpc/rpc-eth-api/src/helpers/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand Down
25 changes: 17 additions & 8 deletions crates/rpc/rpc-types-compat/src/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<JsonStorageKey>,
) -> EIP1186AccountProofResponse {
let info = proof.info.unwrap_or_default();
EIP1186AccountProofResponse {
address: proof.address,
Expand All @@ -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(),
}
}

0 comments on commit 29da7d7

Please sign in to comment.