Repository navigation
Commit f098bd7
fix(phl): require the invariant on loop entry in the
Summary: `while I v` accepted `phoare[M.p : true ==> true] = 0%r` for
`while (b) {}` with the invariant `false` (upstream #1103): the bound was
derived only from the probability of reaching the loop with the invariant
satisfied.
Root cause (src/phl/ecPhlWhile.ml, `t_bdhoare_while_r`): from a memory
satisfying `I /\ G` (the invariant together with the generalized termination
and exit conditions), the loop terminates with probability 1 in a memory
satisfying the post-condition, so `Pr[s; while] >= Pr[s : I /\ G]` always
holds and the `>=` rule is sound. For `<=` and `=`, the runs of `s` that
reach the loop outside `I /\ G` contribute an unknown probability (the loop
may diverge or terminate anywhere), and the rule ignored them.
Fix: for `<=` and `=`, the rule emits the extra goal
`hoare[s : pre ==> I /\ G]` stating that no terminating run of `s` reaches
the loop outside the invariant, except when the bound is syntactically
`1%r` (then `Pr[..] <= 1%r` holds unconditionally, and `= 1%r` follows from
the `>=` direction), so that losslessness proofs keep their two goals. The
`while` tactic (`process_while`) tries `EcPhlAuto.t_pl_trivial` on the extra
goal so trivial cases stay effort-free. examples/MEE-CBC/FunctionalSpec.ec
relied on the unsound step (its invariant holds only when the sampled IV is
the right one): it is restructured with `seq` at the sampling, the `= 1%r`
branch going through the loop rule and the `= 0%r` branch through `hoare`.
Test: tests/phoare-while-vrnt-inv.ec (`fail (by while false 0)` for `=`,
`fail (by while false 0; auto)` for `<=`; `>=` and a `= 1%r` losslessness
proof still accepted).
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>while variant rule1 parent 311ba5d commit f098bd7
3 files changed
Lines changed: 101 additions & 23 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
469 | 469 | | |
470 | 470 | | |
471 | 471 | | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
472 | 505 | | |
473 | 506 | | |
474 | 507 | | |
475 | 508 | | |
476 | 509 | | |
477 | | - | |
478 | | - | |
479 | | - | |
480 | | - | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
481 | 513 | | |
482 | 514 | | |
483 | 515 | | |
484 | 516 | | |
485 | 517 | | |
486 | 518 | | |
487 | 519 | | |
488 | | - | |
489 | | - | |
490 | | - | |
491 | | - | |
492 | | - | |
493 | | - | |
494 | | - | |
495 | | - | |
496 | | - | |
497 | | - | |
498 | | - | |
499 | | - | |
500 | | - | |
501 | | - | |
502 | | - | |
503 | | - | |
504 | | - | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
505 | 525 | | |
506 | 526 | | |
507 | 527 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
149 | 149 | | |
150 | 150 | | |
151 | 151 | | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
152 | 167 | | |
153 | | - | |
| 168 | + | |
154 | 169 | | |
155 | 170 | | |
156 | 171 | | |
| |||
569 | 584 | | |
570 | 585 | | |
571 | 586 | | |
572 | | - | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
573 | 593 | | |
574 | 594 | | |
575 | 595 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
0 commit comments