Skip to content

Commit 28fd22f

Browse files
committed
Optional raise on error/empty code (Only 7002/7251)
1 parent 40f3d9f commit 28fd22f

File tree

3 files changed

+35
-5
lines changed

3 files changed

+35
-5
lines changed

src/ethereum/cancun/fork.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,8 @@ def process_system_transaction(
484484
block_env: vm.BlockEnvironment,
485485
target_address: Address,
486486
data: Bytes,
487+
raise_on_empty_code: bool,
488+
raise_on_error: bool,
487489
) -> MessageCallOutput:
488490
"""
489491
Process a system transaction.
@@ -504,6 +506,11 @@ def process_system_transaction(
504506
"""
505507
system_contract_code = get_account(block_env.state, target_address).code
506508

509+
if len(system_contract_code) == 0 and raise_on_empty_code:
510+
raise InvalidBlock(
511+
f"System contract address {target_address.hex()} does not contain code"
512+
)
513+
507514
tx_env = vm.TransactionEnvironment(
508515
origin=SYSTEM_ADDRESS,
509516
gas_price=block_env.base_fee_per_gas,
@@ -538,6 +545,12 @@ def process_system_transaction(
538545

539546
system_tx_output = process_message_call(system_tx_message)
540547

548+
if system_tx_output.error and raise_on_error:
549+
raise InvalidBlock(
550+
f"System contract ({target_address.hex()}) call failed: "
551+
f"{system_tx_output.error}"
552+
)
553+
541554
# TODO: Empty accounts in post-merge forks are impossible
542555
# see Ethereum Improvement Proposal 7523.
543556
# This line is only included to support invalid tests in the test suite
@@ -585,6 +598,8 @@ def apply_body(
585598
block_env=block_env,
586599
target_address=BEACON_ROOTS_ADDRESS,
587600
data=block_env.parent_beacon_block_root,
601+
raise_on_empty_code=False,
602+
raise_on_error=False,
588603
)
589604

590605
for i, tx in enumerate(map(decode_transaction, transactions)):

src/ethereum/prague/fork.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,8 @@ def process_system_transaction(
516516
block_env: vm.BlockEnvironment,
517517
target_address: Address,
518518
data: Bytes,
519+
raise_on_empty_code: bool,
520+
raise_on_error: bool,
519521
) -> MessageCallOutput:
520522
"""
521523
Process a system transaction.
@@ -535,10 +537,11 @@ def process_system_transaction(
535537
Output of processing the system transaction.
536538
"""
537539
system_contract_code = get_account(block_env.state, target_address).code
538-
if len(system_contract_code) == 0:
539-
raise InvalidBlock(
540-
f"System contract address {target_address.hex()} does not contain code"
541-
)
540+
541+
if len(system_contract_code) == 0 and raise_on_empty_code:
542+
raise InvalidBlock(
543+
f"System contract address {target_address.hex()} does not contain code"
544+
)
542545

543546
tx_env = vm.TransactionEnvironment(
544547
origin=SYSTEM_ADDRESS,
@@ -575,7 +578,7 @@ def process_system_transaction(
575578

576579
system_tx_output = process_message_call(system_tx_message)
577580

578-
if system_tx_output.error:
581+
if system_tx_output.error and raise_on_error:
579582
raise InvalidBlock(
580583
f"System contract ({target_address.hex()}) call failed: "
581584
f"{system_tx_output.error}"
@@ -628,12 +631,16 @@ def apply_body(
628631
block_env=block_env,
629632
target_address=BEACON_ROOTS_ADDRESS,
630633
data=block_env.parent_beacon_block_root,
634+
raise_on_empty_code=False,
635+
raise_on_error=False,
631636
)
632637

633638
process_system_transaction(
634639
block_env=block_env,
635640
target_address=HISTORY_STORAGE_ADDRESS,
636641
data=block_env.block_hashes[-1], # The parent hash
642+
raise_on_empty_code=False,
643+
raise_on_error=False,
637644
)
638645

639646
for i, tx in enumerate(map(decode_transaction, transactions)):
@@ -673,6 +680,8 @@ def process_general_purpose_requests(
673680
block_env=block_env,
674681
target_address=WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS,
675682
data=b"",
683+
raise_on_empty_code=True,
684+
raise_on_error=True,
676685
)
677686

678687
if len(system_withdrawal_tx_output.return_data) > 0:
@@ -684,6 +693,8 @@ def process_general_purpose_requests(
684693
block_env=block_env,
685694
target_address=CONSOLIDATION_REQUEST_PREDEPLOY_ADDRESS,
686695
data=b"",
696+
raise_on_empty_code=True,
697+
raise_on_error=True,
687698
)
688699

689700
if len(system_consolidation_tx_output.return_data) > 0:

src/ethereum_spec_tools/evm_tools/t8n/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,13 +212,17 @@ def run_blockchain_test(self) -> None:
212212
block_env=block_env,
213213
target_address=self.fork.HISTORY_STORAGE_ADDRESS,
214214
data=block_env.block_hashes[-1], # The parent hash
215+
raise_on_empty_code=False,
216+
raise_on_error=False,
215217
)
216218

217219
if self.fork.is_after_fork("ethereum.cancun"):
218220
self.fork.process_system_transaction(
219221
block_env=block_env,
220222
target_address=self.fork.BEACON_ROOTS_ADDRESS,
221223
data=block_env.parent_beacon_block_root,
224+
raise_on_empty_code=False,
225+
raise_on_error=False,
222226
)
223227

224228
for i, tx in zip(self.txs.successfully_parsed, self.txs.transactions):

0 commit comments

Comments
 (0)