Skip to content

Commit 0ce3c96

Browse files
authored
Merge d9d8896 into 83bbccd
2 parents 83bbccd + d9d8896 commit 0ce3c96

61 files changed

Lines changed: 4490 additions & 268 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.lock

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ ee-tests = { path = "crates/ee-tests", package = "revm-ee-tests", version = "0.1
6060
# alloy
6161
alloy-eip2930 = { version = "0.2.1", default-features = false }
6262
alloy-eip7702 = { version = "0.6.1", default-features = false }
63+
alloy-eip7928 = { version = "0.1.0", default-features = false, git = "https://github.com/alloy-rs/eips.git" }
6364
alloy-primitives = { version = "1.3.1", default-features = false }
6465

6566
# alloy in examples, revme or feature flagged.

bins/revme/src/cmd/blockchaintest.rs

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ use revm::{
77
bytecode::Bytecode,
88
context::{cfg::CfgEnv, ContextTr},
99
context_interface::{block::BlobExcessGasAndPrice, result::HaltReason},
10-
database::{states::bundle_state::BundleRetention, EmptyDB, State},
10+
database::{bal::BalDatabase, states::bundle_state::BundleRetention, EmptyDB, State},
1111
handler::EvmTr,
1212
inspector::inspectors::TracerEip3155,
1313
primitives::{hardfork::SpecId, hex, Address, HashMap, U256},
14-
state::AccountInfo,
14+
state::{bal::Bal, AccountInfo},
1515
Context, Database, ExecuteCommitEvm, ExecuteEvm, InspectEvm, MainBuilder, MainContext,
1616
};
1717
use serde_json::json;
@@ -21,6 +21,7 @@ use statetest_types::blockchain::{
2121
use std::collections::BTreeMap;
2222
use std::fs;
2323
use std::path::{Path, PathBuf};
24+
use std::sync::Arc;
2425
use std::time::Instant;
2526
use thiserror::Error;
2627
use walkdir::{DirEntry, WalkDir};
@@ -646,7 +647,7 @@ fn execute_blockchain_test(
646647
}
647648

648649
// Create database with initial state
649-
let mut state = State::builder().build();
650+
let mut state = BalDatabase::new(State::builder().build());
650651

651652
// Capture pre-state for debug info
652653
let mut pre_state_debug = HashMap::new();
@@ -659,6 +660,7 @@ fn execute_blockchain_test(
659660
nonce: account.nonce,
660661
code_hash: revm::primitives::keccak256(&account.code),
661662
code: Some(Bytecode::new_raw(account.code.clone())),
663+
storage_id: None,
662664
};
663665

664666
// Store for debug info
@@ -715,6 +717,14 @@ fn execute_blockchain_test(
715717
this_excess_blob_gas = None;
716718
}
717719

720+
let bal_test = block
721+
.block_access_list
722+
.as_ref()
723+
.and_then(|bal| Bal::try_from(bal.clone()).ok())
724+
.map(Arc::new);
725+
726+
state = state.with_bal_option(bal_test).reset_bal_index();
727+
718728
// Create EVM context for each transaction to ensure fresh state access
719729
let evm_context = Context::mainnet()
720730
.with_block(&block_env)
@@ -800,6 +810,9 @@ fn execute_blockchain_test(
800810
}
801811
};
802812

813+
// bump bal index
814+
evm.db_mut().bump_bal_index();
815+
803816
// If JSON output requested, output transaction details
804817
let execution_result = if json_output {
805818
evm.inspect_tx(tx_env.clone())
@@ -909,6 +922,9 @@ fn execute_blockchain_test(
909922
}
910923
}
911924

925+
// bump bal index
926+
evm.db_mut().bump_bal_index();
927+
912928
// uncle rewards are not implemented yet
913929
post_block::post_block_transition(
914930
&mut evm,
@@ -922,6 +938,19 @@ fn execute_blockchain_test(
922938
.block_hashes
923939
.insert(block_env.number.to::<u64>(), block_hash.unwrap_or_default());
924940

941+
if let Some(bal) = state.bal_state.bal_builder.take() {
942+
if let Some(state_bal) = state.bal_state.bal.as_ref() {
943+
if &bal != state_bal.as_ref() {
944+
println!("Bal mismatch");
945+
println!("Test bal");
946+
state_bal.pretty_print();
947+
println!("Bal:");
948+
bal.pretty_print();
949+
return Err(TestExecutionError::BalMismatchError);
950+
}
951+
}
952+
}
953+
925954
parent_block_hash = block_hash;
926955
if let Some(excess_blob_gas) = this_excess_blob_gas {
927956
parent_excess_blob_gas = excess_blob_gas;
@@ -975,7 +1004,8 @@ fn fork_to_spec_id(fork: ForkSpec) -> SpecId {
9751004
ForkSpec::Cancun | ForkSpec::ShanghaiToCancunAtTime15k => SpecId::CANCUN,
9761005
ForkSpec::Prague | ForkSpec::CancunToPragueAtTime15k => SpecId::PRAGUE,
9771006
ForkSpec::Osaka | ForkSpec::PragueToOsakaAtTime15k => SpecId::OSAKA,
978-
_ => SpecId::OSAKA, // For any unknown forks, use latest available
1007+
ForkSpec::Amsterdam => SpecId::AMSTERDAM,
1008+
_ => SpecId::AMSTERDAM, // For any unknown forks, use latest available
9791009
}
9801010
}
9811011

@@ -1080,6 +1110,9 @@ pub enum TestExecutionError {
10801110
gas_used: u64,
10811111
},
10821112

1113+
#[error("BAL error")]
1114+
BalMismatchError,
1115+
10831116
#[error(
10841117
"Post-state validation failed for {address:?}.{field}: expected {expected}, got {actual}"
10851118
)]
Lines changed: 59 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
use revm::{
2-
context::{Block, ContextTr},
3-
database::State,
2+
context::{Block, ContextTr, JournalTr},
3+
database::{Database, DatabaseCommit},
44
handler::EvmTr,
5-
primitives::{hardfork::SpecId, ONE_ETHER, ONE_GWEI},
6-
Database, SystemCallCommitEvm,
5+
primitives::{address, hardfork::SpecId, Address, Bytes, ONE_ETHER, ONE_GWEI, U256},
6+
SystemCallCommitEvm,
77
};
88
use statetest_types::blockchain::Withdrawal;
99

1010
/// Post block transition that includes:
1111
/// * Block and uncle rewards before the Merge/Paris hardfork.
12-
/// * system calls
12+
/// * Withdrawals (EIP-4895)
13+
/// * Post-block system calls: EIP-7002 (withdrawal requests) and EIP-7251 (consolidation requests)
1314
///
1415
/// # Note
1516
///
1617
/// Uncle rewards are not implemented yet.
1718
#[inline]
1819
pub fn post_block_transition<
1920
'a,
20-
DB: Database + 'a,
21-
EVM: SystemCallCommitEvm<Error: core::fmt::Debug>
22-
+ EvmTr<Context: ContextTr<Db = &'a mut State<DB>>>,
21+
DB: Database + DatabaseCommit + 'a,
22+
EVM: SystemCallCommitEvm<Error: core::fmt::Debug> + EvmTr<Context: ContextTr<Db = DB>>,
2323
>(
2424
evm: &mut EVM,
2525
block: impl Block,
@@ -29,24 +29,36 @@ pub fn post_block_transition<
2929
// block reward
3030
let block_reward = block_reward(spec, 0);
3131
if block_reward != 0 {
32-
let _ = evm
33-
.ctx_mut()
34-
.db_mut()
35-
.increment_balances(vec![(block.beneficiary(), block_reward)]);
32+
evm.ctx_mut()
33+
.journal_mut()
34+
.balance_incr(block.beneficiary(), U256::from(block_reward))
35+
.expect("Db actions to pass");
3636
}
3737

3838
// withdrawals
3939
if spec.is_enabled_in(SpecId::SHANGHAI) {
4040
for withdrawal in withdrawals {
4141
evm.ctx_mut()
42-
.db_mut()
43-
.increment_balances(vec![(
42+
.journal_mut()
43+
.balance_incr(
4444
withdrawal.address,
45-
withdrawal.amount.to::<u128>().saturating_mul(ONE_GWEI),
46-
)])
45+
withdrawal.amount.saturating_mul(U256::from(ONE_GWEI)),
46+
)
4747
.expect("Db actions to pass");
4848
}
4949
}
50+
51+
evm.commit_inner();
52+
53+
// EIP-7002: Withdrawal requests system call
54+
if spec.is_enabled_in(SpecId::PRAGUE) {
55+
system_call_eip7002_withdrawal_request(evm);
56+
}
57+
58+
// EIP-7251: Consolidation requests system call
59+
if spec.is_enabled_in(SpecId::PRAGUE) {
60+
system_call_eip7251_consolidation_request(evm);
61+
}
5062
}
5163

5264
/// Block reward for a block.
@@ -66,3 +78,34 @@ pub const fn block_reward(spec: SpecId, ommers: usize) -> u128 {
6678

6779
reward + (reward >> 5) * ommers as u128
6880
}
81+
82+
pub const WITHDRAWAL_REQUEST_ADDRESS: Address =
83+
address!("0x00000961Ef480Eb55e80D19ad83579A64c007002");
84+
85+
/// EIP-7002: Withdrawal requests system call
86+
pub(crate) fn system_call_eip7002_withdrawal_request(
87+
evm: &mut impl SystemCallCommitEvm<Error: core::fmt::Debug>,
88+
) {
89+
// empty data is valid for EIP-7002
90+
let _ = match evm.system_call_commit(WITHDRAWAL_REQUEST_ADDRESS, Bytes::new()) {
91+
Ok(res) => res,
92+
Err(e) => {
93+
panic!("System call failed: {e:?}");
94+
}
95+
};
96+
}
97+
98+
pub const CONSOLIDATION_REQUEST_ADDRESS: Address =
99+
address!("0x0000BBdDc7CE488642fb579F8B00f3a590007251");
100+
101+
/// EIP-7251: Consolidation requests system call
102+
pub(crate) fn system_call_eip7251_consolidation_request(
103+
evm: &mut impl SystemCallCommitEvm<Error: core::fmt::Debug>,
104+
) {
105+
let _ = match evm.system_call_commit(CONSOLIDATION_REQUEST_ADDRESS, Bytes::new()) {
106+
Ok(res) => res,
107+
Err(e) => {
108+
panic!("System call failed: {e:?}");
109+
}
110+
};
111+
}

bins/revme/src/cmd/blockchaintest/pre_block.rs

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,21 @@
22
33
use revm::{
44
context::{Block, ContextTr},
5-
database::{Database, State},
5+
database::Database,
66
handler::EvmTr,
77
primitives::{address, hardfork::SpecId, Address, B256},
8-
SystemCallCommitEvm,
8+
DatabaseCommit, SystemCallCommitEvm,
99
};
1010

1111
/// Pre block state transition
1212
///
1313
/// # Note
1414
///
15-
/// Contains only withdrawal processing. And it is missing block hash system call.
15+
/// Contains pre-block system calls: EIP-2935 (blockhash) and EIP-4788 (beacon root).
1616
pub fn pre_block_transition<
1717
'a,
18-
DB: Database + 'a,
19-
EVM: SystemCallCommitEvm<Error: core::fmt::Debug>
20-
+ EvmTr<Context: ContextTr<Db = &'a mut State<DB>>>,
18+
DB: Database + DatabaseCommit + 'a,
19+
EVM: SystemCallCommitEvm<Error: core::fmt::Debug> + EvmTr<Context: ContextTr<Db = DB>>,
2120
>(
2221
evm: &mut EVM,
2322
spec: SpecId,
@@ -31,11 +30,15 @@ pub fn pre_block_transition<
3130

3231
// blockhash system call
3332
if let Some(parent_block_hash) = parent_block_hash {
34-
system_call_eip2935_blockhash(spec, parent_block_hash, evm);
33+
if spec.is_enabled_in(SpecId::PRAGUE) {
34+
system_call_eip2935_blockhash(evm, parent_block_hash);
35+
}
3536
}
3637

3738
if let Some(parent_beacon_block_root) = parent_beacon_block_root {
38-
system_call_eip4788_beacon_root(spec, parent_beacon_block_root, evm);
39+
if spec.is_enabled_in(SpecId::CANCUN) {
40+
system_call_eip4788_beacon_root(evm, parent_beacon_block_root);
41+
}
3942
}
4043
}
4144

@@ -44,42 +47,28 @@ pub const HISTORY_STORAGE_ADDRESS: Address = address!("0x0000F90827F1C53a10cb7A0
4447
/// Blockhash system callEIP-2935
4548
#[inline]
4649
pub(crate) fn system_call_eip2935_blockhash(
47-
spec: SpecId,
48-
parent_block_hash: B256,
4950
evm: &mut impl SystemCallCommitEvm<Error: core::fmt::Debug>,
50-
) -> bool {
51-
if !spec.is_enabled_in(SpecId::PRAGUE) {
52-
return true;
53-
}
54-
51+
parent_block_hash: B256,
52+
) {
5553
let _ = match evm.system_call_commit(HISTORY_STORAGE_ADDRESS, parent_block_hash.0.into()) {
5654
Ok(res) => res,
5755
Err(e) => {
5856
panic!("System call failed: {e:?}");
5957
}
6058
};
61-
62-
true
6359
}
6460

6561
pub const BEACON_ROOTS_ADDRESS: Address = address!("000F3df6D732807Ef1319fB7B8bB8522d0Beac02");
6662

6763
/// Beacon root system call EIP-4788
6864
pub(crate) fn system_call_eip4788_beacon_root(
69-
spec: SpecId,
70-
parent_beacon_block_root: B256,
7165
evm: &mut impl SystemCallCommitEvm<Error: core::fmt::Debug>,
72-
) -> bool {
73-
if !spec.is_enabled_in(SpecId::CANCUN) {
74-
return true;
75-
}
76-
66+
parent_beacon_block_root: B256,
67+
) {
7768
let _ = match evm.system_call_commit(BEACON_ROOTS_ADDRESS, parent_beacon_block_root.0.into()) {
7869
Ok(res) => res,
7970
Err(e) => {
8071
panic!("System call failed: {e:?}");
8172
}
8273
};
83-
84-
true
8574
}

bins/revme/src/cmd/statetest/runner.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ use revm::{
99
database,
1010
database_interface::EmptyDB,
1111
inspector::{inspectors::TracerEip3155, InspectCommitEvm},
12-
primitives::U256,
13-
primitives::{hardfork::SpecId, Bytes, B256},
12+
primitives::{hardfork::SpecId, Bytes, B256, U256},
1413
Context, ExecuteCommitEvm, MainBuilder, MainContext,
1514
};
1615
use serde_json::json;
@@ -438,6 +437,7 @@ fn execute_single_test(ctx: TestExecutionContext) -> Result<(), TestErrorKind> {
438437
};
439438
*ctx.elapsed.lock().unwrap() += timer.elapsed();
440439

440+
let exec_result = exec_result.map_err(|b| b.map_db_err(|db| db.into_db_error()));
441441
// Check results
442442
check_evm_execution(
443443
ctx.test,

0 commit comments

Comments
 (0)