Skip to content

feat: add hardfork configuration system#100

Merged
mw2000 merged 6 commits intomainfrom
feat/issue-75-hardfork-config
Mar 22, 2026
Merged

feat: add hardfork configuration system#100
mw2000 merged 6 commits intomainfrom
feat/issue-75-hardfork-config

Conversation

@mw2000
Copy link
Copy Markdown
Owner

@mw2000 mw2000 commented Mar 21, 2026

Summary

Closes #75.

Adds a hardfork configuration system so eevm can toggle EIP-specific behavior based on the target hardfork, matching the design of revm's SpecId.

Changes

New: EEVM.HardforkConfig

  • spec_id type covering Frontier through Prague
  • Numeric ordering map so hardfork comparisons are simple integer arithmetic
  • enabled?(config, :eip_XXXX) helper — returns true if the EIP is active at the given fork
  • default/0 returns Cancun (preserves backwards compatibility)

Updated: EEVM.Config

  • Added hardfork: HardforkConfig.t() field (default :cancun)
  • Config.new/1 accepts an optional spec_id atom

Updated: EEVM.MachineState

  • new/2 accepts :hardfork keyword option, passed through to Config.new/1

EIP Guards Added

EIP Location Activation
EIP-3855 PUSH0 control_flow.ex Shanghai+
EIP-1153 TLOAD/TSTORE storage_ops.ex Cancun+
EIP-5656 MCOPY memory_ops.ex Cancun+
EIP-6780 SELFDESTRUCT semantics termination.ex Cancun+
EIP-2929 cold/warm access costs gas/access.ex Berlin+
EIP-3529 refund cap (1/5 vs 1/2) executor.ex London+
EIP-170 runtime code size limit creation.ex Spurious Dragon+
EIP-3860 initcode size limit + cost creation.ex Shanghai+
EIP-3541 0xEF prefix rejection creation.ex London+

All pre-activation: opcodes return :invalid; gas rules fall back to pre-EIP behavior.

Tests (test/hardfork_config_test.exs)

  • Unit tests for enabled?/2 at every EIP's hardfork boundary
  • Behavioral tests verifying PUSH0, TLOAD, TSTORE, MCOPY become :invalid before activation
  • EIP-6780: pre-Cancun SELFDESTRUCT always fully deletes; Cancun+ preserves account unless created this tx
  • EIP-2929: gas cost difference verified between Istanbul and Berlin
  • EIP-3529: both 1/5 and 1/2 refund cap paths exercised
  • Default hardfork asserted to be Cancun

Backwards Compatibility

All existing tests are unaffected — default hardfork is Cancun, which is what all existing tests implicitly relied on.

mw2000 and others added 5 commits March 21, 2026 03:01
Defines the Frontier through Prague hardfork timeline and an EIP\nactivation map so callers can check whether a given EIP feature\nflag is active for a given spec_id.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)
Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
…hineState.new/2

Config.new/1 now accepts a spec_id atom (default :cancun) and stores a\nHardforkConfig struct. MachineState.new/2 accepts a :hardfork keyword\noption and passes it to Config.new/1, preserving backwards compatibility.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)
Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
- EIP-3855 PUSH0 (0x5F): invalid before Shanghai\n- EIP-1153 TLOAD/TSTORE (0x5C/0x5D): invalid before Cancun\n- EIP-5656 MCOPY (0x5E): invalid before Cancun\n- EIP-6780 SELFDESTRUCT: pre-Cancun always fully deletes; Cancun+ only\n  deletes if contract was created in the same transaction\n- EIP-170 code size limit: skipped before Spurious Dragon\n- EIP-3860 initcode size limit + word cost: skipped before Shanghai\n- EIP-3541 0xEF prefix rejection: skipped before London

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)
Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
- EIP-2929 (Berlin+): address_access_cost and storage_access_cost now\n  check the hardfork config before applying cold/warm tracking\n- EIP-3529 (London+): apply_refund uses 1/5 cap; pre-London uses 1/2

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)
Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Adds HardforkConfigTest with:\n- Unit tests for enabled?/2 across all EIPs and hardfork boundaries\n- Behavioral tests verifying PUSH0, TLOAD/TSTORE, MCOPY become\n  :invalid before their activation hardfork\n- EIP-6780 SELFDESTRUCT: pre-Cancun always deletes, post-Cancun preserves\n- EIP-2929 gas cost differences between Istanbul and Berlin\n- EIP-3529 refund cap (1/5 London vs 1/2 pre-London)\n- Default hardfork is Cancun\n\nAlso updates ConfigTest for new Config.new/1 signature.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)
Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
@mw2000 mw2000 changed the title feat: add hardfork configuration system (issue #75) feat: add hardfork configuration system Mar 21, 2026
- memory_ops.ex: wrap long expansion_cost line per mix format\n- creation.ex: fix continuation indent on multi-line if/and expressions\n- hardfork_config_test.exs: each byte on its own line in <<>> literal;\n  fix EIP-2929 pre-Berlin gas assertion (storage_access returns 0, not 100)

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)
Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
@mw2000 mw2000 merged commit 0b4c945 into main Mar 22, 2026
2 checks passed
@mw2000 mw2000 deleted the feat/issue-75-hardfork-config branch March 22, 2026 04:37
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.

Add hardfork configuration system

1 participant