-
Notifications
You must be signed in to change notification settings - Fork 64
fix(phl): emit the non-negativity of the bound as a separate goal in rnd (on #1105)
#1135
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
1
commit into
EasyCrypt:negative-phoare-false
Choose a base branch
from
Yiping106283:fix-phoare-rnd-nonneg
base: negative-phoare-false
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.
Open
Changes from all commits
Commits
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
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
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
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 |
|---|---|---|
|
|
@@ -212,6 +212,18 @@ module Core = struct | |
| let bd = {m;inv=f_local bd_id treal} in | ||
| bd, map_ss_inv2 f_eq (bhs_bd bhs) bd, [(bd_id,GTty treal)] | ||
| in | ||
| (* For [<=], the bound check [mu distr event <= bd] is lifted into the | ||
| post-condition of a (partial-correctness) hoare judgment on the prefix | ||
| [s], which only has to hold on terminating runs of [s]. That is sound | ||
| for the mass of the terminating runs, but the non-terminating runs of | ||
| [s] contribute probability 0 to the conclusion, which is bounded by | ||
| [bd] only if [bd] is non-negative. 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): emit [0 <= bd] as a separate | ||
| (last) goal, quantified over all memories, unconditionally. *) | ||
| let nonneg_concl = | ||
| f_forall_mems_ss_inv bhs.bhs_m | ||
| (map_ss_inv2 f_real_le {m;inv=f_r0} (bhs_bd bhs)) in | ||
| let subgoals = match tac_info, bhs.bhs_cmp with | ||
| | PNoRndParams, FHle -> | ||
| if is_post_indep then | ||
|
|
@@ -227,7 +239,7 @@ module Core = struct | |
| let post = POE.lift post in | ||
| let concl = f_hoareS (snd bhs.bhs_m) pre s post in | ||
| let concl = f_forall_simpl binders concl in | ||
| [concl] | ||
| [concl; nonneg_concl] | ||
| | PNoRndParams, _ -> | ||
| if is_post_indep then | ||
| (* event is true *) | ||
|
|
@@ -253,7 +265,7 @@ module Core = struct | |
| let post = POE.lift post in | ||
| let concl = f_hoareS (snd bhs.bhs_m) pre s post in | ||
| let concl = f_forall_simpl binders concl in | ||
| [concl] | ||
| [concl; nonneg_concl] | ||
| | PSingleRndParam event, _ -> | ||
| let event = event ty_distr in | ||
| let bounded_distr = map_ss_inv2 f_cmp (map_ss_inv2 (f_mu env) distr event) bound in | ||
|
|
@@ -682,7 +694,19 @@ let process_rnd | |
|
|
||
| | _ -> tc_error !!tc "invalid arguments" | ||
| in | ||
| t_bdhoare_rnd tac_info tc | ||
| (* For [<=] with an event, [t_bdhoare_rnd] emits the non-negativity of | ||
| the bound as a last, pure side-condition: try to close it so trivially | ||
| non-negative bounds stay effort-free (a genuinely negative bound is | ||
| left as an unprovable goal). *) | ||
| let t_side tc = | ||
| match (FApi.tc1_goal tc).f_node with | ||
| | FhoareS _ | FbdHoareS _ | FeHoareS _ | FequivS _ -> t_id tc | ||
| | _ -> FApi.t_try t_trivial tc in | ||
| let t_side = | ||
| match tac_info, (tc1_as_bdhoareS tc).bhs_cmp with | ||
| | (PNoRndParams | PSingleRndParam _), FHle -> t_side | ||
| | _ -> t_id in | ||
| FApi.t_last t_side (t_bdhoare_rnd tac_info 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 could be done directly inside the |
||
| | _, _, _ when is_equivS concl -> | ||
| let process_form f ty1 ty2 = | ||
|
|
||
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,52 @@ | ||
| (* pHL `rnd` with an upper bound (upstream #1119): the bound check is lifted | ||
| into the post-condition of a hoare judgment on the statements preceding | ||
| the sampling, which only constrains their terminating runs. The rule must | ||
| also require the bound to be non-negative; under #1105 a pHL judgment | ||
| with a bound that is negative in some memory is false, so that goal is | ||
| quantified over all memories, unconditionally: after the ordinary goal, | ||
| `0%r <= -1%r` must remain and must be unprovable. *) | ||
| require import AllCore Distr. | ||
|
|
||
| module M = { | ||
| proc f() : unit = { var x : int; while (true) { } x <$ dunit 0; } | ||
| }. | ||
|
|
||
| lemma bad : phoare[M.f : true ==> true] <= (-1)%r. | ||
| proof. | ||
| proc. | ||
| rnd (fun (_ : int) => true). | ||
| + by while (true); auto. | ||
| (* remaining goal: forall &hr, 0%r <= -1%r *) | ||
| move=> &hr. | ||
| fail (by smt()). | ||
| abort. | ||
|
|
||
| (* Same with the event inferred from the post-condition. *) | ||
| module N = { | ||
| proc f() : int = { var x : int; while (true) { } x <$ dunit 0; return x; } | ||
| }. | ||
|
|
||
| lemma bad' : phoare[N.f : true ==> res = 0] <= (-1)%r. | ||
| proof. | ||
| proc. | ||
| rnd. | ||
| + by while (true); auto. | ||
| (* remaining goal: forall &hr, 0%r <= -1%r *) | ||
| move=> &hr. | ||
| fail (by smt()). | ||
| abort. | ||
|
|
||
| (* Loop-free: the prefix terminates, but the bound is still negative. *) | ||
| module L = { | ||
| proc f() : unit = { var y : int; var x : int; y <$ dnull; x <$ dunit 0; } | ||
| }. | ||
|
|
||
| lemma bad'' : phoare[L.f : true ==> true] <= (-1)%r. | ||
| proof. | ||
| proc. | ||
| rnd (fun (_ : int) => true). | ||
| + by auto=> /> y; rewrite supp_dnull. | ||
| (* remaining goal: forall &hr, 0%r <= -1%r *) | ||
| move=> &hr. | ||
| fail (by smt()). | ||
| abort. |
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
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
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.
I would remove the above comment. It is at the wrong place and not clear. A comment can be added at line 242 and 268 to explain why bound check are added (a short clear one liner is ok).