Skip to content

Commit

Permalink
verify proofs
Browse files Browse the repository at this point in the history
  • Loading branch information
joshieDo committed Nov 26, 2024
1 parent c056d6e commit 9027de2
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 30 deletions.
3 changes: 2 additions & 1 deletion Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ reth-payload-builder = { git = "https://github.com/paradigmxyz/reth.git", rev =
reth-primitives = { git = "https://github.com/paradigmxyz/reth.git", rev = "f211aac", features = [
"optimism",
] }
reth-primitives-traits = { git = "https://github.com/paradigmxyz/reth.git", rev = "f211aac" }
reth-provider = { git = "https://github.com/paradigmxyz/reth.git", rev = "f211aac", features = [
"optimism",
] }
Expand Down
4 changes: 3 additions & 1 deletion crates/e2e-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ categories.workspace = true
[dev-dependencies]
odyssey-common.workspace = true

reth-primitives-traits.workspace = true
reth-trie-common.workspace = true

alloy.workspace = true
alloy-network.workspace = true
alloy-rpc-types.workspace = true
Expand All @@ -20,7 +23,6 @@ alloy-signer-local.workspace = true
tokio.workspace = true
url = "2.5.0"
ci_info = "0.14.14"
serde.workspace = true

[lints]
workspace = true
65 changes: 37 additions & 28 deletions crates/e2e-tests/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ use alloy::{
signers::SignerSync,
};
use alloy_network::{TransactionBuilder, TransactionBuilder7702};
use alloy_rpc_types::{BlockNumberOrTag, EIP1186AccountProofResponse, TransactionRequest};
use alloy_rpc_types::{Block, BlockNumberOrTag, EIP1186AccountProofResponse, TransactionRequest};
use alloy_signer_local::PrivateKeySigner;
use reth_primitives_traits::Account;
use reth_trie_common::{AccountProof, StorageProof};
use url::Url;

static REPLICA_RPC: LazyLock<Url> = LazyLock::new(|| {
Expand Down Expand Up @@ -130,51 +132,58 @@ async fn test_new_wallet_api() -> Result<(), Box<dyn std::error::Error>> {

#[tokio::test]
async fn test_withdrawal_proof_with_fallback() -> Result<(), Box<dyn std::error::Error>> {
if !ci_info::is_ci() {
return Ok(());
}

#[derive(Debug, Clone, serde::Serialize)]
struct ProofParams {
address: Address,
keys: Vec<B256>,
block: BlockNumberOrTag,
}
// if !ci_info::is_ci() {
// return Ok(());
// }

let provider = ProviderBuilder::new().on_http(REPLICA_RPC.clone());
let signer = PrivateKeySigner::from_bytes(&b256!(
"59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d"
))?;
let block: Block = provider
.client()
.request("eth_getBlockByNumber", (BlockNumberOrTag::Latest, false))
.await?;
let block_number = BlockNumberOrTag::Number(block.header.number);

// Withdrawal contract will return an empty account proof, since it only handles storage proofs
let withdrawal_contract_response: EIP1186AccountProofResponse = provider
.client()
.request(
"eth_getProof",
ProofParams {
address: odyssey_common::WITHDRAWAL_CONTRACT,
keys: vec![B256::ZERO],
block: BlockNumberOrTag::Latest,
},
(odyssey_common::WITHDRAWAL_CONTRACT, vec![B256::ZERO], block_number),
)
.await?;

assert!(withdrawal_contract_response.account_proof.is_empty());
assert!(!withdrawal_contract_response.storage_proof.is_empty());

let storage_root = withdrawal_contract_response.storage_hash;
for proof in withdrawal_contract_response.storage_proof {
StorageProof::new(proof.key.as_b256()).with_proof(proof.proof).verify(storage_root)?
}

// If not targeting the withdrawal contract, it defaults back to the standard getProof
// implementation
let signer = PrivateKeySigner::from_bytes(&b256!(
"59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d"
))?;

let eoa_response: EIP1186AccountProofResponse = provider
.client()
.request(
"eth_getProof",
ProofParams {
address: signer.address(),
keys: vec![],
block: BlockNumberOrTag::Latest,
},
)
.await?;
.request("eth_getProof", (signer.address(), [0; 0], block_number))
.await
.unwrap();

assert!(!eoa_response.account_proof.is_empty());
AccountProof {
address: signer.address(),
info: Some(Account {
nonce: eoa_response.nonce,
balance: eoa_response.balance,
bytecode_hash: None,
}),
proof: eoa_response.account_proof,
..Default::default()
}
.verify(block.header.state_root)?;

Ok(())
}

0 comments on commit 9027de2

Please sign in to comment.