Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
14 changes: 13 additions & 1 deletion src/pytest_plugins/filler/pre_alloc.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,15 @@ class Alloc(BaseAlloc):
_contract_address_iterator: Iterator[Address] = PrivateAttr()
_eoa_iterator: Iterator[EOA] = PrivateAttr()
_evm_code_type: EVMCodeType | None = PrivateAttr(None)
_fork: Fork = PrivateAttr()

def __init__(
self,
*args,
alloc_mode: AllocMode,
contract_address_iterator: Iterator[Address],
eoa_iterator: Iterator[EOA],
fork: Fork,
evm_code_type: EVMCodeType | None = None,
**kwargs,
):
Expand All @@ -112,6 +114,7 @@ def __init__(
self._contract_address_iterator = contract_address_iterator
self._eoa_iterator = eoa_iterator
self._evm_code_type = evm_code_type
self._fork = fork

def __setitem__(self, address: Address | FixedSizeBytesConvertible, account: Account | None):
"""Set account associated with an address."""
Expand Down Expand Up @@ -162,12 +165,19 @@ def deploy_contract(
if self._alloc_mode == AllocMode.STRICT:
assert Number(nonce) >= 1, "impossible to deploy contract with nonce lower than one"

code = self.code_pre_processor(code, evm_code_type=evm_code_type)
code_bytes = bytes(code) if not isinstance(code, (bytes, str)) else code
max_code_size = self._fork.max_code_size()
assert len(code_bytes) <= max_code_size, (
f"code too large: {len(code_bytes)} > {max_code_size}"
)

super().__setitem__(
contract_address,
Account(
nonce=nonce,
balance=balance,
code=self.code_pre_processor(code, evm_code_type=evm_code_type),
code=code,
storage=storage,
),
)
Expand Down Expand Up @@ -416,11 +426,13 @@ def pre(
contract_address_iterator: Iterator[Address],
eoa_iterator: Iterator[EOA],
evm_code_type: EVMCodeType,
fork: Fork,
) -> Alloc:
"""Return default pre allocation for all tests (Empty alloc)."""
return Alloc(
alloc_mode=alloc_mode,
contract_address_iterator=contract_address_iterator,
eoa_iterator=eoa_iterator,
fork=fork,
evm_code_type=evm_code_type,
)
6 changes: 5 additions & 1 deletion src/pytest_plugins/filler/tests/test_pre_alloc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import pytest

from ethereum_test_base_types import Address, TestPrivateKey, TestPrivateKey2
from ethereum_test_forks import Fork, Prague
from ethereum_test_types import EOA
from ethereum_test_vm import EVMCodeType
from ethereum_test_vm import Opcodes as Op
Expand All @@ -18,7 +19,9 @@


def create_test_alloc(
alloc_mode: AllocMode = AllocMode.PERMISSIVE, evm_code_type: EVMCodeType = EVMCodeType.LEGACY
alloc_mode: AllocMode = AllocMode.PERMISSIVE,
fork: Fork = Prague,
evm_code_type: EVMCodeType = EVMCodeType.LEGACY,
) -> Alloc:
"""Create a test Alloc instance with default iterators."""
contract_iter = iter(
Expand All @@ -33,6 +36,7 @@ def create_test_alloc(
alloc_mode=alloc_mode,
contract_address_iterator=contract_iter,
eoa_iterator=eoa_iter,
fork=fork,
evm_code_type=evm_code_type,
)

Expand Down
11 changes: 9 additions & 2 deletions tests/benchmark/test_worst_compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -2872,13 +2872,20 @@ def test_worst_push(
):
"""Test running a block with as many PUSH as possible."""
op = opcode[1] if opcode.has_data_portion() else opcode
opcode_sequence = op * fork.max_stack_height()
target_contract_address = pre.deploy_contract(code=opcode_sequence)

op_seq = Bytecode()
for _ in range(fork.max_stack_height()):
if len(op_seq) + len(op) > fork.max_code_size():
break
op_seq += op

target_contract_address = pre.deploy_contract(code=op_seq)

calldata = Bytecode()
attack_block = Op.POP(Op.STATICCALL(Op.GAS, target_contract_address, 0, 0, 0, 0))

code = code_loop_precompile_call(calldata, attack_block, fork)

code_address = pre.deploy_contract(code=code)

tx = Transaction(
Expand Down
Loading