|
| 1 | +import pytest |
| 2 | + |
| 3 | +from ethereum_test_forks import Fork |
| 4 | +from ethereum_test_tools import (Alloc, Block, BlockchainTestFiller, |
| 5 | + Environment, Transaction) |
| 6 | +from ethereum_test_tools.vm.opcode import Opcodes as Op |
| 7 | + |
| 8 | +REFERENCE_SPEC_GIT_PATH = "TODO" |
| 9 | +REFERENCE_SPEC_VERSION = "TODO" |
| 10 | + |
| 11 | +MAX_CONTRACT_SIZE = 24 * 1024 |
| 12 | +GAS_LIMIT = 36_000_000 |
| 13 | +MAX_NUM_CONTRACT_CALLS = (GAS_LIMIT - 21_000) // (3 + 2600) |
| 14 | + |
| 15 | + |
| 16 | +@pytest.mark.zkevm |
| 17 | +@pytest.mark.valid_from("Cancun") |
| 18 | +@pytest.mark.parametrize( |
| 19 | + "num_called_contracts", |
| 20 | + [ |
| 21 | + 1, |
| 22 | + # 10, |
| 23 | + # MAX_NUM_CONTRACT_CALLS |
| 24 | + ], |
| 25 | +) |
| 26 | +def test_worst_bytecode( |
| 27 | + blockchain_test: BlockchainTestFiller, |
| 28 | + pre: Alloc, |
| 29 | + fork: Fork, |
| 30 | + num_called_contracts : int, |
| 31 | +): |
| 32 | + """ |
| 33 | + Test a block execution calling contracts with the maximum size of bytecode. |
| 34 | + """ |
| 35 | + env = Environment(gas_limit=GAS_LIMIT) |
| 36 | + |
| 37 | + contract_addrs = [] |
| 38 | + for i in range(num_called_contracts): |
| 39 | + code = Op.JUMPDEST * (MAX_CONTRACT_SIZE - 1 - 10) + Op.PUSH10(i) |
| 40 | + contract_addrs.append(pre.deploy_contract(code=code)) |
| 41 | + |
| 42 | + attack_code = sum([Op.EXTCODESIZE(contract_addrs[i]) for i in range(num_called_contracts)]) |
| 43 | + attack_contract = pre.deploy_contract(code=attack_code) |
| 44 | + |
| 45 | + tx = Transaction( |
| 46 | + to=attack_contract, |
| 47 | + gas_limit=GAS_LIMIT, |
| 48 | + gas_price=10, |
| 49 | + sender=pre.fund_eoa(), |
| 50 | + data=[], |
| 51 | + value=0, |
| 52 | + ) |
| 53 | + |
| 54 | + blockchain_test( |
| 55 | + env=env, |
| 56 | + pre=pre, |
| 57 | + post={}, |
| 58 | + blocks=[Block(txs=[tx])], |
| 59 | + ) |
0 commit comments