Skip to content

feat: bytecode immutables (#1992)#2027

Merged
Th0rgal merged 12 commits into
mainfrom
task/1992-immutables
Jun 17, 2026
Merged

feat: bytecode immutables (#1992)#2027
Th0rgal merged 12 commits into
mainfrom
task/1992-immutables

Conversation

@Th0rgal

@Th0rgal Th0rgal commented Jun 13, 2026

Copy link
Copy Markdown
Member

Summary

Implements issue #1992 — Solidity-style bytecode immutables.

  • Adds Expr.immutable, Stmt.setImmutable, ImmutableSpec, and CompilationModel.immutables.
  • Macro immutables stay out of storage fields; constructor initializers lower to setImmutable.
  • Yul lowering emits loadimmutable(...) reads and deploy-side setimmutable(dataoffset("runtime"), ...).
  • Layout / reporting / validation / trust / usage surfaces all account for immutables.
  • Removes the INITIAL_CHAIN_ID slot-1024 hack.

Proofs

  • Immutable semantics added to source/denote states; denote/source agreement proved for immutable reads and setImmutable.
  • setImmutable wired through supported statement fragments, generic induction boundaries, end-to-end base cases, and generated transition summaries.

Test plan

  • lake build Verity Contracts Compiler PrintAxioms → "Build completed successfully."
  • scripts/refresh_verification_artifacts.sh → "[refresh] PASS"
  • python3 scripts/check_proof_length.py → passed (no proof > 50 lines)
  • make check → "All checks passed."
  • zero sorry, zero axioms

Note

Medium Risk
Large compiler and proof surface change affecting generated contract bytecode; mitigated by strict validation and extensive tests, but incorrect lowering would affect all contracts using immutables.

Overview
Replaces the prior approach of hiding immutables in synthetic storage fields with Solidity-style bytecode immutables on CompilationModel.immutables.

The IR gains Expr.immutable and Stmt.setImmutable. Lowering emits loadimmutable for reads and deploy-side setimmutable(dataoffset("runtime"), …) for writes; setImmutable is rejected outside constructor/deploy (memory vs calldata dynamic source). Compile-time checks add duplicate immutable names, constructor-only initialization (every declared immutable must appear as Stmt.setImmutable in the constructor), and scoped name validation for reads/writes in functions vs constructor.

Layout reporting now includes an immutables array (bytecodeImmutable kind, zero storage footprint). Macro smoke tests and compile-driver tests were updated to expect the new surface instead of __immutable_* storage slots.

Formal semantics and proofs thread an immutable : String → Uint256 through runtime/denote state, prove denote/source agreement for immutable reads and setImmutable, and extend supported fragments, scope discipline, transition summaries, and end-to-end proof cases accordingly.

Reviewed by Cursor Bugbot for commit 1a19449. Bugbot is set up for automated code reviews on this repo. Configure here.

@vercel

vercel Bot commented Jun 13, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
verity Ready Ready Preview, Comment Jun 17, 2026 10:49am

Request Review

Comment thread Compiler/CompilationModel/ScopeValidation.lean Outdated
Comment thread Compiler/CompilationModel/Compile.lean Outdated
@github-actions

Copy link
Copy Markdown
Contributor
\n### CI Failure Hints\n\nFailed jobs: `build`\n\nCopy-paste local triage:\n```bash\nmake check\nlake build\nFOUNDRY_PROFILE=difftest forge test -vv\n```

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 343b051. Configure here.

Comment thread Compiler/CompilationModel/Validation.lean
Comment thread Compiler/CompilationModel/Dispatch.lean
Th0rgal added 2 commits June 17, 2026 09:36
Add a dedup check for spec.immutables in validateCompilationModel,
mirroring the existing dedup checks for fields/events/internals, plus a
compile-error regression test.
 Bugbot)

ImmutableSpec.init is declarative-only and never emitted by codegen; deploy
code only emits setimmutable from explicit Stmt.setImmutable statements. Without
this check a declared immutable could go uninitialized and read garbage at
runtime. validateImmutableInitialization rejects specs that declare immutables
with no constructor, or leave any declared immutable unset.
@Th0rgal Th0rgal merged commit 3268129 into main Jun 17, 2026
13 of 20 checks passed
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