Skip to content

audit: extract errorStringSelectorWord constant, add CI sync check#671

Merged
Th0rgal merged 1 commit into
mainfrom
audit/dedup-error-selector-constant
Feb 22, 2026
Merged

audit: extract errorStringSelectorWord constant, add CI sync check#671
Th0rgal merged 1 commit into
mainfrom
audit/dedup-error-selector-constant

Conversation

@Th0rgal
Copy link
Copy Markdown
Member

@Th0rgal Th0rgal commented Feb 22, 2026

Summary

  • Extract errorStringSelectorWord (0x08c379a0 << 224) as a public constant in ContractSpec.lean, replacing 5 inline magic hex literals across compiler and proof files
  • Interpreter.lean keeps a private decimal copy (avoiding ContractSpec import); CI now validates both values stay in sync
  • New check Add raise-slot helper and example #7 in check_selectors.py: check_error_selector_sync() validates the constant in both ContractSpec and Interpreter

What changed

File Change
Compiler/ContractSpec.lean New public errorStringSelectorWord; revertWithMessage uses it
Compiler/Proofs/IRGeneration/Expr.lean 4 concrete IR revert defs use the constant instead of inline hex
Compiler/Interpreter.lean Added comments linking private copy to canonical constant
scripts/check_selectors.py New check_error_selector_sync() validates constant consistency
AUDIT.md Documented design decision and CI check

Test plan

  • check_selectors.py passes locally (includes new sync check)
  • check_doc_counts.py passes locally
  • Full CI (Lean build + Foundry tests)

🤖 Generated with Claude Code


Note

Low Risk
Mostly constant deduplication plus an additional CI consistency check; behavior should remain identical aside from preventing accidental selector drift.

Overview
Extracts a shared errorStringSelectorWord constant for the Error(string) ABI selector (shifted into a 32-byte word) and replaces multiple inline magic literals in ContractSpec.revertWithMessage and concrete IR proof revert snippets.

Keeps the interpreter’s private copy but documents it as a duplicate of the canonical value, and extends scripts/check_selectors.py to CI-validate that the ContractSpec and Interpreter constants remain in sync; AUDIT.md is updated to record this design decision and the new check.

Written by Cursor Bugbot for commit b0fef29. This will update automatically on new commits. Configure here.

The Error(string) selector (0x08c379a0 << 224) was duplicated as magic
hex literals in 6 locations across 3 files.  Extract a public constant
`errorStringSelectorWord` in ContractSpec.lean and reference it from
`revertWithMessage` and the 4 concrete IR proof terms in Expr.lean.

Interpreter.lean keeps a private decimal copy to avoid importing
ContractSpec; a new CI check in check_selectors.py validates both
values stay in sync.

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

vercel Bot commented Feb 22, 2026

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

Project Deployment Actions Updated (UTC)
dumbcontracts Ready Ready Preview, Comment Feb 22, 2026 2:19am

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.

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.

f"Interpreter.revertSelectorWord: value {interp_val} does not "
f"match canonical errorStringSelectorWord "
f"({_ERROR_STRING_SELECTOR_SHIFTED})"
)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

CI sync check silently passes on missing Interpreter definition

Medium Severity

check_error_selector_sync silently passes when _INTERPRETER_RE fails to match in Interpreter.lean (e.g., if the definition is renamed, reformatted, or removed). Unlike the ContractSpec branch which reports an error when its regex doesn't match, the Interpreter branch simply does nothing when m2 is None. This contradicts the stated guarantee in AUDIT.md that "CI validates both values match" and is inconsistent with how other sync checks (e.g., check_builtin_list_sync.py) handle missing definitions.

Additional Locations (1)

Fix in Cursor Fix in Web

@Th0rgal Th0rgal merged commit b66bd79 into main Feb 22, 2026
23 checks passed
@Th0rgal Th0rgal deleted the audit/dedup-error-selector-constant branch February 22, 2026 02:23
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.

2 participants