Skip to content

Commit 86eb727

Browse files
feat(forks): introduce max code size / max initcode size
1 parent bceb08f commit 86eb727

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

src/ethereum_test_forks/base_fork.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,18 @@ def evm_code_types(cls, block_number: int = 0, timestamp: int = 0) -> List[EVMCo
462462
"""Return list of EVM code types supported by the fork."""
463463
pass
464464

465+
@classmethod
466+
@abstractmethod
467+
def max_code_size(cls) -> int | None:
468+
"""Return the maximum code size to be deployed in a CREATE-frame."""
469+
pass
470+
471+
@classmethod
472+
@abstractmethod
473+
def max_initcode_size(cls) -> int | None:
474+
"""Return the maximum initcode size when using a CREATE frame."""
475+
pass
476+
465477
@classmethod
466478
@abstractmethod
467479
def call_opcodes(

src/ethereum_test_forks/forks/forks.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,16 @@ def evm_code_types(cls, block_number: int = 0, timestamp: int = 0) -> List[EVMCo
364364
"""At Genesis, only legacy EVM code is supported."""
365365
return [EVMCodeType.LEGACY]
366366

367+
@classmethod
368+
def max_code_size(cls) -> None:
369+
"""At genesis, there is no upper bound for code size (bounded by block gas limit)."""
370+
return None
371+
372+
@classmethod
373+
def max_initcode_size(cls) -> None:
374+
"""At genesis, there is no upper bound for initcode size (bounded by block gas limit)."""
375+
return None
376+
367377
@classmethod
368378
def call_opcodes(
369379
cls, block_number: int = 0, timestamp: int = 0
@@ -629,6 +639,12 @@ def precompiles(cls, block_number: int = 0, timestamp: int = 0) -> List[Address]
629639
block_number, timestamp
630640
)
631641

642+
@classmethod
643+
def max_code_size(cls) -> int:
644+
# NOTE: Move this to Spurious Dragon once this fork is introduced. See EIP-170.
645+
"""At Spurious Dragon, an upper bound was introduced for max contract code size."""
646+
return int(0x6000)
647+
632648
@classmethod
633649
def call_opcodes(
634650
cls, block_number: int = 0, timestamp: int = 0
@@ -855,6 +871,11 @@ def engine_new_payload_version(
855871
"""From Shanghai, new payload calls must use version 2."""
856872
return 2
857873

874+
@classmethod
875+
def max_initcode_size(cls) -> int:
876+
"""From Shanghai, the initcode size is now limited. See EIP-3860."""
877+
return int(0xC000)
878+
858879
@classmethod
859880
def valid_opcodes(
860881
cls,
@@ -1302,6 +1323,16 @@ def engine_get_payload_version(
13021323
"""From Osaka, get payload calls must use version 5."""
13031324
return 5
13041325

1326+
@classmethod
1327+
def max_code_size(cls) -> int:
1328+
"""From Osaka, the max code size is lifted. See EIP-7907."""
1329+
return int(0x40000)
1330+
1331+
@classmethod
1332+
def max_initcode_size(cls) -> int:
1333+
"""At genesis, there is no upper bound for initcode size (bounded by block gas limit)."""
1334+
return int(0x80000)
1335+
13051336
@classmethod
13061337
def is_deployed(cls) -> bool:
13071338
"""

0 commit comments

Comments
 (0)