Skip to content

Commit bbf57a8

Browse files
feat(forks): introduce max code size / max initcode size
1 parent 031fb2f commit bbf57a8

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
@@ -471,6 +471,18 @@ def evm_code_types(cls, block_number: int = 0, timestamp: int = 0) -> List[EVMCo
471471
"""Return list of EVM code types supported by the fork."""
472472
pass
473473

474+
@classmethod
475+
@abstractmethod
476+
def max_code_size(cls) -> int | None:
477+
"""Return the maximum code size to be deployed in a CREATE-frame."""
478+
pass
479+
480+
@classmethod
481+
@abstractmethod
482+
def max_initcode_size(cls) -> int | None:
483+
"""Return the maximum initcode size when using a CREATE frame."""
484+
pass
485+
474486
@classmethod
475487
@abstractmethod
476488
def call_opcodes(

src/ethereum_test_forks/forks/forks.py

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

372+
@classmethod
373+
def max_code_size(cls) -> None:
374+
"""At genesis, there is no upper bound for code size (bounded by block gas limit)."""
375+
return None
376+
377+
@classmethod
378+
def max_initcode_size(cls) -> None:
379+
"""At genesis, there is no upper bound for initcode size (bounded by block gas limit)."""
380+
return None
381+
372382
@classmethod
373383
def call_opcodes(
374384
cls, block_number: int = 0, timestamp: int = 0
@@ -634,6 +644,12 @@ def precompiles(cls, block_number: int = 0, timestamp: int = 0) -> List[Address]
634644
block_number, timestamp
635645
)
636646

647+
@classmethod
648+
def max_code_size(cls) -> int:
649+
# NOTE: Move this to Spurious Dragon once this fork is introduced. See EIP-170.
650+
"""At Spurious Dragon, an upper bound was introduced for max contract code size."""
651+
return int(0x6000)
652+
637653
@classmethod
638654
def call_opcodes(
639655
cls, block_number: int = 0, timestamp: int = 0
@@ -860,6 +876,11 @@ def engine_new_payload_version(
860876
"""From Shanghai, new payload calls must use version 2."""
861877
return 2
862878

879+
@classmethod
880+
def max_initcode_size(cls) -> int:
881+
"""From Shanghai, the initcode size is now limited. See EIP-3860."""
882+
return int(0xC000)
883+
863884
@classmethod
864885
def valid_opcodes(
865886
cls,
@@ -1317,6 +1338,16 @@ def engine_get_blobs_version(cls, block_number: int = 0, timestamp: int = 0) ->
13171338
"""At Osaka, the engine get blobs version is 2."""
13181339
return 2
13191340

1341+
@classmethod
1342+
def max_code_size(cls) -> int:
1343+
"""From Osaka, the max code size is lifted. See EIP-7907."""
1344+
return int(0x40000)
1345+
1346+
@classmethod
1347+
def max_initcode_size(cls) -> int:
1348+
"""At genesis, there is no upper bound for initcode size (bounded by block gas limit)."""
1349+
return int(0x80000)
1350+
13201351
@classmethod
13211352
def is_deployed(cls) -> bool:
13221353
"""

0 commit comments

Comments
 (0)