Skip to content

feat(forks,tests): implement EIP-8337 Validated EVM Code - #3576

Draft
gcolvin wants to merge 3 commits into
ethereum:forks/amsterdamfrom
gcolvin:eips/amsterdam/eip-8337
Draft

gcolvin wants to merge 3 commits into
ethereum:forks/amsterdamfrom
gcolvin:eips/amsterdam/eip-8337

Conversation

@gcolvin

@gcolvin gcolvin commented Sep 11, 2026

Copy link
Copy Markdown

Draft. Reference implementation and tests for EIP-8337, which adds opt-in validation on top of EIP-7979 (#3575, which this branch includes). Not proposed for Hegotá; posted to show that 7979 can be validated in about 450 lines when the time comes. MAGIC bytes, header layout, and the validation charge are placeholders, each defined in one place. All 200 fixtures fill against the spec; just static is clean.

Description

Related Issues or PRs

N/A.

Checklist

  • Ran fast static checks to avoid CI fails, see Code Standards & Verifying Changes: just static
  • PR title has the form <type>(<area>): <title>, where <type> and <area> come from an appropriate C-<type>, respectively A-<area>, label. The title should match the target squash commit message.

Cute Animal Picture

Put a link to a cute animal picture inside the parenthesis-->

EIP-7979 adds explicit call and return instructions to the EVM: a
per-frame return stack and three opcodes, CALLSUB (0xB0), CALLDEST
(0xB1) and RETURNSUB (0xB2), using the EIP's placeholder values.

Spec (src/ethereum/forks/amsterdam):
- Evm gains `return_stack` and `valid_call_destinations`;
  RETURN_STACK_LIMIT = 1024.
- The JUMPDEST scan becomes a single pass, `get_valid_destinations`,
  returning both the jump and the call destination sets. A CALLDEST is
  both, so JUMP and JUMPI need no change. The EIP-8024 immediate
  handling is preserved.
- callsub/calldest/returnsub in control_flow.py; ReturnStackOverflowError
  and ReturnStackUnderflowError; gas costs mid (8), jumpdest (1) and
  low (5).

Framework (packages/testing):
- Opcode table entries and the EIP7979 fork mixin, picked up by
  Amsterdam automatically.

Tests (tests/amsterdam/eip7979_callsub, 44 tests, 130 fixtures):
- The EIP's five vectors byte-for-byte; invalid destinations (JUMPDEST,
  PUSH data, DUPN immediate, out of range, uint64 overflow, self, stack
  underflow); return-stack underflow; the 1024 limit by counted
  recursion; per-frame isolation across all four call opcodes; call
  elimination via JUMP/JUMPI, tail call and mutual recursion at constant
  depth; exact gas by measurement; initcode, CREATE, CREATE2 and 7702
  contexts; fork transition.
- tests/frontier/opcodes/test_all_opcodes.py: CALLSUB and RETURNSUB get
  the same special-casing as JUMP in the generic harness.
ethereum-spec-lint's UintLenHygiene rule requires ulen(...) rather than
Uint(len(...)).
EIP-8337 validates code prefixed with MAGIC bytes at CREATE time,
proving fully static control flow and no data-stack underflow, and
begins execution of such code immediately after its header. Requires
EIP-7979.

Placeholders, each in one place (vm/validation.py, vm/gas.py), pending
the EIP: MAGIC = 0xEF 0x79, a one-byte version 0x01 naming this fork's
validation rules, VALIDATION_BYTE_COST = 64.

Spec (src/ethereum/forks/amsterdam):
- vm/validation.py: the EIP's reference validator, ported with the
  opcode table extended to this fork (CLZ, SLOTNUM, and EIP-8024
  DUPN/SWAPN/EXCHANGE with their immediate rules). Traversal begins at
  the entry point; header bytes are unreachable data.
- CREATE (all three paths): code beginning with MAGIC is charged
  VALIDATION_BYTE_COST per byte before validation runs, then validated;
  failure is an exceptional halt (InvalidValidatedCode), as EIP-3541's
  rejection is. Other 0xEF prefixes are rejected as before.
- Execution of created MAGIC code starts after the header; positions
  remain absolute. Initcode is neither validated nor given an entry
  point. The runtime JUMPDEST scan also starts at the entry point.

Framework: an EIP8337 mixin (no opcode changes).

Tests (tests/amsterdam/eip8337_validated_code, 66 tests, 200 fixtures):
- The EIP's 43 validation vectors deployed behind the header (PUSH1
  destinations relocated by the header length), each created iff valid.
- Header and prefix cases: header only, wrong version, bare MAGIC, the
  EIP-3541/EOF/7702 0xEF prefixes, plain code.
- CREATE and CREATE2 paths, factory keeps its gas on failure; MAGIC
  initcode gets no entry point; the validation charge measured as
  exactly VALIDATION_BYTE_COST per byte against equal-length plain code.
- Execution: entry point, CODESIZE and CODECOPY see the header, absolute
  JUMP/CALLSUB positions, MAGIC callee under every call opcode, invalid
  MAGIC code placed directly in state halts at runtime.
- Fork transition.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant