Skip to content

audit: extract selectorShift constant, add CI sync check#673

Merged
Th0rgal merged 1 commit into
mainfrom
audit/selector-shift-constant-and-ci-sync
Feb 22, 2026
Merged

audit: extract selectorShift constant, add CI sync check#673
Th0rgal merged 1 commit into
mainfrom
audit/selector-shift-constant-and-ci-sync

Conversation

@Th0rgal
Copy link
Copy Markdown
Member

@Th0rgal Th0rgal commented Feb 22, 2026

Summary

What changed

File Change
Compiler/ContractSpec.lean New public selectorShift; used in revertWithCustomError
Compiler/Codegen.lean New private selectorShift; used in buildSwitch
Compiler/Proofs/YulGeneration/Builtins.lean Comment linking to canonical definition
scripts/check_selectors.py New check_selector_shift_sync() validates 3-way 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
  • check_builtin_list_sync.py passes locally
  • Full CI (Lean build + Foundry tests)

🤖 Generated with Claude Code


Note

Low Risk
Constant extraction + CI check only; behavior should be unchanged aside from reducing risk of future constant drift in selector/custom-error encoding.

Overview
Extracts selectorShift (=224) into a named constant in ContractSpec, and mirrors it in Codegen and proof Builtins, replacing hard-coded 224 literals in selector extraction and custom error selector packing.

Extends scripts/check_selectors.py with a new CI validation to ensure selectorShift stays consistent across those three modules, and updates AUDIT.md to document the shared-constant decision and the new check.

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

The selector shift amount (224 = 256 - 32 bits) was hardcoded as bare
literals in Codegen.buildSwitch and ContractSpec.revertWithCustomError,
while the proof module had its own named `selectorShift` in Builtins.lean.

Define the canonical constant in ContractSpec.lean and named copies in
Codegen.lean and Builtins.lean (avoiding cross-module imports).  A new
CI check validates all three definitions 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 3:31am

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.


_SELECTOR_SHIFT_RE = re.compile(
r"def\s+selectorShift\s*:\s*Nat\s*:=\s*224"
)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Regex lacks trailing word boundary after value

Low Severity

_SELECTOR_SHIFT_RE ends with the bare literal 224 without a trailing word boundary (\b) or end-of-line anchor. Since re.search is used, a value like 2240 or 22400 would still match because 224 appears as a prefix. This undermines the sync check's purpose — it would silently accept an incorrect shift value. Adding \b or $ after 224 would ensure an exact match.

Fix in Cursor Fix in Web

@Th0rgal Th0rgal merged commit 65f6022 into main Feb 22, 2026
23 checks passed
@Th0rgal Th0rgal deleted the audit/selector-shift-constant-and-ci-sync branch February 22, 2026 03:35
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