Skip to content

chore(l1): fix contract deployment tests from EIP-7002 #2630

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions cmd/ef_tests/blockchain/tests/prague.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,11 @@ const SKIPPED_TESTS_REVM: [&str; 13] = [
];

#[cfg(feature = "levm")]
const SKIPPED_TESTS_LEVM: [&str; 46] = [
"tests/prague/eip7002_el_triggerable_withdrawals/test_contract_deployment.py::test_system_contract_deployment[fork_CancunToPragueAtTime15k-blockchain_test-deploy_after_fork-nonzero_balance]",
"tests/prague/eip7002_el_triggerable_withdrawals/test_contract_deployment.py::test_system_contract_deployment[fork_CancunToPragueAtTime15k-blockchain_test-deploy_after_fork-zero_balance]",
const SKIPPED_TESTS_LEVM: [&str; 42] = [
"tests/prague/eip7002_el_triggerable_withdrawals/test_modified_withdrawal_contract.py::test_system_contract_errors[fork_Prague-blockchain_test-system_contract_out_of_gas-system_contract_0x00000961ef480eb55e80d19ad83579a64c007002]",
"tests/prague/eip7002_el_triggerable_withdrawals/test_modified_withdrawal_contract.py::test_system_contract_errors[fork_Prague-blockchain_test-system_contract_reverts-system_contract_0x00000961ef480eb55e80d19ad83579a64c007002]",
"tests/prague/eip7002_el_triggerable_withdrawals/test_modified_withdrawal_contract.py::test_system_contract_errors[fork_Prague-blockchain_test-system_contract_reaches_gas_limit-system_contract_0x00000961ef480eb55e80d19ad83579a64c007002]",
"tests/prague/eip7002_el_triggerable_withdrawals/test_modified_withdrawal_contract.py::test_system_contract_errors[fork_Prague-blockchain_test-system_contract_throws-system_contract_0x00000961ef480eb55e80d19ad83579a64c007002]",
"tests/prague/eip7251_consolidations/test_contract_deployment.py::test_system_contract_deployment[fork_CancunToPragueAtTime15k-blockchain_test-deploy_after_fork-zero_balance]",
"tests/prague/eip7251_consolidations/test_contract_deployment.py::test_system_contract_deployment[fork_CancunToPragueAtTime15k-blockchain_test-deploy_after_fork-nonzero_balance]",
"tests/prague/eip7251_consolidations/test_modified_consolidation_contract.py::test_system_contract_errors[fork_Prague-blockchain_test-system_contract_reaches_gas_limit-system_contract_0x0000bbddc7ce488642fb579f8b00f3a590007251]",
"tests/prague/eip7251_consolidations/test_modified_consolidation_contract.py::test_system_contract_errors[fork_Prague-blockchain_test-system_contract_out_of_gas-system_contract_0x0000bbddc7ce488642fb579f8b00f3a590007251]",
"tests/prague/eip7251_consolidations/test_modified_consolidation_contract.py::test_system_contract_errors[fork_Prague-blockchain_test-system_contract_throws-system_contract_0x0000bbddc7ce488642fb579f8b00f3a590007251]",
Expand Down
51 changes: 35 additions & 16 deletions crates/vm/backends/levm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use ethrex_common::{
},
Address, H256, U256,
};
use ethrex_levm::constants::EMPTY_CODE_HASH;
use ethrex_levm::db::gen_db::GeneralizedDatabase;
use ethrex_levm::{
errors::{ExecutionReport, TxResult, VMError},
Expand Down Expand Up @@ -312,37 +313,51 @@ impl LEVM {
pub(crate) fn read_withdrawal_requests(
block_header: &BlockHeader,
db: &mut GeneralizedDatabase,
) -> Option<ExecutionReport> {
) -> Result<Option<ExecutionReport>, EvmError> {
let report = generic_system_contract_levm(
block_header,
Bytes::new(),
db,
*WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS,
*SYSTEM_ADDRESS,
)
.ok()?;
)?;

// According to EIP-7002 we need to check if the WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS
// has any code after being deployed. If not, the whole block becomes invalid.
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-7002.md
let account = db.get_account(*WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS)?;
if code_hash(&account.info.bytecode) == EMPTY_CODE_HASH {
return Err(EvmError::Custom("BlockException.SYSTEM_CONTRACT_EMPTY: WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS has no code after deployment".to_string()));
}

match report.result {
TxResult::Success => Some(report),
_ => None,
TxResult::Success => Ok(Some(report)),
_ => Ok(None),
}
}
pub(crate) fn dequeue_consolidation_requests(
block_header: &BlockHeader,
db: &mut GeneralizedDatabase,
) -> Option<ExecutionReport> {
) -> Result<Option<ExecutionReport>, EvmError> {
let report = generic_system_contract_levm(
block_header,
Bytes::new(),
db,
*CONSOLIDATION_REQUEST_PREDEPLOY_ADDRESS,
*SYSTEM_ADDRESS,
)
.ok()?;
)?;

// According to EIP-7251 we need to check if the CONSOLIDATION_REQUEST_PREDEPLOY_ADDRESS
// has any code after being deployed. If not, the whole block becomes invalid.
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-7251.md
let acc = db.get_account(*CONSOLIDATION_REQUEST_PREDEPLOY_ADDRESS)?;
if code_hash(&acc.info.bytecode) == EMPTY_CODE_HASH {
return Err(EvmError::Custom("BlockException.SYSTEM_CONTRACT_EMPTY: CONSOLIDATION_REQUEST_PREDEPLOY_ADDRESS has no code after deployment".to_string()));
}

match report.result {
TxResult::Success => Some(report),
_ => None,
TxResult::Success => Ok(Some(report)),
_ => Ok(None),
}
}

Expand Down Expand Up @@ -615,18 +630,22 @@ pub fn extract_all_requests_levm(
}
}

let withdrawals_data: Vec<u8> = match LEVM::read_withdrawal_requests(header, db) {
let withdrawals_data: Vec<u8> = match LEVM::read_withdrawal_requests(header, db)? {
Some(report) => {
// the cache is updated inside the generic_system_call
report.output.into()
match report.result {
TxResult::Success => report.output.into(), // the cache is updated inside the generic_system_call
TxResult::Revert(vmerror) => return Err(EvmError::from(vmerror)),
}
}
None => Default::default(),
};

let consolidation_data: Vec<u8> = match LEVM::dequeue_consolidation_requests(header, db) {
let consolidation_data: Vec<u8> = match LEVM::dequeue_consolidation_requests(header, db)? {
Some(report) => {
// the cache is updated inside the generic_system_call
report.output.into()
match report.result {
TxResult::Success => report.output.into(), // the cache is updated inside the generic_system_call
TxResult::Revert(vmerror) => return Err(EvmError::from(vmerror)),
}
}
None => Default::default(),
};
Expand Down