Skip to content

Commit c8b1911

Browse files
feat(pre_alloc): Add maximum bytecode size limit for contract deployment
1 parent 98848df commit c8b1911

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/pytest_plugins/filler/pre_alloc.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
CONTRACT_START_ADDRESS_DEFAULT = 0x1000000000000000000000000000000000001000
3737
CONTRACT_ADDRESS_INCREMENTS_DEFAULT = 0x100
3838

39+
MAX_BYTECODE_SIZE = 24576
40+
3941

4042
def pytest_addoption(parser: pytest.Parser):
4143
"""Add command-line options to pytest."""
@@ -162,12 +164,18 @@ def deploy_contract(
162164
if self._alloc_mode == AllocMode.STRICT:
163165
assert Number(nonce) >= 1, "impossible to deploy contract with nonce lower than one"
164166

167+
code = self.code_pre_processor(code, evm_code_type=evm_code_type)
168+
code_bytes = bytes(code) if not isinstance(code, (bytes, str)) else code
169+
assert len(code_bytes) <= MAX_BYTECODE_SIZE, (
170+
f"code too large: {len(code_bytes)} > {MAX_BYTECODE_SIZE}"
171+
)
172+
165173
super().__setitem__(
166174
contract_address,
167175
Account(
168176
nonce=nonce,
169177
balance=balance,
170-
code=self.code_pre_processor(code, evm_code_type=evm_code_type),
178+
code=code,
171179
storage=storage,
172180
),
173181
)

0 commit comments

Comments
 (0)