Repository navigation
fix(phl): check the bound of the upper-bound while rule on all memories (on #1105)
#1130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Yiping106283
wants to merge
2
commits into
EasyCrypt:main
Choose a base branch
from
Yiping106283:fix-phoare-while-le-bound
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+78
−10
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -185,19 +185,39 @@ let t_bdhoare_while_rev_r inv tc = | |
| f_imp while_jgmt unfolded_while_jgmt | ||
| in | ||
|
|
||
| (* 2. Sub-goal *) | ||
| let rem_concl = | ||
| let modi = s_write env lp_body in | ||
| (* 2. Sub-goal: the prefix establishes the invariant *) | ||
| let rem_concl = f_hoareS mt b_pre rem_s (POE.lift inv) in | ||
|
|
||
| (* 3. Sub-goal: on exit with the post-condition, the bound is 1. | ||
| 4. Sub-goal: the bound is non-negative. | ||
|
|
||
| Both are conditions on the bound that justify the transformation, not | ||
| conditions on the behaviour of [rem_s]: they are needed for every memory | ||
| the loop may start from (3, 4) and, since a non-terminating run of | ||
| [rem_s] contributes probability 0 to the conclusion, for every memory | ||
| satisfying the pre-condition (4). They are therefore emitted quantified | ||
| over all memories and NOT inside the (partial-correctness) post-condition | ||
| of sub-goal 2, which only has to hold on terminating runs of [rem_s]. | ||
| Moreover a pHL judgment is false as soon as its bound is negative in | ||
| some memory (whether or not that memory satisfies the pre-condition), | ||
| so (4) is required unconditionally. *) | ||
| let exit_concl = | ||
| let term_post = map_ss_inv2 f_imp | ||
| (map_ss_inv2 f_and inv (map_ss_inv2 f_and (map_ss_inv1 f_not lp_guard) b_post)) | ||
| (map_ss_inv2 f_eq bound {m;inv=f_r1}) in | ||
| let term_post = generalize_mod_ss_inv env modi term_post in | ||
| let term_post = map_ss_inv2 f_and inv term_post in | ||
| let post = { hsi_m = term_post.m; hsi_inv = POE.empty term_post.inv; } in | ||
| f_hoareS mt b_pre rem_s post | ||
| EcSubst.f_forall_mems_ss_inv mem term_post | ||
| in | ||
|
|
||
| let nonneg_concl = | ||
| EcSubst.f_forall_mems_ss_inv mem | ||
| (map_ss_inv2 f_real_le {m;inv=f_r0} bound) | ||
| in | ||
|
|
||
| FApi.xmutate1_hyps tc `While [(hyps', body_concl); (hyps, rem_concl)] | ||
| FApi.xmutate1_hyps tc `While | ||
| [(hyps', body_concl ); | ||
| (hyps , rem_concl ); | ||
| (hyps , exit_concl ); | ||
| (hyps , nonneg_concl)] | ||
|
|
||
| (* -------------------------------------------------------------------- *) | ||
| (* Rule for = or >= *) | ||
|
|
@@ -580,7 +600,12 @@ let process_while side winfos tc = | |
| t_bdhoare_while_rev_geq phi vrnt k eps tc | ||
| | None, None -> | ||
| let _, phi = TTC.tc1_process_Xhl_formula tc phi in | ||
| t_bdhoare_while_rev phi tc | ||
| (* [t_bdhoare_while_rev] emits the bound side-conditions (exit | ||
| bound, non-negativity) as the last two goals; try to close them | ||
| automatically so trivial cases stay effort-free. *) | ||
| FApi.t_onalli | ||
| (function 2 | 3 -> FApi.t_try t_trivial | _ -> t_id) | ||
| (t_bdhoare_while_rev phi tc) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This changes can be put directly into |
||
|
|
||
| | None, Some _ -> | ||
| tc_error !!tc "invalid arguments" | ||
|
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| (* pHL `while` with an invariant only, upper bound (issue #1102): the | ||
| conditions on the bound (`inv /\ !e /\ post => bd = 1%r`, `0%r <= bd`) | ||
| must be goals quantified over all memories, not part of the | ||
| post-condition of the hoare judgment on the statements preceding the | ||
| loop, which a diverging prefix or a never-established invariant | ||
| discharges vacuously. Under #1105 a pHL judgment with a bound that is | ||
| negative in some memory is false, so the non-negativity goal is | ||
| unconditional. Here `0%r <= -1%r` must remain, unprovable. *) | ||
| require import AllCore Real. | ||
|
|
||
| module M = { proc p() = { while (true) {} } }. | ||
|
|
||
| lemma bad : phoare[M.p : true ==> false] <= (-1%r). | ||
| proof. | ||
| proc. | ||
| while (true). | ||
| + auto. | ||
| + done. | ||
| (* remaining goal: forall &hr, 0%r <= -1%r *) | ||
| move=> &hr. | ||
| fail (by smt()). | ||
| abort. | ||
|
|
||
| (* Invariant `false`, "established" by a diverging prefix: only the | ||
| non-negativity of the bound rejects it. *) | ||
| module N = { proc p() = { while (true) {} while (true) {} } }. | ||
|
|
||
| lemma bad' : phoare[N.p : true ==> false] <= (-1%r). | ||
| proof. | ||
| proc. | ||
| while false. | ||
| + auto. | ||
| + while true. | ||
| + done. | ||
| done. | ||
| (* remaining goal: forall &hr, 0%r <= -1%r *) | ||
| move=> &hr. | ||
| fail (by smt()). | ||
| abort. |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The above paragraph is confusing for me, and not very useful; maybe it can be removed. Just keep line 191 and 192, and place it at the correct position.