Skip to content

Align Yul interpreter with Solidity semantics#84

Draft
danrobinson wants to merge 4 commits into
NethermindEth:mainfrom
danrobinson:codex/solidity-switch-semantics
Draft

Align Yul interpreter with Solidity semantics#84
danrobinson wants to merge 4 commits into
NethermindEth:mainfrom
danrobinson:codex/solidity-switch-semantics

Conversation

@danrobinson
Copy link
Copy Markdown

@danrobinson danrobinson commented May 15, 2026

Summary

This aligns several Yul interpreter behaviors with Solidity's Yul semantics:

  • switch now executes only the selected case body, or the default body when no case matches.
  • Switches without an explicit default now lower through the Yul notation layer as an empty default body, matching Solidity's default {} equivalence.
  • Block execution now drops locals declared inside the block when the block exits.
  • Declarations and assignments are represented separately, so let x := ... and x := ... no longer have the same AST/semantics.
  • Invalid references to out-of-scope or undeclared variables now produce an interpreter error instead of silently reading a value.
  • Duplicate declarations of visible variables now produce an interpreter error, matching Solidity/Yul's no-shadowing rule.
  • Function return variables are initialized to zero when a Yul function call starts.
  • Call-like builtins now treat a reverted callee as a failed call returning 0, instead of propagating Revert as an interpreter error.
  • Yul SELFDESTRUCT now halts execution after applying the existing modelled account and substate effects.

This does not attempt to fully remodel SELFDESTRUCT. The existing limitations around account/external-interaction behavior remain, including not triggering fallback behavior on a recipient contract and not claiming a full account-lifecycle model for all post-Cancun/EIP-6780 cases.

Regression tests

Added focused Yul semantics tests covering:

  • a selected switch case with a reverting default branch;
  • omitted-default switch notation lowering to an empty default and executing regularly on no match;
  • block-local variables not leaking outside their block;
  • rejection of shadowed declarations;
  • assignment to an existing local;
  • rejection of assignment to an undeclared local;
  • zero initialization of empty function return variables;
  • call to a reverting callee returning 0;
  • SELFDESTRUCT preventing following code from executing.

Testing

lake build EvmYul.Yul.YulNotation
lake build EvmYul.Yul.YulSemanticsTests.Main
lake exe yulSemanticsTests
lake build

@danrobinson danrobinson changed the title Fix Yul switch execution to run only selected branch Align Yul interpreter with Solidity semantics May 15, 2026
@danrobinson danrobinson force-pushed the codex/solidity-switch-semantics branch from 66633c5 to 355d10e Compare May 15, 2026 03:52
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