Fix rewrite Pr [mu1_le_eq_mu1]: add missing memory-independence check#930
Open
LucianoXu wants to merge 3 commits intoEasyCrypt:mainfrom
Open
Fix rewrite Pr [mu1_le_eq_mu1]: add missing memory-independence check#930LucianoXu wants to merge 3 commits intoEasyCrypt:mainfrom
LucianoXu wants to merge 3 commits intoEasyCrypt:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR addresses a soundness bug in the mu1_le_eq_mu1 probability rewrite: rewriting Pr[... : res = k] into mu1 d k is unsound when k depends on the post-execution memory.
Changes:
- Added a check rejecting rewrites where the compared value
kdepends on the post-execution memory. - Added a similar post-memory dependency check for the distribution argument
d, emitting clearer critical errors.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
strub
requested changes
Mar 10, 2026
Member
|
Thanks. Here, the bug was already documented in the source code (don't ask me why). I think that we have a bunch of comments with FIXME like this. I suggest that you add this information to the prompt (i.e. "The EasyCrypt source code contains FIXME. Target them."). I can see more of them in the same file, and certainly in others. |
oskgo
reviewed
Mar 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
rewrite Pr [mu1_le_eq_mu1 d]is unsound when the valuekin the eventres = kdepends on the post-execution memory. This PR adds the missing check flagged by theFIXMEcomments atecPhlPrRw.ml:254-255.Proof of
falseThe following EasyCrypt file proves
falseby exploiting this bug:Before fix:
easycrypt compile -no-eco novel_prrw_false.ecexits 0 (provesfalse).After fix: exits 1 with error:
Root cause
The
mu1_le_eq_mu1rewrite transformsPr[M.f() @ &m : res = k]intomu1 d k. This is sound whenkis a constant (independent of the post-execution memory). But whenkreferences a global variable modified by the procedure (e.g.,N.x):res = N.xevaluatesN.xin the post-state, whereN.x = resalways holds → probability 1mu1 dbool N.xtreatsN.xas a constant (dangling memory reference) →1/21 = 1/2The source code already had
FIXMEcomments atecPhlPrRw.ml:254-255acknowledging the missing checks.Fix
Added checks that both
k(the value compared tores) andd(the distribution) have free variables disjoint from the post-execution memory identifier. If either depends on the post-memory, a clear error is emitted.Disclosure
This bug was discovered and this fix was authored with the assistance of Claude Code (Anthropic).
🤖 Generated with Claude Code