Keep "X is in the collection" inside a FOR EACH pass, not on the way out
The way out of a FOR EACH loop includes the case of no pass at all, but the checker added "X is in the collection" to the loop's head state and then used that same state as the way out. After a loop over an empty list the fact is FALSE, so the checker held a contradiction and proved anything after the loop, ASSERT 1 == 2 included (tests/prover/foreach-empty.pseudo). The fact is now assumed only for the body of a pass. The soundness test gains a canary: after every program that runs to its end without input, ASSERT 1 == 2 is appended and must not be proved, since a proof there means a contradiction on a path every run takes. A one-off scan with the canary after every top-level statement of every program (476 points) found nothing else. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FgvbRdoEheAHqsRmr2WuKZ
This commit is contained in:
3 files changed
+48
-3
No files matched your search
@@ -123,3 +123,30 @@ test('nothing the prover proves is broken by a run or by generated inputs', () =
|
||||
assert.ok(proved >= 150, `only ${proved} proved obligations were checked`);
|
||||
assert.deepEqual(problems, []);
|
||||
});
|
||||
|
||||
test('canary: after a program that runs to its end, ASSERT 1 == 2 is never proved', () => {
|
||||
// A false claim proved at a point every run reaches means the checker holds a contradiction
|
||||
// there: some rule assumed a fact a run can break. This finds such a rule even when no
|
||||
// program happens to assert something false after it (tests/prover/foreach-empty.pseudo).
|
||||
const problems = [];
|
||||
let canaries = 0;
|
||||
for (const p of programs()) {
|
||||
const st = studyOf(p.src);
|
||||
if (!st.ok || /^\s*INPUT\b/m.test(p.src)) continue;
|
||||
let run;
|
||||
try { run = runPseudo(st, {}); } catch { continue; }
|
||||
if (run.error || run.truncated) continue;
|
||||
const lines = p.src.replace(/\s+$/, '').split('\n');
|
||||
const line = lines.length + 1;
|
||||
const withCanary = studyOf(`${lines.join('\n')}\nASSERT 1 == 2\n`);
|
||||
if (!withCanary.ok) continue;
|
||||
const r = verify(withCanary.program.program, { budgetMs: 3000 });
|
||||
const main = r.units.find((u) => u.kind === 'main');
|
||||
const o = main?.obligations.find((x) => x.kind === 'assert' && x.line === line);
|
||||
if (!o) continue;
|
||||
canaries++;
|
||||
if (o.status === 'proved') problems.push(`${p.name}: ASSERT 1 == 2 after the last line is proved`);
|
||||
}
|
||||
assert.ok(canaries >= 60, `only ${canaries} programs carried a canary`);
|
||||
assert.deepEqual(problems, []);
|
||||
});
|
||||
@@ -0,0 +1,13 @@
|
||||
// The way out of a FOR EACH loop includes the case of no pass at all. A
|
||||
// checker that kept "X is in Xs" on the way out held FALSE after looping over
|
||||
// an empty list, and proved anything, even 1 == 2.
|
||||
// MUST-NOT-PROVE: assert@12
|
||||
DECLARE Xs : LIST OF INTEGER
|
||||
DECLARE S : INTEGER
|
||||
Xs <- []
|
||||
S <- 0
|
||||
FOR EACH X IN Xs
|
||||
S <- S + X
|
||||
NEXT X
|
||||
ASSERT 1 == 2
|
||||
OUTPUT S
|
||||
Reference in new issue
Block a user