Skip to content

feat(opcodes): reject 0xEF code prefix in CREATE/CREATE2#94

Merged
mw2000 merged 1 commit intomainfrom
feat/issue-72-ef-prefix-rejection
Mar 20, 2026
Merged

feat(opcodes): reject 0xEF code prefix in CREATE/CREATE2#94
mw2000 merged 1 commit intomainfrom
feat/issue-72-ef-prefix-rejection

Conversation

@mw2000
Copy link
Copy Markdown
Owner

@mw2000 mw2000 commented Mar 20, 2026

Summary

Implements EIP-3541 (London hardfork): CREATE and CREATE2 now reject deployment of runtime code whose first byte is 0xEF. This prefix is reserved for the EVM Object Format (EOF) to ensure future EOF contracts cannot be deployed accidentally or maliciously using the legacy creation path.

What changed

lib/eevm/opcodes/system/creation.ex

  • Added reject_eip_3541_runtime_code?/1 predicate that checks byte_size(runtime_code) > 0 and :binary.first(runtime_code) == 0xEF
  • Inserted the check in execute_create_inner/6 at the correct position: after init code execution, after EIP-170 code size check, before code deposit — so init code gas is consumed but no contract is deployed
  • Added @doc block explaining the EIP, its position in the check sequence, and the empty-code exception

test/opcodes/system/eip_3541_test.exs (new)

  • CREATE with 0xEF runtime prefix → pushes 0, nonce incremented, no code stored
  • CREATE2 with 0xEF runtime prefix → pushes 0
  • CREATE with empty runtime code → succeeds (empty is not 0xEF)
  • CREATE with 0x60 runtime prefix → succeeds, code stored correctly
  • Init code containing 0xEF bytes (but returning non-0xEF runtime) → succeeds

Spec reference

@mw2000 mw2000 changed the title feat(opcodes): reject 0xEF code prefix in CREATE/CREATE2 (EIP-3541) — Closes #72 feat(opcodes): reject 0xEF code prefix in CREATE/CREATE2 Mar 20, 2026
@mw2000 mw2000 force-pushed the feat/issue-72-ef-prefix-rejection branch 4 times, most recently from cc1637c to e72dac8 Compare March 20, 2026 08:06
…loses #72

EIP-3541 (London hardfork): CREATE and CREATE2 must refuse to deploy runtime
code whose first byte is 0xEF. That prefix is reserved for the EVM Object
Format (EOF) — future EOF contracts must be created via a dedicated EOF
creation transaction, not through legacy creation opcodes.

The check is inserted in execute_create_inner/6 at the correct position:
after init code execution, after EIP-170 code size validation, and before
code deposit. This means:
  - Init code gas is consumed (no refund on rejection)
  - Sender nonce is incremented before the attempt
  - Empty runtime code (<<>>) is explicitly allowed

Tests cover both opcodes, the empty-runtime edge case, safe non-0xEF
runtime code, and the case where 0xEF appears inside init code but the
returned runtime starts with a different byte.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
@mw2000 mw2000 force-pushed the feat/issue-72-ef-prefix-rejection branch from e72dac8 to e7c6807 Compare March 20, 2026 08:10
@mw2000 mw2000 merged commit 246773f into main Mar 20, 2026
2 checks passed
@mw2000 mw2000 deleted the feat/issue-72-ef-prefix-rejection branch March 20, 2026 08:13
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