Skip to content

Commit 4c64af4

Browse files
authored
fix(l1): added error for case where system contract code is empty (#4731)
**Description** This PR adds a check for the case where a system contract code is empty. This is required to pass a few Hive tests recently added that ask to return an error in such a case.
1 parent f6ccc00 commit 4c64af4

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

crates/vm/backends/levm/mod.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ mod tracing;
44
use super::BlockExecutionResult;
55
use crate::system_contracts::{
66
BEACON_ROOTS_ADDRESS, CONSOLIDATION_REQUEST_PREDEPLOY_ADDRESS, HISTORY_STORAGE_ADDRESS,
7-
SYSTEM_ADDRESS, WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS,
7+
PRAGUE_SYSTEM_CONTRACTS, SYSTEM_ADDRESS, WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS,
88
};
99
use crate::{EvmError, ExecutionResult};
1010
use bytes::Bytes;
@@ -381,6 +381,21 @@ pub fn generic_system_contract_levm(
381381
..Default::default()
382382
};
383383

384+
// This check is not necessary in practice, since contract deployment has succesfully happened in all relevant testnets and mainnet
385+
// However, it's necessary to pass some of the Hive tests related to system contract deployment, which is why we have it
386+
// The error that should be returned for the relevant contracts is indicated in the following:
387+
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-7002.md#empty-code-failure
388+
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-7251.md#empty-code-failure
389+
if PRAGUE_SYSTEM_CONTRACTS
390+
.iter()
391+
.any(|contract| contract.address == contract_address)
392+
&& db.get_account_code(contract_address)?.is_empty()
393+
{
394+
return Err(EvmError::SystemContractCallFailed(format!(
395+
"System contract: {contract_address} has no code after deployment"
396+
)));
397+
};
398+
384399
let tx = &Transaction::EIP1559Transaction(EIP1559Transaction {
385400
to: TxKind::Call(contract_address),
386401
value: U256::zero(),

crates/vm/system_contracts.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,8 @@ pub fn system_contracts_for_fork(fork: Fork) -> impl Iterator<Item = SystemContr
6969
.into_iter()
7070
.filter(move |system_contract| system_contract.active_since_fork <= fork)
7171
}
72+
73+
pub const PRAGUE_SYSTEM_CONTRACTS: [SystemContract; 2] = [
74+
WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS,
75+
CONSOLIDATION_REQUEST_PREDEPLOY_ADDRESS,
76+
];

0 commit comments

Comments
 (0)