feat: update el requests for devnet 4 (#11865)

Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
Oliver
2024-10-19 14:48:35 +02:00
committed by GitHub
parent 2ae93682b4
commit 3bd695ee63
106 changed files with 799 additions and 1328 deletions

View File

@ -4,8 +4,9 @@ use crate::{
dao_fork::{DAO_HARDFORK_BENEFICIARY, DAO_HARDKFORK_ACCOUNTS},
EthEvmConfig,
};
use alloc::{boxed::Box, sync::Arc, vec, vec::Vec};
use alloc::{boxed::Box, sync::Arc, vec::Vec};
use alloy_consensus::Transaction as _;
use alloy_eips::eip7685::Requests;
use alloy_primitives::{BlockNumber, U256};
use core::fmt::Display;
use reth_chainspec::{ChainSpec, EthereumHardforks, MAINNET};
@ -19,7 +20,7 @@ use reth_evm::{
ConfigureEvm,
};
use reth_execution_types::ExecutionOutcome;
use reth_primitives::{BlockWithSenders, EthereumHardfork, Header, Receipt, Request};
use reth_primitives::{BlockWithSenders, EthereumHardfork, Header, Receipt};
use reth_prune_types::PruneModes;
use reth_revm::{
batch::BlockBatchRecord,
@ -104,7 +105,7 @@ where
#[derive(Debug, Clone)]
struct EthExecuteOutput {
receipts: Vec<Receipt>,
requests: Vec<Request>,
requests: Requests,
gas_used: u64,
}
@ -122,7 +123,7 @@ where
EvmConfig: ConfigureEvm<Header = Header>,
{
/// Executes the transactions in the block and returns the receipts of the transactions in the
/// block, the total gas used and the list of EIP-7685 [requests](Request).
/// block, the total gas used and the list of EIP-7685 [requests](Requests).
///
/// This applies the pre-execution and post-execution changes that require an [EVM](Evm), and
/// executes the transactions.
@ -205,11 +206,11 @@ where
let deposit_requests =
crate::eip6110::parse_deposits_from_receipts(&self.chain_spec, &receipts)?;
let post_execution_requests = system_caller.apply_post_execution_changes(&mut evm)?;
[deposit_requests, post_execution_requests].concat()
let mut requests = Requests::new(vec![deposit_requests]);
requests.extend(system_caller.apply_post_execution_changes(&mut evm)?);
requests
} else {
vec![]
Requests::default()
};
Ok(EthExecuteOutput { receipts, requests, gas_used: cumulative_gas_used })
@ -283,7 +284,7 @@ where
/// Execute a single block and apply the state changes to the internal state.
///
/// Returns the receipts of the transactions in the block, the total gas used and the list of
/// EIP-7685 [requests](Request).
/// EIP-7685 [requests](Requests).
///
/// Returns an error if execution fails.
fn execute_without_verification_with_state_hook<F>(
@ -494,11 +495,12 @@ where
#[cfg(test)]
mod tests {
use super::*;
use alloy_consensus::{TxLegacy, EMPTY_ROOT_HASH};
use alloy_consensus::TxLegacy;
use alloy_eips::{
eip2935::{HISTORY_STORAGE_ADDRESS, HISTORY_STORAGE_CODE},
eip4788::{BEACON_ROOTS_ADDRESS, BEACON_ROOTS_CODE, SYSTEM_ADDRESS},
eip7002::{WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS, WITHDRAWAL_REQUEST_PREDEPLOY_CODE},
eip7685::EMPTY_REQUESTS_HASH,
};
use alloy_primitives::{b256, fixed_bytes, keccak256, Bytes, TxKind, B256};
use reth_chainspec::{ChainSpecBuilder, ForkCondition};
@ -583,7 +585,6 @@ mod tests {
transactions: vec![],
ommers: vec![],
withdrawals: None,
requests: None,
},
},
senders: vec![],
@ -612,12 +613,7 @@ mod tests {
&BlockWithSenders {
block: Block {
header: header.clone(),
body: BlockBody {
transactions: vec![],
ommers: vec![],
withdrawals: None,
requests: None,
},
body: BlockBody { transactions: vec![], ommers: vec![], withdrawals: None },
},
senders: vec![],
},
@ -684,7 +680,6 @@ mod tests {
transactions: vec![],
ommers: vec![],
withdrawals: None,
requests: None,
},
},
senders: vec![],
@ -739,7 +734,6 @@ mod tests {
transactions: vec![],
ommers: vec![],
withdrawals: None,
requests: None,
},
},
senders: vec![],
@ -1016,7 +1010,7 @@ mod tests {
parent_hash: B256::random(),
timestamp: 1,
number: fork_activation_block,
requests_root: Some(EMPTY_ROOT_HASH),
requests_hash: Some(EMPTY_REQUESTS_HASH),
..Header::default()
};
let provider = executor_provider(chain_spec);
@ -1075,7 +1069,7 @@ mod tests {
parent_hash: B256::random(),
timestamp: 1,
number: fork_activation_block,
requests_root: Some(EMPTY_ROOT_HASH),
requests_hash: Some(EMPTY_REQUESTS_HASH),
..Header::default()
};
@ -1121,7 +1115,7 @@ mod tests {
);
let mut header = chain_spec.genesis_header().clone();
header.requests_root = Some(EMPTY_ROOT_HASH);
header.requests_hash = Some(EMPTY_REQUESTS_HASH);
let header_hash = header.hash_slow();
let provider = executor_provider(chain_spec);
@ -1159,7 +1153,7 @@ mod tests {
parent_hash: header_hash,
timestamp: 1,
number: 1,
requests_root: Some(EMPTY_ROOT_HASH),
requests_hash: Some(EMPTY_REQUESTS_HASH),
..Header::default()
};
let header_hash = header.hash_slow();
@ -1196,7 +1190,7 @@ mod tests {
parent_hash: header_hash,
timestamp: 1,
number: 2,
requests_root: Some(EMPTY_ROOT_HASH),
requests_hash: Some(EMPTY_REQUESTS_HASH),
..Header::default()
};
@ -1254,15 +1248,16 @@ mod tests {
HashMap::default(),
);
// https://github.com/lightclient/7002asm/blob/e0d68e04d15f25057af7b6d180423d94b6b3bdb3/test/Contract.t.sol.in#L49-L64
// https://github.com/lightclient/sys-asm/blob/9282bdb9fd64e024e27f60f507486ffb2183cba2/test/Withdrawal.t.sol.in#L36
let validator_public_key = fixed_bytes!("111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111");
let withdrawal_amount = fixed_bytes!("2222222222222222");
let withdrawal_amount = fixed_bytes!("0203040506070809");
let input: Bytes = [&validator_public_key[..], &withdrawal_amount[..]].concat().into();
assert_eq!(input.len(), 56);
let mut header = chain_spec.genesis_header().clone();
header.gas_limit = 1_500_000;
header.gas_used = 134_807;
// measured
header.gas_used = 135_856;
header.receipts_root =
b256!("b31a3e47b902e9211c4d349af4e4c5604ce388471e79ca008907ae4616bb0ed3");
@ -1272,10 +1267,10 @@ mod tests {
chain_id: Some(chain_spec.chain.id()),
nonce: 1,
gas_price: header.base_fee_per_gas.unwrap().into(),
gas_limit: 134_807,
gas_limit: header.gas_used,
to: TxKind::Call(WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS),
// `MIN_WITHDRAWAL_REQUEST_FEE`
value: U256::from(1),
value: U256::from(2),
input,
}),
);
@ -1302,11 +1297,9 @@ mod tests {
let receipt = receipts.first().unwrap();
assert!(receipt.success);
let request = requests.first().unwrap();
let withdrawal_request = request.as_withdrawal_request().unwrap();
assert_eq!(withdrawal_request.source_address, sender_address);
assert_eq!(withdrawal_request.validator_pubkey, validator_public_key);
assert_eq!(withdrawal_request.amount, u64::from_be_bytes(withdrawal_amount.into()));
assert!(requests[0].is_empty(), "there should be no deposits");
assert!(!requests[1].is_empty(), "there should be a withdrawal");
assert!(requests[2].is_empty(), "there should be no consolidations");
}
#[test]