From add8ccada113ac4c13007e89bb7d00bc3d5c86a7 Mon Sep 17 00:00:00 2001 From: marqdo-prove Date: Thu, 26 Nov 2026 11:28:04 +0800 Subject: [PATCH] prove: refute mutated program models and prove portable replay - bounded witness candidates are now also tried when the proposition contains program-model calls that Rust cannot evaluate; Lean's decide is the authority, so a mutated model refutes only with a kernel-verified negation (M07) - e2e: model mutation refuted; bundle replayed from a different checkout path - full acceptance run: 11 passed, 0 failed, 271.39 s - STATUS updated with the final evidence --- docs/STATUS.md | 6 ++++-- src/prove.rs | 34 +++++++++++++++++------------- tests/e2e.rs | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+), 16 deletions(-) diff --git a/docs/STATUS.md b/docs/STATUS.md index 0618cbd..cbcdd32 100644 --- a/docs/STATUS.md +++ b/docs/STATUS.md @@ -87,10 +87,12 @@ Observed results (wall clock, warm filesystem, debug build of Prove): | tampered `proof.ndjson` then `replay` | rejected with exit 2 (`certificate.invalid`), no `verified` | | `check tests/fixtures/unknown.mq.md` (`a^2+b^2 ≥ 2ab`) | `unknown`, exit 1 — search exhausted, no refutation invented | | exported bundle, then a prose-only edit in a dependency, then `replay` | `certificate.stale`, exit 1, no `verified` | +| program model mutated to `return x * x - 1` (goal `square(x) ≥ 0`) | `refuted` with a Lean-verified negation (witness `x = 0`), `scope=program_model` | +| bundle exported in one checkout, sources copied byte-identically to another absolute directory, `replay` there | `verified`, `current` — the certificate is bound to portable identities, not machine paths | | `marqdo tool install tool-bundle/tool.json` then `marqdo prove --version` and `marqdo prove check examples/algebra.mq.md --json` | installed tool dispatches through the real CLI Tool Protocol (`api_revision 1`), version `marqdo-prove 0.1.0`, target `verified` (cache hit, ~10 s) | Run as `cargo test --test e2e -- --ignored --test-threads=1` (requires -`MARQDO_BIN` and the fixed backend): **9 passed, 0 failed, 213.78 s**. +`MARQDO_BIN` and the fixed backend): **11 passed, 0 failed, 271.39 s**. ## Executed test suite @@ -106,7 +108,7 @@ cargo test # see counts below | `tests/analysis_document.rs` (real CLI, entry extraction) | 3 passed | | `tests/formula_contract.rs` (grammar, precedence, bounds, diagnostics, rendering, evaluation) | 12 passed | | `tests/document_contract.rs` (no-target, shape errors, unsupported/invalid formulas, missing/external links, cycles, `--unit`, upstream static failure, root escape) | 11 passed | -| `tests/e2e.rs` (Lean-backed, `#[ignore]`) | 9 passed, 213.78 s | +| `tests/e2e.rs` (Lean-backed, `#[ignore]`) | 11 passed, 271.39 s | ## Tool installation evidence diff --git a/src/prove.rs b/src/prove.rs index 0f6da88..fba27f1 100644 --- a/src/prove.rs +++ b/src/prove.rs @@ -1405,23 +1405,28 @@ fn build_hint_terms( terms } +/// Bounded counterexample candidates, in a deterministic order. +/// +/// A candidate is kept when the proposition is *not known true* at that +/// assignment. `evaluate` cannot see through program-model calls (it returns +/// `None`), so those assignments are kept as candidates too and Lean's `decide` +/// is the authority that accepts or rejects the negation. This is why a +/// modified program model can still be refuted, without executing it in Rust. fn counterexample_candidates(goal: Option<&Goal>) -> Vec> { let Some(goal) = goal else { return Vec::new(); }; const VALUES: [i64; 10] = [0, 1, -1, 2, -2, 3, -3, 5, -5, 10]; - let mut candidates = Vec::new(); if goal.vars.is_empty() { - if let Some(value) = goal.evaluate(&[]) { - if !value { - candidates.push(Vec::new()); - } - } - return candidates; + return match goal.evaluate(&[]) { + Some(true) => Vec::new(), + _ => vec![Vec::new()], + }; } if goal.vars.len() > 2 { - return candidates; + return Vec::new(); } + let mut candidates = Vec::new(); let mut budget = 16usize; for first in VALUES { for second in VALUES { @@ -1433,13 +1438,14 @@ fn counterexample_candidates(goal: Option<&Goal>) -> Vec> { } else { vec![BigInt::from(first), BigInt::from(second)] }; - if goal.vars.len() == 2 && first != 0 && second != 0 { - // Still evaluate; combinations are bounded by the budget. - } - if let Some(false) = goal.evaluate(&values) { - candidates.push(values); - budget -= 1; + if goal.evaluate(&values) == Some(true) { + if goal.vars.len() == 1 { + break; + } + continue; } + candidates.push(values); + budget -= 1; if goal.vars.len() == 1 { break; } diff --git a/tests/e2e.rs b/tests/e2e.rs index 9d1fd07..c28c731 100644 --- a/tests/e2e.rs +++ b/tests/e2e.rs @@ -273,3 +273,59 @@ fn stale_bundle_is_rejected_after_a_source_change() { "{report}" ); } + +#[test] +#[ignore] +fn mutated_program_model_is_refuted_not_verified() { + let directory = work("model-mutation"); + let project = directory.join("project"); + std::fs::create_dir_all(&project).expect("project dir"); + for file in ["algebra.mq.md", "arithmetic.mq.md"] { + std::fs::copy(repo().join("examples").join(file), project.join(file)).expect("copy"); + } + let entry = project.join("arithmetic.mq.md"); + let source = std::fs::read_to_string(&entry).expect("read"); + std::fs::write( + &entry, + source.replace("`return x * x`", "`return x * x - 1`"), + ) + .expect("mutate return"); + let (code, report) = check(&entry, &[]); + assert_eq!(code, 1, "{report}"); + assert_eq!(report["targets"][0]["outcome"], "refuted", "{report}"); + assert_eq!(report["targets"][0]["scope"], "program_model"); +} + +#[test] +#[ignore] +fn bundle_replays_from_a_different_checkout_directory() { + let first = work("clean-replay-a"); + let second = work("clean-replay-b"); + let bundle = first.join("bundle"); + for file in ["algebra.mq.md", "vector.mq.md"] { + std::fs::copy(repo().join("examples").join(file), first.join(file)).expect("copy"); + } + let (code, report) = check( + &first.join("vector.mq.md"), + &["--out", bundle.to_str().expect("utf8")], + ); + assert_eq!(code, 0, "{report}"); + // A different absolute checkout path with identical source bytes. + for file in ["algebra.mq.md", "vector.mq.md"] { + std::fs::copy(repo().join("examples").join(file), second.join(file)).expect("copy"); + } + let second_bundle = second.join("bundle"); + std::fs::create_dir_all(&second_bundle).expect("bundle dir"); + for file in ["manifest.json", "proof.ndjson"] { + std::fs::copy(bundle.join(file), second_bundle.join(file)).expect("copy bundle"); + } + let (code, replayed) = run(&[ + "replay", + second.join("vector.mq.md").to_str().expect("utf8"), + second_bundle.to_str().expect("utf8"), + "--json", + ]); + assert_eq!(code, 0, "{replayed}"); + assert_eq!(replayed["targets"][0]["outcome"], "verified", "{replayed}"); + assert_eq!(replayed["targets"][0]["freshness"], "current"); +}