diff --git a/client/src/node.rs b/client/src/node.rs index e6141eb..3bd38f7 100644 --- a/client/src/node.rs +++ b/client/src/node.rs @@ -113,7 +113,8 @@ impl Node { pub async fn get_code(&self, address: &Address, block: &BlockTag) -> Result> { let payload = self.get_payload(block)?; - self.execution.get_code(&address, payload).await + let account = self.execution.get_account(&address, None, payload).await?; + Ok(account.code) } pub async fn get_storage_at(&self, address: &Address, slot: H256) -> Result { diff --git a/execution/src/evm.rs b/execution/src/evm.rs index a282943..311ba2c 100644 --- a/execution/src/evm.rs +++ b/execution/src/evm.rs @@ -4,6 +4,7 @@ use bytes::Bytes; use ethers::{ abi::ethereum_types::BigEndianHash, prelude::{Address, H160, H256, U256}, + types::transaction::eip2930::AccessListItem, }; use eyre::Result; use futures::future::join_all; @@ -87,9 +88,28 @@ impl Evm { let handle = thread::spawn(move || { let list_fut = rpc.create_access_list(&opts_moved, block_moved); let runtime = Runtime::new()?; - let list = runtime.block_on(list_fut)?; + let mut list = runtime.block_on(list_fut)?.0; - let account_futs = list.0.iter().map(|account| { + let from_access_entry = AccessListItem { + address: opts_moved.from.unwrap_or_default(), + storage_keys: Vec::default(), + }; + + let to_access_entry = AccessListItem { + address: opts_moved.to, + storage_keys: Vec::default(), + }; + + let producer_account = AccessListItem { + address: Address::from_slice(&payload.fee_recipient), + storage_keys: Vec::default(), + }; + + list.push(from_access_entry); + list.push(to_access_entry); + list.push(producer_account); + + let account_futs = list.iter().map(|account| { let addr_fut = futures::future::ready(account.address); let account_fut = execution.get_account( &account.address, diff --git a/execution/src/execution.rs b/execution/src/execution.rs index 5713a01..3741e98 100644 --- a/execution/src/execution.rs +++ b/execution/src/execution.rs @@ -10,6 +10,7 @@ use eyre::Result; use common::utils::hex_str_to_bytes; use consensus::types::ExecutionPayload; +use revm::KECCAK_EMPTY; use triehash_ethereum::ordered_trie_root; use super::proof::{encode_account, verify_proof}; @@ -76,12 +77,18 @@ impl ExecutionClient { slot_map.insert(storage_proof.key, storage_proof.value); } - let code = self.rpc.get_code(address, payload.block_number).await?; - let code_hash = keccak256(&code).into(); + let code = if proof.code_hash == KECCAK_EMPTY { + Vec::new() + } else { + let code = self.rpc.get_code(address, payload.block_number).await?; + let code_hash = keccak256(&code).into(); - if proof.code_hash != code_hash { - eyre::bail!("Invalid Proof"); - } + if proof.code_hash != code_hash { + eyre::bail!("Invalid Proof"); + } + + code + }; Ok(Account { balance: proof.balance, @@ -93,19 +100,6 @@ impl ExecutionClient { }) } - pub async fn get_code(&self, address: &Address, payload: &ExecutionPayload) -> Result> { - let account = self.get_account(address, None, payload).await?; - let code = self.rpc.get_code(address, payload.block_number).await?; - - let code_hash = keccak256(&code).into(); - - if account.code_hash != code_hash { - eyre::bail!("Invalid Proof"); - } - - Ok(code) - } - pub async fn send_raw_transaction(&self, bytes: &Vec) -> Result { self.rpc.send_raw_transaction(bytes).await } diff --git a/execution/tests/execution.rs b/execution/tests/execution.rs index 3e3d3c0..0409146 100644 --- a/execution/tests/execution.rs +++ b/execution/tests/execution.rs @@ -47,39 +47,6 @@ async fn test_get_account_bad_proof() { assert!(account_res.is_err()); } -#[tokio::test] -async fn test_get_code() { - let execution = get_client(); - let address = Address::from_str("14f9D4aF749609c1438528C0Cce1cC3f6D411c47").unwrap(); - - let mut payload = ExecutionPayload::default(); - payload.state_root = Vector::from_iter( - hex_str_to_bytes("0xaa02f5db2ee75e3da400d10f3c30e894b6016ce8a2501680380a907b6674ce0d") - .unwrap(), - ); - - let code = execution.get_code(&address, &payload).await.unwrap(); - let code_hash = keccak256(code); - - assert_eq!( - code_hash.as_slice(), - &hex_str_to_bytes("0xc6ca0679d7242fa080596f2fe2e6b172d9b927a6b52278343826e33745854327") - .unwrap() - ); -} - -#[tokio::test] -async fn test_get_code_bad_proof() { - let execution = get_client(); - let address = Address::from_str("14f9D4aF749609c1438528C0Cce1cC3f6D411c47").unwrap(); - - let payload = ExecutionPayload::default(); - - let code_res = execution.get_code(&address, &payload).await; - - assert!(code_res.is_err()); -} - #[tokio::test] async fn test_get_tx() { let execution = get_client();