Skip to content

Commit e6108ed

Browse files
timsburkSamWilsn
authored andcommitted
Refactor transaction validation to use MAX_INIT_CODE_SIZE instead of MAX_CODE_SIZE across multiple modules
1 parent d12896a commit e6108ed

File tree

9 files changed

+15
-12
lines changed

9 files changed

+15
-12
lines changed

src/ethereum/cancun/transactions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,14 +443,14 @@ def validate_transaction(tx: Transaction) -> Uint:
443443
444444
[EIP-2681]: https://eips.ethereum.org/EIPS/eip-2681
445445
"""
446-
from .vm.interpreter import MAX_CODE_SIZE
446+
from .vm.interpreter import MAX_INIT_CODE_SIZE
447447

448448
intrinsic_gas = calculate_intrinsic_cost(tx)
449449
if intrinsic_gas > tx.gas:
450450
raise InvalidTransaction("Insufficient gas")
451451
if U256(tx.nonce) >= U256(U64.MAX_VALUE):
452452
raise InvalidTransaction("Nonce too high")
453-
if tx.to == Bytes0(b"") and len(tx.data) > 2 * MAX_CODE_SIZE:
453+
if tx.to == Bytes0(b"") and len(tx.data) > MAX_INIT_CODE_SIZE:
454454
raise InvalidTransaction("Code size too large")
455455

456456
return intrinsic_gas

src/ethereum/cancun/vm/instructions/system.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,15 @@ def generic_create(
7272
# This import causes a circular import error
7373
# if it's not moved inside this method
7474
from ...vm.interpreter import (
75-
MAX_CODE_SIZE,
75+
MAX_INIT_CODE_SIZE,
7676
STACK_DEPTH_LIMIT,
7777
process_create_message,
7878
)
7979

8080
call_data = memory_read_bytes(
8181
evm.memory, memory_start_position, memory_size
8282
)
83-
if len(call_data) > 2 * MAX_CODE_SIZE:
83+
if len(call_data) > MAX_INIT_CODE_SIZE:
8484
raise OutOfGasError
8585

8686
create_message_gas = max_message_call_gas(Uint(evm.gas_left))

src/ethereum/cancun/vm/interpreter.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262

6363
STACK_DEPTH_LIMIT = Uint(1024)
6464
MAX_CODE_SIZE = 0x6000
65+
MAX_INIT_CODE_SIZE = 2 * MAX_CODE_SIZE
6566

6667

6768
@dataclass

src/ethereum/prague/transactions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -540,14 +540,14 @@ def validate_transaction(tx: Transaction) -> Tuple[Uint, Uint]:
540540
[EIP-2681]: https://eips.ethereum.org/EIPS/eip-2681
541541
[EIP-7623]: https://eips.ethereum.org/EIPS/eip-7623
542542
"""
543-
from .vm.interpreter import MAX_CODE_SIZE
543+
from .vm.interpreter import MAX_INIT_CODE_SIZE
544544

545545
intrinsic_gas, calldata_floor_gas_cost = calculate_intrinsic_cost(tx)
546546
if max(intrinsic_gas, calldata_floor_gas_cost) > tx.gas:
547547
raise InvalidTransaction("Insufficient gas")
548548
if U256(tx.nonce) >= U256(U64.MAX_VALUE):
549549
raise InvalidTransaction("Nonce too high")
550-
if tx.to == Bytes0(b"") and len(tx.data) > 2 * MAX_CODE_SIZE:
550+
if tx.to == Bytes0(b"") and len(tx.data) > MAX_INIT_CODE_SIZE:
551551
raise InvalidTransaction("Code size too large")
552552

553553
return intrinsic_gas, calldata_floor_gas_cost

src/ethereum/prague/vm/instructions/system.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,15 @@ def generic_create(
7373
# This import causes a circular import error
7474
# if it's not moved inside this method
7575
from ...vm.interpreter import (
76-
MAX_CODE_SIZE,
76+
MAX_INIT_CODE_SIZE,
7777
STACK_DEPTH_LIMIT,
7878
process_create_message,
7979
)
8080

8181
call_data = memory_read_bytes(
8282
evm.memory, memory_start_position, memory_size
8383
)
84-
if len(call_data) > 2 * MAX_CODE_SIZE:
84+
if len(call_data) > MAX_INIT_CODE_SIZE:
8585
raise OutOfGasError
8686

8787
create_message_gas = max_message_call_gas(Uint(evm.gas_left))

src/ethereum/prague/vm/interpreter.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464

6565
STACK_DEPTH_LIMIT = Uint(1024)
6666
MAX_CODE_SIZE = 0x6000
67+
MAX_INIT_CODE_SIZE = 2 * MAX_CODE_SIZE
6768

6869

6970
@dataclass

src/ethereum/shanghai/transactions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,14 +344,14 @@ def validate_transaction(tx: Transaction) -> Uint:
344344
345345
[EIP-2681]: https://eips.ethereum.org/EIPS/eip-2681
346346
"""
347-
from .vm.interpreter import MAX_CODE_SIZE
347+
from .vm.interpreter import MAX_INIT_CODE_SIZE
348348

349349
intrinsic_gas = calculate_intrinsic_cost(tx)
350350
if intrinsic_gas > tx.gas:
351351
raise InvalidTransaction("Insufficient gas")
352352
if U256(tx.nonce) >= U256(U64.MAX_VALUE):
353353
raise InvalidTransaction("Nonce too high")
354-
if tx.to == Bytes0(b"") and len(tx.data) > 2 * MAX_CODE_SIZE:
354+
if tx.to == Bytes0(b"") and len(tx.data) > MAX_INIT_CODE_SIZE:
355355
raise InvalidTransaction("Code size too large")
356356

357357
return intrinsic_gas

src/ethereum/shanghai/vm/instructions/system.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,15 @@ def generic_create(
7171
# This import causes a circular import error
7272
# if it's not moved inside this method
7373
from ...vm.interpreter import (
74-
MAX_CODE_SIZE,
74+
MAX_INIT_CODE_SIZE,
7575
STACK_DEPTH_LIMIT,
7676
process_create_message,
7777
)
7878

7979
call_data = memory_read_bytes(
8080
evm.memory, memory_start_position, memory_size
8181
)
82-
if len(call_data) > 2 * MAX_CODE_SIZE:
82+
if len(call_data) > MAX_INIT_CODE_SIZE:
8383
raise OutOfGasError
8484

8585
create_message_gas = max_message_call_gas(Uint(evm.gas_left))

src/ethereum/shanghai/vm/interpreter.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262

6363
STACK_DEPTH_LIMIT = Uint(1024)
6464
MAX_CODE_SIZE = 0x6000
65+
MAX_INIT_CODE_SIZE = 2 * MAX_CODE_SIZE
6566

6667

6768
@dataclass

0 commit comments

Comments
 (0)