Skip to content

fix: align Lean justifiability overflow semantics - #597

Closed
ss1738 wants to merge 1 commit into
lambdaclass:lean-formalizationfrom
ss1738:draft/lean-justifiability-overflow
Closed

fix: align Lean justifiability overflow semantics#597
ss1738 wants to merge 1 commit into
lambdaclass:lean-formalizationfrom
ss1738:draft/lean-justifiability-overflow

Conversation

@ss1738

@ss1738 ss1738 commented Aug 28, 2026

Copy link
Copy Markdown

Context

While extending the existing justifiability formalization, I found a
fixed-width arithmetic boundary outside the current proof domain.

For delta = 2^62 + 2, the previous Lean implementation returned true
because UInt64 wrapping reduced 4 * delta + 1 to 9, satisfying the
odd-square check. The corresponding mathematical delta is neither square nor
pronic.

Change

The Lean implementation now evaluates the pronic branch only when
4 * delta + 1 fits in UInt64, matching the checked-arithmetic structure in
the native Rust source.

Regression proofs cover values around the overflow boundary.

Proof contract

justifiable_equiv remains explicitly bounded by d.toNat < 2^62.
This PR does not strengthen that theorem to a total equivalence result.

The Rust-side documentation has also been updated to state the actual proof
domain rather than claiming correctness for all natural numbers.

Testing

  • cd formal && lake build EthLambdaProofs
  • regression cases for 2^62 - 1, 2^62, 2^62 + 2, and UInt64::MAX

@ss1738
ss1738 force-pushed the draft/lean-justifiability-overflow branch from c009c09 to d0848b3 Compare August 28, 2026 15:22
@ss1738 ss1738 changed the title formal: align Lean justifiability overflow semantics fix: align Lean justifiability overflow semantics Aug 28, 2026
@ss1738
ss1738 marked this pull request as ready for review September 5, 2026 02:21
|| isqrt delta ^ 2 == delta
|| (let val := 4 * delta + 1
isqrt val ^ 2 == val && val % 2 == 1)
|| if delta <= 4611686018427387903 then

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We should make this work correctly with all values if possible, otherwise just leaving it at < 2**62 like before is enough. Making this return a fixed wrong result, true or false, isn't really a fix here.

@MegaRedHand

Copy link
Copy Markdown
Collaborator

We're not currently accepting PRs to the lean-formalization branch. As I mentioned in Telegram, the Lean4 formalization is expected to land on the leanSpec repo, so the PR should go there. Feel free to use the code in lean-formalization as the base, however, or ask us for feedback.

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.

3 participants