Skip to content

Commit f3d1ad7

Browse files
feat: EIP-7954 — double max code size and initcode limit (Amsterdam) (#12)
* feat: EIP-7954 — double max code size and initcode limit for Amsterdam Signed-off-by: garyschulte <garyschulte@gmail.com>
1 parent 3886b0d commit f3d1ad7

File tree

4 files changed

+24
-10
lines changed

4 files changed

+24
-10
lines changed

src/handler/validation.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ const TX_EIP7702_AUTH_COST: u64 = 25000;
1616
// EIP-7623: token costs (different from calldata gas costs)
1717
const FLOOR_ZERO_TOKEN_COST: u64 = 1;
1818
const FLOOR_NONZERO_TOKEN_COST: u64 = 4;
19-
// EIP-3860: max initcode size = 2 * MAX_CODE_SIZE
20-
const MAX_INITCODE_SIZE: usize = 49152;
2119

2220
/// Validation utilities
2321
pub const Validation = struct {
@@ -95,10 +93,12 @@ pub const Validation = struct {
9593
const spec = ctx.cfg.spec;
9694

9795
// EIP-3860 (Shanghai+): initcode size limit for CREATE transactions
96+
// EIP-7954 (Amsterdam+): limit doubled to 65536
9897
if (primitives.isEnabledIn(spec, .shanghai)) {
9998
if (tx.kind == .Create) {
10099
const calldata_len = if (tx.data) |d| d.items.len else 0;
101-
if (calldata_len > MAX_INITCODE_SIZE) {
100+
const max_initcode: usize = if (primitives.isEnabledIn(spec, .amsterdam)) primitives.AMSTERDAM_MAX_INITCODE_SIZE else primitives.MAX_INITCODE_SIZE;
101+
if (calldata_len > max_initcode) {
102102
return ValidationError.CreateInitcodeOverLimit;
103103
}
104104
}

src/interpreter/host.zig

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -416,16 +416,17 @@ pub const Host = struct {
416416
frame_depth: usize,
417417
) CreateSetupResult {
418418
const MAX_CALL_DEPTH = 1024;
419-
const MAX_CODE_SIZE: usize = 24576;
420-
const MAX_INITCODE_SIZE: usize = 2 * MAX_CODE_SIZE;
421-
422419
const js = &self.ctx.journaled_state;
423420
const spec_id = js.inner.spec;
424421

425422
if (frame_depth >= MAX_CALL_DEPTH) return .{ .failed = CreateResult.preExecFailure(gas_limit) };
426423

427424
if (primitives.isEnabledIn(spec_id, .shanghai)) {
428-
if (init_code.len > MAX_INITCODE_SIZE) return .{ .failed = CreateResult.preExecFailure(gas_limit) };
425+
const max_initcode: usize = if (primitives.isEnabledIn(spec_id, .amsterdam))
426+
primitives.AMSTERDAM_MAX_INITCODE_SIZE
427+
else
428+
primitives.MAX_INITCODE_SIZE;
429+
if (init_code.len > max_initcode) return .{ .failed = CreateResult.preExecFailure(gas_limit) };
429430
}
430431

431432
if (value > 0) {
@@ -491,7 +492,7 @@ pub const Host = struct {
491492
return_data: []const u8,
492493
spec_id: primitives.SpecId,
493494
) CreateResult {
494-
const MAX_CODE_SIZE: usize = 24576;
495+
const MAX_CODE_SIZE: usize = if (primitives.isEnabledIn(spec_id, .amsterdam)) primitives.AMSTERDAM_MAX_CODE_SIZE else primitives.MAX_CODE_SIZE;
495496
const js = &self.ctx.journaled_state;
496497

497498
if (!result.isSuccess()) {

src/interpreter/opcodes/call.zig

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,10 @@ pub fn opCreate(ctx: *InstructionContext) void {
382382
}
383383

384384
// EIP-3860 (Shanghai+): oversized initcode causes exceptional halt in calling frame.
385+
// EIP-7954 (Amsterdam+): limit doubled to 65536 (2 * 32768).
385386
if (primitives.isEnabledIn(spec, .shanghai)) {
386-
if (size_u > 49152) { // MAX_INITCODE_SIZE = 2 * 24576
387+
const max_initcode: usize = if (primitives.isEnabledIn(spec, .amsterdam)) primitives.AMSTERDAM_MAX_INITCODE_SIZE else primitives.MAX_INITCODE_SIZE;
388+
if (size_u > max_initcode) {
387389
ctx.interpreter.halt(.out_of_gas);
388390
return;
389391
}
@@ -491,8 +493,10 @@ pub fn opCreate2(ctx: *InstructionContext) void {
491493
}
492494

493495
// EIP-3860 (Shanghai+): oversized initcode causes exceptional halt in calling frame.
496+
// EIP-7954 (Amsterdam+): limit doubled to 65536 (2 * 32768).
494497
if (primitives.isEnabledIn(spec, .shanghai)) {
495-
if (size_u > 49152) { // MAX_INITCODE_SIZE = 2 * 24576
498+
const max_initcode: usize = if (primitives.isEnabledIn(spec, .amsterdam)) primitives.AMSTERDAM_MAX_INITCODE_SIZE else primitives.MAX_INITCODE_SIZE;
499+
if (size_u > max_initcode) {
496500
ctx.interpreter.halt(.out_of_gas);
497501
return;
498502
}

src/primitives/main.zig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,15 @@ pub const STACK_LIMIT: usize = 1024;
8181
/// EVM call stack limit
8282
pub const CALL_STACK_LIMIT: u64 = 1024;
8383

84+
/// EIP-170: maximum deployed contract code size (24576 bytes)
85+
pub const MAX_CODE_SIZE: usize = 24576;
86+
/// EIP-7954 (Amsterdam+): maximum deployed contract code size doubled (32768 bytes)
87+
pub const AMSTERDAM_MAX_CODE_SIZE: usize = 32768;
88+
/// EIP-3860: maximum initcode size = 2 * MAX_CODE_SIZE (49152 bytes)
89+
pub const MAX_INITCODE_SIZE: usize = 2 * MAX_CODE_SIZE;
90+
/// EIP-7954 (Amsterdam+): maximum initcode size = 2 * AMSTERDAM_MAX_CODE_SIZE (65536 bytes)
91+
pub const AMSTERDAM_MAX_INITCODE_SIZE: usize = 2 * AMSTERDAM_MAX_CODE_SIZE;
92+
8493
/// Blob base fee update fraction for Cancun hardfork (EIP-4844)
8594
pub const BLOB_BASE_FEE_UPDATE_FRACTION_CANCUN: u64 = 3338477;
8695
/// Blob base fee update fraction for Prague/Osaka hardfork (EIP-7691)

0 commit comments

Comments
 (0)