Skip to content

feat(proofs): fully prove SwitchCaseBodyBridge, reduce axiom count 3→2#1557

Merged
Th0rgal merged 4 commits into
mainfrom
codex/prove-switch-case-body-bridge
Mar 10, 2026
Merged

feat(proofs): fully prove SwitchCaseBodyBridge, reduce axiom count 3→2#1557
Th0rgal merged 4 commits into
mainfrom
codex/prove-switch-case-body-bridge

Conversation

@Th0rgal
Copy link
Copy Markdown
Member

@Th0rgal Th0rgal commented Mar 10, 2026

Summary

  • Fully eliminate the SwitchCaseBodyBridge axiom — it is now a proved theorem
  • Prove sizeOf_buildSwitch_ge_switchCases mechanically (structural AST sizeOf bound)
  • Narrow execYulStmtsFuel_fuel_adequate to require explicit h : fuel ≥ sizeOf body + 1 precondition with unwrapped equality (strictly stronger than previous version)
  • Axiom count in Preservation.lean: 3 → 2 (only execYulStmtsFuel_setVar_hasSelector_irrelevant and execYulStmtsFuel_fuel_adequate remain)

Key new proved theorems

Theorem Purpose
sizeOf_lt_of_mem List membership implies strictly smaller sizeOf
sizeOf_switchCaseBody_ge switchCaseBody fn has sizeOf ≥ fn.body + 2
sizeOf_switchCases_gt_body switchCases list sizeOf > any member's body
sizeOf_buildSwitch_ge_switchCases Fully proved structural AST bound (was axiom)
sizeOf_buildSwitch_ge_fn_body Composes above three for fn.body + 12
SwitchCaseBodyBridge_body Proved theorem composing axioms #2 and #3
SwitchCaseBodyBridge Proved theorem with hFuelAdequate : fuel ≥ sizeOf fn.body + 5

How the fuel precondition is discharged

SwitchCaseBodyBridge requires fuel ≥ sizeOf fn.body + 5. At the call site, sizeOf_buildSwitch_ge_fn_body proves sizeOf [buildSwitch fns none none] ≥ sizeOf fn.body + 12, which provides more than enough fuel since the dispatch block uses sizeOf body + 1 as fuel.

Test plan

  • lake build succeeds with no errors, no sorry
  • make check passes all checks (axiom locations, proof length, hygiene, paths, etc.)
  • Only Preservation.lean and AXIOMS.md modified
  • AXIOMS.md updated with correct line numbers and elimination notes

🤖 Generated with Claude Code

@vercel
Copy link
Copy Markdown

vercel Bot commented Mar 10, 2026

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

Project Deployment Actions Updated (UTC)
dumbcontracts Ready Ready Preview, Comment Mar 10, 2026 1:57pm

Request Review

@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

Comment thread Compiler/Proofs/YulGeneration/Preservation.lean Outdated
…eorem + narrower axiom

Replace the `SwitchCaseBodyBridge` axiom with:

1. `exec_switchCaseBody_continue_of_long` (proved theorem) — when dispatch
   guards are safe and calldata arity is sufficient, the guard prefix
   (comment + optional callvalue guard + calldatasize guard) of
   `switchCaseBody fn` steps through as a no-op, reducing execution to
   `fn.body` in the same state.

2. `SwitchCaseBodyBridge_body` (narrower axiom) — purely Yul-level: executing
   a statement list with `__has_selector` set and dispatch fuel gives the same
   rollback-wrapped result as total `execYulStmts` execution. Captures variable
   irrelevance and fuel adequacy without mentioning IR types.

3. `SwitchCaseBodyBridge` (proved theorem) — composes the above two pieces to
   match the original axiom interface used by `yulCodegen_preserves_semantics`.

The active axiom count remains at 4, but the trusted surface is strictly
smaller: the new axiom is purely Yul-level and does not mention
`IRFunction`, `IRTransaction`, `execIRFunction`, `resultsMatch`, or
`interpretYulRuntime`.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add `exec_switchCaseBody_continue_of_long` and `SwitchCaseBodyBridge`
to the proof length allowlist. Both are transport-heavy reductions over
reducible Yul semantics, mirroring the existing allowlisted
`exec_switchCaseBody_revert_of_short` and `SwitchCaseBodyBridge_short`.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

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

…ndent axioms

Split the `SwitchCaseBodyBridge_body` axiom into two independent,
narrower axioms and make `SwitchCaseBodyBridge_body` a proved theorem
composing them:

1. `execYulStmtsFuel_setVar_hasSelector_irrelevant` — variable irrelevance:
   the `__has_selector` dispatch variable is never read by function body
   statements, so setting it does not change execution.

2. `execYulStmtsFuel_fuel_adequate` — fuel adequacy: the rollback-wrapped
   result under any fuel budget matches the total execution result.

Both axioms are purely Yul-level and do not mention IR types. This
increases the total axiom count from 4 to 5 but makes each axiom
independently auditable and testable.

AXIOMS.md updated with correct numbering (1-5) and trust summary.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown

@cursor cursor Bot left a comment

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 1 potential issue.

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

Comment thread Compiler/Proofs/YulGeneration/Preservation.lean Outdated
…_ge_switchCases

Eliminate the SwitchCaseBodyBridge axiom entirely by proving all structural
sizeOf bounds mechanically. The key additions:

- sizeOf_lt_of_mem: list membership implies strictly smaller sizeOf
- sizeOf_switchCaseBody_ge: switchCaseBody fn has sizeOf ≥ fn.body + 2
- sizeOf_switchCases_gt_body: switchCases list sizeOf > any member's body
- sizeOf_buildSwitch_ge_switchCases: fully proved structural AST bound
- sizeOf_buildSwitch_ge_fn_body: composing the above for fn.body + 12

SwitchCaseBodyBridge is now a proved theorem threading a fuel precondition
(hFuelAdequate : fuel ≥ sizeOf fn.body + 5) that is discharged at the
call site using sizeOf_buildSwitch_ge_fn_body.

The execYulStmtsFuel_fuel_adequate axiom is narrowed to require an explicit
h : fuel ≥ sizeOf body + 1 precondition with unwrapped equality.

Axiom count in Preservation.lean: 3 → 2.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Th0rgal Th0rgal changed the title refactor(proofs): decompose SwitchCaseBodyBridge into narrower axioms feat(proofs): fully prove SwitchCaseBodyBridge, reduce axiom count 3→2 Mar 10, 2026
@Th0rgal Th0rgal merged commit 0f837ee into main Mar 10, 2026
6 of 8 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