Skip to content

audit: extract addressMask constant, fix silent fallback, correct docstring#672

Merged
Th0rgal merged 1 commit into
mainfrom
audit/address-mask-constant-and-fallback-fix
Feb 22, 2026
Merged

audit: extract addressMask constant, fix silent fallback, correct docstring#672
Th0rgal merged 1 commit into
mainfrom
audit/address-mask-constant-and-fallback-fix

Conversation

@Th0rgal
Copy link
Copy Markdown
Member

@Th0rgal Th0rgal commented Feb 22, 2026

Summary

  • Extract addressMask ((2^160)-1) as a public constant in ContractSpec.lean, replacing 15 inline literals across compiler codegen, AST driver, and proof terms
  • Add CI check Add Lean to Yul compiler implementation plan #8 in check_selectors.py: check_address_mask_sync() validates consistency between ContractSpec.addressMask and Interpreter.addressModulus
  • Fix silent fallback: check_selectors.py now emits a stderr warning when yul-ast/ is validated against ContractSpec specs instead of ASTSpecs (was completely silent — audit transparency gap)
  • Fix misleading docstring on ABI.lean:renderSpecialEntry (claimed "always returns some" but code has a defensive none branch)

What changed

File Change
Compiler/ContractSpec.lean New public addressMask; 4 inline literals replaced
Compiler/ASTDriver.lean 1 inline literal replaced; addressMask added to open list
Compiler/Proofs/IRGeneration/Expr.lean 10 inline literals replaced
Compiler/Interpreter.lean Comments linking addressModulus to canonical constant
Compiler/ABI.lean Docstring corrected (code/doc contradiction)
scripts/check_selectors.py New check_address_mask_sync(); silent fallback → stderr warning
AUDIT.md Documented addressMask design decision and CI check

Test plan

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

🤖 Generated with Claude Code


Note

Low Risk
Primarily refactors repeated address-masking literals into a shared constant and adds CI/doc updates; behavior should be unchanged aside from clearer CI warnings.

Overview
Introduces a canonical addressMask constant in ContractSpec.lean and replaces multiple inline (2^160)-1 literals across the ContractSpec codegen paths, the AST driver’s constructor arg loading, and IR proof fixtures to keep address normalization consistent.

Strengthens CI/audit transparency by extending scripts/check_selectors.py with an address mask/modulus sync check (ContractSpec vs Interpreter) and emitting a stderr warning when yul-ast/ validation falls back to ContractSpec specs due to missing/empty ASTSpecs.lean. Also fixes a misleading docstring in ABI.lean about renderSpecialEntry and updates AUDIT.md to document the new shared constant and CI coverage.

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

…string

Extract `addressMask` ((2^160)-1) as a public constant in
ContractSpec.lean, replacing 15 scattered inline literals across
ContractSpec, ASTDriver, and proof terms in Expr.lean.

Interpreter.lean keeps a private `addressModulus` (2^160) to avoid
importing ContractSpec; a new CI check validates both stay in sync.

Also:
- check_selectors.py: emit stderr warning when yul-ast/ falls back
  to ContractSpec specs (was silent — audit transparency gap)
- ABI.lean: fix misleading docstring on renderSpecialEntry (claimed
  "always returns some" but code has a defensive guard)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@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.

@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 3:00am

Request Review

@Th0rgal Th0rgal merged commit 45b37e0 into main Feb 22, 2026
23 checks passed
@Th0rgal Th0rgal deleted the audit/address-mask-constant-and-fallback-fix branch February 22, 2026 03:04
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.

# Address mask constant sync
# ---------------------------------------------------------------------------

_ADDRESS_MASK: int = (2**160) - 1
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Unused _ADDRESS_MASK constant never referenced in check

Low Severity

_ADDRESS_MASK is defined at module scope but never referenced by check_address_mask_sync() or anything else. The analogous _ERROR_STRING_SELECTOR_SHIFTED constant is used for value validation in check_error_selector_sync(). This looks like the value-validation step was intended but omitted, leaving dead code and a weaker check than its error-selector counterpart.

Additional Locations (1)

Fix in Cursor Fix in Web

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