Audit pass: full-corpus evidence, full-gate mutation, 3-way metamorphic, recomputable causal, bundle attestation
1 (artifact bundle): ci_reports writes evidence/MANIFEST.tsv (content hash+len of every evidence file); attestation verifies completeness+integrity; merge-gates requires the bundle. 2 (every leaf full evidence): run_all_to streams a full trace+delta record for EVERY leaf (base 'b' and perturbation 'p'), not a sample. 3 (attestation completeness): attestation enforces a leaf<->trace bijection (traces == leaves and covered set == leaf set), not just consistency. 4 (collapse derives from full traces): trace_feature_row single-sourced into collapse_analysis; attestation recomputes each collapse row from the retained full trace and requires bit-exact match. 5 (mutants through full gates): evaluate_mutants runs each mutant through engine_acceptance over 128 generated cases (trace/equivalence/domain/ metamorphic/causal), replacing the 64-input local predicates. 6 (trace+delta+future): metamorphic enforces consumed->trace per-case plus consumed-aggregate delta (>=0.65) and future (>=0.80) rates. 7 (recomputable causal): per-edge intervention records written to evidence/causal_evidence.tsv; attestation RE-EXECUTES each from its seed and recomputes base_dv/alt_dv. 8 (no string/comment proof): removed web_assets JS-substring test and the tautological string assert in ci_reports. Verified at fast scale end-to-end: 6600/6600 traces reconstructed, leaf bijection, 1600/1600 causal records recomputed, 600/600 collapse rows derived, bundle intact. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
+272
-200
@@ -22,7 +22,7 @@ use reference_runtime::{
|
||||
canonical, execute, Canonical, EngineConfig, ResolutionInput, ResolutionResult, Runtime,
|
||||
};
|
||||
use runtime_under_test::{native_resolve, RuntimeUnderTest};
|
||||
use semantic_mutation::{generate_mutants, DetectionClass, MutationOutcome};
|
||||
use semantic_mutation::{generate_mutants, MutationOutcome};
|
||||
use std::collections::HashMap;
|
||||
use std::io::Write;
|
||||
use world_model::{
|
||||
@@ -211,23 +211,39 @@ pub fn causal_trace_fails(median_edges: f64, p95_rank: f64) -> bool {
|
||||
median_edges < TRACE_EDGES_MIN || p95_rank < TRACE_RANK_P95_MIN
|
||||
}
|
||||
|
||||
/// Per-config causal gate over an input corpus (used to kill mutants by the same
|
||||
/// predicate the acceptance trace gate uses).
|
||||
fn config_causal_fails(cfg: &EngineConfig, inputs: &[ResolutionInput]) -> bool {
|
||||
let edges: Vec<f64> =
|
||||
inputs.iter().map(|i| execute(cfg, i).trace.causal_edge_count() as f64).collect();
|
||||
let ranks: Vec<f64> =
|
||||
inputs.iter().map(|i| execute(cfg, i).trace.causal_rank() as f64).collect();
|
||||
causal_trace_fails(median(&edges), percentile(&ranks, 0.05))
|
||||
}
|
||||
/// Number of generated cases each mutant is run through (a real corpus, not a
|
||||
/// fixed 64-input local sample).
|
||||
pub const MUTATION_GATE_CASES: usize = 128;
|
||||
|
||||
/// Per-config domain-participation gate over an input corpus.
|
||||
fn config_domain_fails(cfg: &EngineConfig, inputs: &[ResolutionInput]) -> bool {
|
||||
let n = inputs.len().max(1) as f64;
|
||||
/// Run an engine config through the FULL set of engine-behavior acceptance gates
|
||||
/// over `n_cases` freshly generated cases (the same gate functions and corpus
|
||||
/// shape the acceptance run uses) and return the names of the gates it fails.
|
||||
/// The reference returns an empty vec; a broken engine returns the gates that
|
||||
/// catch it.
|
||||
pub fn engine_acceptance(cfg: &EngineConfig, n_cases: usize) -> Vec<String> {
|
||||
let refcfg = EngineConfig::reference();
|
||||
let mut edges = Vec::with_capacity(n_cases);
|
||||
let mut ranks = Vec::with_capacity(n_cases);
|
||||
let mut equiv_fail = false;
|
||||
let mut appears = [0u64; NUM_DOMAINS];
|
||||
let mut mutated = [0u64; NUM_DOMAINS];
|
||||
for i in inputs {
|
||||
let r = execute(cfg, i);
|
||||
let mut influence_changed = [false; NUM_DOMAINS];
|
||||
let mut consumed = 0usize;
|
||||
let mut consumed_trace_violation = 0usize;
|
||||
let mut consumed_delta = 0usize;
|
||||
let mut consumed_future = 0usize;
|
||||
let n = n_cases.max(1) as f64;
|
||||
|
||||
for i in 0..n_cases {
|
||||
let (case, _) = generate_accepted_case(case_seed(i));
|
||||
let input = input_from_case(&case);
|
||||
let r = execute(cfg, &input);
|
||||
let rr = execute(&refcfg, &input);
|
||||
edges.push(r.trace.causal_edge_count() as f64);
|
||||
ranks.push(r.trace.causal_rank() as f64);
|
||||
if canonical(&r) != canonical(&rr) {
|
||||
equiv_fail = true;
|
||||
}
|
||||
for d in 0..NUM_DOMAINS {
|
||||
if r.trace.read_graph.access_count[d] > 0 || r.trace.write_graph.access_count[d] > 0 {
|
||||
appears[d] += 1;
|
||||
@@ -238,86 +254,90 @@ fn config_domain_fails(cfg: &EngineConfig, inputs: &[ResolutionInput]) -> bool {
|
||||
mutated[dd.domain.0 as usize] += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
(0..NUM_DOMAINS).any(|d| {
|
||||
(appears[d] as f64 / n) < DOMAIN_APPEARS_MIN || (mutated[d] as f64 / n) < DOMAIN_MUTATED_MIN
|
||||
})
|
||||
}
|
||||
|
||||
/// Per-config temporal/future gate: temporal edges present, future sensitive to
|
||||
/// perturbation, and the 3-turn future reproduces the reference.
|
||||
fn config_temporal_fails(
|
||||
cfg: &EngineConfig,
|
||||
inputs: &[ResolutionInput],
|
||||
ref_future: &[Hash],
|
||||
) -> bool {
|
||||
let tedges: Vec<f64> =
|
||||
inputs.iter().map(|i| execute(cfg, i).trace.temporal_graph.edge_count() as f64).collect();
|
||||
if median(&tedges) < 1.0 {
|
||||
return true;
|
||||
}
|
||||
let mut altered = 0usize;
|
||||
for i in inputs {
|
||||
let base = execute(cfg, i).replay.future_hash;
|
||||
let mut p = i.clone();
|
||||
p.world.domains[0].observed[0] = p.world.domains[0].observed[0].wrapping_add(101);
|
||||
p.world.mark_perturbed();
|
||||
if execute(cfg, &p).replay.future_hash != base {
|
||||
altered += 1;
|
||||
// Per-domain measured influence: masking each domain in `cfg` must change
|
||||
// this config's own output.
|
||||
let base_h = (r.trace.canonical_hash(), r.delta.hash());
|
||||
for d in 0..NUM_DOMAINS {
|
||||
if influence_changed[d] {
|
||||
continue;
|
||||
}
|
||||
let mut mc = cfg.clone();
|
||||
mc.domain_mask[d] = false;
|
||||
let m = execute(&mc, &input);
|
||||
if (m.trace.canonical_hash(), m.delta.hash()) != base_h {
|
||||
influence_changed[d] = true;
|
||||
}
|
||||
}
|
||||
// Metamorphic over this case's perturbations.
|
||||
let bt = r.trace.canonical_hash();
|
||||
let bd = r.delta.hash();
|
||||
let bf = r.replay.future_hash;
|
||||
for pc in &case.perturbations {
|
||||
let pin = input_with_world(&case, pc.world.clone());
|
||||
let pr = execute(cfg, &pin);
|
||||
let read = r.trace.read_graph.access_count[pc.target_domain % NUM_DOMAINS] > 0;
|
||||
if read {
|
||||
consumed += 1;
|
||||
if pr.delta.hash() != bd {
|
||||
consumed_delta += 1;
|
||||
}
|
||||
if pr.replay.future_hash != bf {
|
||||
consumed_future += 1;
|
||||
}
|
||||
if pc.expectation.expect_trace_change
|
||||
&& pr.trace.canonical_hash() == bt
|
||||
&& pc.expectation.neutral_explanation.is_none()
|
||||
{
|
||||
consumed_trace_violation += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (altered as f64 / inputs.len().max(1) as f64) < FUTURE_ALT_MIN {
|
||||
return true;
|
||||
|
||||
let mut fails = Vec::new();
|
||||
if causal_trace_fails(median(&edges), percentile(&ranks, 0.05)) {
|
||||
fails.push("causal_rank/trace".to_string());
|
||||
}
|
||||
inputs
|
||||
.iter()
|
||||
.zip(ref_future)
|
||||
.any(|(i, rf)| execute(cfg, i).replay.future_hash != *rf)
|
||||
if equiv_fail {
|
||||
fails.push("runtime_equivalence".to_string());
|
||||
}
|
||||
if (0..NUM_DOMAINS).any(|d| {
|
||||
(appears[d] as f64 / n) < DOMAIN_APPEARS_MIN
|
||||
|| (mutated[d] as f64 / n) < DOMAIN_MUTATED_MIN
|
||||
|| !influence_changed[d]
|
||||
}) {
|
||||
fails.push("domain_participation".to_string());
|
||||
}
|
||||
let mc = consumed.max(1) as f64;
|
||||
if consumed == 0
|
||||
|| (consumed_trace_violation as f64 / mc) > 0.01
|
||||
|| (consumed_delta as f64 / mc) < CONSUMED_DELTA_MIN
|
||||
|| (consumed_future as f64 / mc) < CONSUMED_FUTURE_MIN
|
||||
{
|
||||
fails.push("metamorphic_response".to_string());
|
||||
}
|
||||
let ce = causal_explanation_gate(cfg, n_cases, 4);
|
||||
if !ce.failures.is_empty() {
|
||||
fails.push("causal_explanation".to_string());
|
||||
}
|
||||
fails
|
||||
}
|
||||
|
||||
/// Per-config equivalence gate: the config diverges from the reference canonical
|
||||
/// view on at least one input.
|
||||
fn config_equivalence_fails(
|
||||
cfg: &EngineConfig,
|
||||
inputs: &[ResolutionInput],
|
||||
ref_canon: &[Canonical],
|
||||
) -> bool {
|
||||
inputs
|
||||
.iter()
|
||||
.zip(ref_canon)
|
||||
.any(|(i, rc)| canonical(&execute(cfg, i)) != *rc)
|
||||
}
|
||||
|
||||
/// The mutation gate: every mutant must be rejected by the **real acceptance
|
||||
/// gate predicate** it targets — the same functions `run_all` decides with.
|
||||
pub fn evaluate_mutants(count: usize, inputs: &[ResolutionInput]) -> MutationOutcome {
|
||||
let refcfg = EngineConfig::reference();
|
||||
let ref_canon: Vec<Canonical> = inputs.iter().map(|i| canonical(&execute(&refcfg, i))).collect();
|
||||
let ref_future: Vec<Hash> = inputs.iter().map(|i| execute(&refcfg, i).replay.future_hash).collect();
|
||||
/// The mutation gate: every mutant must be rejected by the FULL engine-behavior
|
||||
/// acceptance gates over a real generated-case corpus (not 64 fixed inputs).
|
||||
pub fn evaluate_mutants(count: usize, _inputs: &[ResolutionInput]) -> MutationOutcome {
|
||||
let mutants = generate_mutants(count);
|
||||
let mut killed = 0;
|
||||
let mut survivors = Vec::new();
|
||||
for m in &mutants {
|
||||
let rejected = match m.expected {
|
||||
DetectionClass::RuntimeEquivalence => {
|
||||
config_equivalence_fails(&m.config, inputs, &ref_canon)
|
||||
}
|
||||
DetectionClass::CausalGate => config_causal_fails(&m.config, inputs),
|
||||
DetectionClass::TemporalGate => config_temporal_fails(&m.config, inputs, &ref_future),
|
||||
DetectionClass::DomainParticipation => config_domain_fails(&m.config, inputs),
|
||||
};
|
||||
if rejected {
|
||||
killed += 1;
|
||||
} else {
|
||||
let fails = engine_acceptance(&m.config, MUTATION_GATE_CASES);
|
||||
if fails.is_empty() {
|
||||
survivors.push((
|
||||
m.id,
|
||||
format!(
|
||||
"mutant {} ({}) not rejected by the real acceptance gate {}",
|
||||
m.id,
|
||||
m.name,
|
||||
m.expected.name()
|
||||
),
|
||||
format!("mutant {} ({}) passed all acceptance gates", m.id, m.name),
|
||||
));
|
||||
} else {
|
||||
killed += 1;
|
||||
}
|
||||
}
|
||||
MutationOutcome { total: mutants.len(), killed, survivors }
|
||||
@@ -476,50 +496,11 @@ fn compressibility(features: &[i64]) -> f64 {
|
||||
(1.0 - h / 8.0).clamp(0.0, 1.0)
|
||||
}
|
||||
|
||||
/// Real serialized-trace feature row used by the collapse analysis. Layout per
|
||||
/// domain block (width 9): `[infl_out, infl_in, flow_out, flow_in, read, write,
|
||||
/// temporal, obs_delta, hid_delta]`, followed by globals `[causal_rank,
|
||||
/// edge_count, touched, divergence_mean]`. This is genuine trace structure, not
|
||||
/// a hash-derived proxy.
|
||||
/// Trace feature row used by the collapse analysis — the single definition lives
|
||||
/// in `collapse_analysis::trace_feature_row` so the attestor can recompute the
|
||||
/// same row from the retained full trace and prove the summary derives from it.
|
||||
fn trace_feature_row(r: &ResolutionResult) -> Vec<f64> {
|
||||
let infl = r.trace.causal_graph.influence_matrix();
|
||||
let mut flow = [[0.0f64; NUM_DOMAINS]; NUM_DOMAINS];
|
||||
for &(a, b, bits) in &r.trace.information_flow.edges {
|
||||
flow[a as usize % NUM_DOMAINS][b as usize % NUM_DOMAINS] += bits as f64;
|
||||
}
|
||||
let mut temporal = [0.0f64; NUM_DOMAINS];
|
||||
for &(_s, _off, d) in &r.trace.temporal_graph.edges {
|
||||
temporal[d as usize % NUM_DOMAINS] += 1.0;
|
||||
}
|
||||
|
||||
let mut row = Vec::with_capacity(FEATURE_W);
|
||||
for d in 0..NUM_DOMAINS {
|
||||
let infl_out: f64 = (0..NUM_DOMAINS).map(|j| infl[d][j]).sum();
|
||||
let infl_in: f64 = (0..NUM_DOMAINS).map(|i| infl[i][d]).sum();
|
||||
let flow_out: f64 = (0..NUM_DOMAINS).map(|j| flow[d][j]).sum();
|
||||
let flow_in: f64 = (0..NUM_DOMAINS).map(|i| flow[i][d]).sum();
|
||||
let read = r.trace.read_graph.access_count[d] as f64;
|
||||
let write = r.trace.write_graph.access_count[d] as f64;
|
||||
let temp = temporal[d];
|
||||
let obs_delta: f64 = r.delta.domain_deltas[d]
|
||||
.observed
|
||||
.iter()
|
||||
.map(|&v| (v as f64).abs())
|
||||
.sum();
|
||||
let hid_delta: f64 = r.delta.domain_deltas[d]
|
||||
.hidden
|
||||
.iter()
|
||||
.map(|&v| (v as f64).abs())
|
||||
.sum();
|
||||
row.extend_from_slice(&[
|
||||
infl_out, infl_in, flow_out, flow_in, read, write, temp, obs_delta, hid_delta,
|
||||
]);
|
||||
}
|
||||
row.push(r.trace.causal_rank() as f64);
|
||||
row.push(r.trace.causal_edge_count() as f64);
|
||||
row.push(r.trace.touched_domain_count() as f64);
|
||||
row.push(r.trace.context_divergence());
|
||||
row
|
||||
collapse_analysis::trace_feature_row(&r.trace, &r.delta)
|
||||
}
|
||||
|
||||
/// Outcome of checking a perturbation's **declared** metamorphic expectation
|
||||
@@ -552,6 +533,8 @@ pub fn metamorphic_outcome(
|
||||
if exp.expect_trace_change && perturbed_domain_read {
|
||||
if trace_changed {
|
||||
ExpectationOutcome::Upheld
|
||||
} else if exp.neutral_explanation.is_some() {
|
||||
ExpectationOutcome::ExplainedNeutral
|
||||
} else {
|
||||
ExpectationOutcome::Violation
|
||||
}
|
||||
@@ -562,6 +545,13 @@ pub fn metamorphic_outcome(
|
||||
}
|
||||
}
|
||||
|
||||
/// Consumed-perturbation aggregate thresholds for delta/future. Per-case strict
|
||||
/// enforcement of delta/future is unsound (clamping and masking legitimately
|
||||
/// leave them unchanged), so these are enforced as fractions over the consumed
|
||||
/// perturbations. Reference rates measured at ~0.77 (delta) and ~0.90 (future).
|
||||
pub const CONSUMED_DELTA_MIN: f64 = 0.65;
|
||||
pub const CONSUMED_FUTURE_MIN: f64 = 0.80;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Result aggregates.
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -611,6 +601,9 @@ pub struct MetamorphicGates {
|
||||
/// Count of perturbations the program actually consumed (gate is vacuous
|
||||
/// without these).
|
||||
pub consumed: usize,
|
||||
/// Fraction of consumed perturbations that changed the delta / the future.
|
||||
pub consumed_delta_rate: f64,
|
||||
pub consumed_future_rate: f64,
|
||||
pub failures: Vec<String>,
|
||||
}
|
||||
|
||||
@@ -665,6 +658,10 @@ pub struct CiResults {
|
||||
/// replay-record leaf, and checks the leaf is in `merkle_leaves` — proving
|
||||
/// the leaves are backed by full trace structure, not a summary.
|
||||
pub trace_evidence: Vec<TraceEvidence>,
|
||||
/// The collapse feature rows, in the same order as the first base executions
|
||||
/// in the trace evidence, so the attestor can recompute each from the full
|
||||
/// trace and prove the summary derives from it (finding 4).
|
||||
pub collapse_feature_rows: Vec<Vec<f64>>,
|
||||
}
|
||||
|
||||
/// One sampled full-trace evidence record.
|
||||
@@ -755,6 +752,8 @@ pub fn run_all_to(scale: Scale, mut evidence_sink: Option<&mut dyn Write>) -> Ci
|
||||
let mut meta_expect_violation = 0usize;
|
||||
let mut meta_explained_neutral = 0usize;
|
||||
let mut meta_consumed = 0usize;
|
||||
let mut meta_consumed_delta = 0usize;
|
||||
let mut meta_consumed_future = 0usize;
|
||||
let mut min_perturbations = usize::MAX;
|
||||
|
||||
let mut contract_pass = 0usize;
|
||||
@@ -814,11 +813,13 @@ pub fn run_all_to(scale: Scale, mut evidence_sink: Option<&mut dyn Write>) -> Ci
|
||||
let mut c_expect_violation = 0usize;
|
||||
let mut c_explained_neutral = 0usize;
|
||||
let mut c_consumed = 0usize;
|
||||
let mut c_consumed_delta = 0usize;
|
||||
let mut c_consumed_future = 0usize;
|
||||
let mut c_pert = 0usize;
|
||||
// Capture each perturbation execution so the committed case can run
|
||||
// the full 100% reference/runtime comparison without recomputing the
|
||||
// reference side.
|
||||
let mut pert_execs: Vec<(ResolutionInput, Canonical, Hash)> = Vec::new();
|
||||
let mut pert_execs: Vec<(ResolutionInput, Canonical, Hash, String)> = Vec::new();
|
||||
for pc in &case.perturbations {
|
||||
let pinput = input_with_world(&case, pc.world.clone());
|
||||
let pr = execute(&cfg, &pinput);
|
||||
@@ -842,13 +843,32 @@ pub fn run_all_to(scale: Scale, mut evidence_sink: Option<&mut dyn Write>) -> Ci
|
||||
r.trace.read_graph.access_count[pc.target_domain % NUM_DOMAINS] > 0;
|
||||
if perturbed_read {
|
||||
c_consumed += 1;
|
||||
if ad {
|
||||
c_consumed_delta += 1;
|
||||
}
|
||||
if af {
|
||||
c_consumed_future += 1;
|
||||
}
|
||||
}
|
||||
match metamorphic_outcome(&pc.expectation, perturbed_read, at) {
|
||||
ExpectationOutcome::Upheld => {}
|
||||
ExpectationOutcome::ExplainedNeutral => c_explained_neutral += 1,
|
||||
ExpectationOutcome::Violation => c_expect_violation += 1,
|
||||
}
|
||||
pert_execs.push((pinput, canonical(&pr), pr.replay.hash()));
|
||||
// Full-trace evidence line for THIS perturbation leaf (finding 2):
|
||||
// every leaf, base and perturbation, carries a recomputable trace.
|
||||
let pline = format!(
|
||||
"p {:016x} {:016x} {:016x} {:016x} {:016x} {:016x}\t{}\t{}",
|
||||
pr.replay.world_seed,
|
||||
pr.replay.program_seed,
|
||||
pr.replay.contract_seed,
|
||||
pr.replay.perturbation_seed,
|
||||
pr.replay.future_hash.0,
|
||||
pr.replay.hash().0,
|
||||
pr.trace.serialize(),
|
||||
pr.delta.serialize(),
|
||||
);
|
||||
pert_execs.push((pinput, canonical(&pr), pr.replay.hash(), pline));
|
||||
}
|
||||
let future_sensitivity = if c_pert > 0 {
|
||||
c_alt_future as f64 / c_pert as f64
|
||||
@@ -901,7 +921,7 @@ pub fn run_all_to(scale: Scale, mut evidence_sink: Option<&mut dyn Write>) -> Ci
|
||||
if let Some(w) = evidence_sink.as_deref_mut() {
|
||||
let _ = writeln!(
|
||||
w,
|
||||
"{:016x} {:016x} {:016x} {:016x} {:016x} {:016x}\t{}\t{}",
|
||||
"b {:016x} {:016x} {:016x} {:016x} {:016x} {:016x}\t{}\t{}",
|
||||
r.replay.world_seed,
|
||||
r.replay.program_seed,
|
||||
r.replay.contract_seed,
|
||||
@@ -919,7 +939,7 @@ pub fn run_all_to(scale: Scale, mut evidence_sink: Option<&mut dyn Write>) -> Ci
|
||||
delta: r.delta.clone(),
|
||||
});
|
||||
}
|
||||
for (pinput, pref_canon, pleaf) in &pert_execs {
|
||||
for (pinput, pref_canon, pleaf, pline) in &pert_execs {
|
||||
let prut = rut.resolve(pinput.clone());
|
||||
equiv_total += 1;
|
||||
if *pref_canon == canonical(&prut) {
|
||||
@@ -929,6 +949,9 @@ pub fn run_all_to(scale: Scale, mut evidence_sink: Option<&mut dyn Write>) -> Ci
|
||||
.push(format!("case {} (perturbation) reference != runtime_under_test", i));
|
||||
}
|
||||
merkle_leaves.push(*pleaf);
|
||||
if let Some(w) = evidence_sink.as_deref_mut() {
|
||||
let _ = writeln!(w, "{}", pline);
|
||||
}
|
||||
}
|
||||
|
||||
actual_executions += 1;
|
||||
@@ -964,6 +987,8 @@ pub fn run_all_to(scale: Scale, mut evidence_sink: Option<&mut dyn Write>) -> Ci
|
||||
meta_expect_violation += c_expect_violation;
|
||||
meta_explained_neutral += c_explained_neutral;
|
||||
meta_consumed += c_consumed;
|
||||
meta_consumed_delta += c_consumed_delta;
|
||||
meta_consumed_future += c_consumed_future;
|
||||
perturbation_runs += c_pert;
|
||||
min_perturbations = min_perturbations.min(c_pert);
|
||||
|
||||
@@ -1094,11 +1119,27 @@ pub fn run_all_to(scale: Scale, mut evidence_sink: Option<&mut dyn Write>) -> Ci
|
||||
r_violation
|
||||
));
|
||||
}
|
||||
// Non-vacuity: the relation must actually be exercised — there must be
|
||||
// perturbations the program consumed for the enforcement to mean anything.
|
||||
if meta_total > 0 && meta_consumed == 0 {
|
||||
meta_failures.push("metamorphic enforcement vacuous: no consumed perturbations".into());
|
||||
}
|
||||
// Delta and future expectations: per-case strict enforcement is unsound
|
||||
// (clamping/masking), so enforce them as fractions over consumed
|
||||
// perturbations.
|
||||
let mc = meta_consumed.max(1) as f64;
|
||||
let consumed_delta_rate = meta_consumed_delta as f64 / mc;
|
||||
let consumed_future_rate = meta_consumed_future as f64 / mc;
|
||||
if consumed_delta_rate < CONSUMED_DELTA_MIN {
|
||||
meta_failures.push(format!(
|
||||
"consumed-perturbation delta-change rate {:.4} < {}",
|
||||
consumed_delta_rate, CONSUMED_DELTA_MIN
|
||||
));
|
||||
}
|
||||
if consumed_future_rate < CONSUMED_FUTURE_MIN {
|
||||
meta_failures.push(format!(
|
||||
"consumed-perturbation future-change rate {:.4} < {}",
|
||||
consumed_future_rate, CONSUMED_FUTURE_MIN
|
||||
));
|
||||
}
|
||||
let metamorphic = MetamorphicGates {
|
||||
total: meta_total,
|
||||
altered_trace: r_trace,
|
||||
@@ -1107,6 +1148,8 @@ pub fn run_all_to(scale: Scale, mut evidence_sink: Option<&mut dyn Write>) -> Ci
|
||||
expectation_violations: r_violation,
|
||||
explained_neutral: r_explained,
|
||||
consumed: meta_consumed,
|
||||
consumed_delta_rate,
|
||||
consumed_future_rate,
|
||||
failures: meta_failures,
|
||||
};
|
||||
|
||||
@@ -1116,7 +1159,7 @@ pub fn run_all_to(scale: Scale, mut evidence_sink: Option<&mut dyn Write>) -> Ci
|
||||
|
||||
// ---- Collapse gates (real trace information) ----
|
||||
progress!("collapse analysis (11 attacks over real trace features)...");
|
||||
let corpus = BehaviorCorpus::build(collapse_rows);
|
||||
let corpus = BehaviorCorpus::build(collapse_rows.clone());
|
||||
let collapse = analyze(&corpus);
|
||||
|
||||
// ---- Mutation gates (killed by named gate) ----
|
||||
@@ -1262,6 +1305,7 @@ pub fn run_all_to(scale: Scale, mut evidence_sink: Option<&mut dyn Write>) -> Ci
|
||||
coverage,
|
||||
merkle_leaves: retained_leaves,
|
||||
trace_evidence,
|
||||
collapse_feature_rows: collapse_rows,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1279,6 +1323,31 @@ pub struct CausalExplanationGate {
|
||||
pub edges_confirmed: usize,
|
||||
pub confirmed_fraction: f64,
|
||||
pub failures: Vec<String>,
|
||||
/// Per-edge intervention records, sufficient to independently recompute each
|
||||
/// confirmation (finding 7).
|
||||
pub evidence: Vec<CausalEvidenceRecord>,
|
||||
}
|
||||
|
||||
/// One recomputable per-edge intervention record: regenerate the case from
|
||||
/// `case_seed`, perturb the recorded source lane, and the destination lane's
|
||||
/// delta must move from `base_dv` to `alt_dv` (`confirmed = base_dv != alt_dv`).
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct CausalEvidenceRecord {
|
||||
pub case_seed: u64,
|
||||
pub from_domain: u8,
|
||||
pub from_lane: u8,
|
||||
pub from_hidden: bool,
|
||||
pub to_domain: u8,
|
||||
pub to_lane: u8,
|
||||
pub to_hidden: bool,
|
||||
pub base_dv: i64,
|
||||
pub alt_dv: i64,
|
||||
}
|
||||
|
||||
impl CausalEvidenceRecord {
|
||||
pub fn confirmed(&self) -> bool {
|
||||
self.base_dv != self.alt_dv
|
||||
}
|
||||
}
|
||||
|
||||
/// Minimum fraction of recorded causal edges that must be intervention-confirmed.
|
||||
@@ -1305,11 +1374,13 @@ pub fn causal_confirmation(
|
||||
cases: usize,
|
||||
edges_per_case: usize,
|
||||
scramble: bool,
|
||||
) -> (usize, usize) {
|
||||
) -> (usize, usize, Vec<CausalEvidenceRecord>) {
|
||||
let mut tested = 0usize;
|
||||
let mut confirmed = 0usize;
|
||||
let mut records = Vec::new();
|
||||
for i in 0..cases {
|
||||
let (case, _) = generate_accepted_case(case_seed(i));
|
||||
let seed = case_seed(i);
|
||||
let (case, _) = generate_accepted_case(seed);
|
||||
let input = input_from_case(&case);
|
||||
let base = execute(cfg, &input);
|
||||
let edges = &base.trace.causal_graph.edges;
|
||||
@@ -1340,9 +1411,22 @@ pub fn causal_confirmation(
|
||||
if base_dv != alt_dv {
|
||||
confirmed += 1;
|
||||
}
|
||||
if !scramble {
|
||||
records.push(CausalEvidenceRecord {
|
||||
case_seed: seed,
|
||||
from_domain: sd as u8,
|
||||
from_lane: sl as u8,
|
||||
from_hidden: shidden,
|
||||
to_domain: dd as u8,
|
||||
to_lane: e.to.lane,
|
||||
to_hidden: e.to.hidden,
|
||||
base_dv,
|
||||
alt_dv,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
(tested, confirmed)
|
||||
(tested, confirmed, records)
|
||||
}
|
||||
|
||||
pub fn causal_explanation_gate(
|
||||
@@ -1350,7 +1434,7 @@ pub fn causal_explanation_gate(
|
||||
cases: usize,
|
||||
edges_per_case: usize,
|
||||
) -> CausalExplanationGate {
|
||||
let (tested, confirmed) = causal_confirmation(cfg, cases, edges_per_case, false);
|
||||
let (tested, confirmed, evidence) = causal_confirmation(cfg, cases, edges_per_case, false);
|
||||
let frac = if tested > 0 { confirmed as f64 / tested as f64 } else { 0.0 };
|
||||
let mut failures = Vec::new();
|
||||
if tested < CAUSAL_CONFIRM_SAMPLE_MIN {
|
||||
@@ -1370,6 +1454,7 @@ pub fn causal_explanation_gate(
|
||||
edges_confirmed: confirmed,
|
||||
confirmed_fraction: frac,
|
||||
failures,
|
||||
evidence,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1634,23 +1719,21 @@ mod tests {
|
||||
#[test]
|
||||
fn consumed_perturbation_must_alter_trace() {
|
||||
let active = TraceDifferenceExpectation::active();
|
||||
// Program consumed the perturbed domain but the trace did not change:
|
||||
// a hard metamorphic violation.
|
||||
assert_eq!(
|
||||
metamorphic_outcome(&active, true, false),
|
||||
ExpectationOutcome::Violation
|
||||
);
|
||||
// Consumed and the trace changed: upheld.
|
||||
assert_eq!(
|
||||
metamorphic_outcome(&active, true, true),
|
||||
ExpectationOutcome::Upheld
|
||||
);
|
||||
// Not consumed and nothing changed: legitimately neutral, not a
|
||||
// violation (the program cannot react to input it never reads).
|
||||
assert_eq!(
|
||||
metamorphic_outcome(&active, false, false),
|
||||
ExpectationOutcome::ExplainedNeutral
|
||||
);
|
||||
assert_eq!(metamorphic_outcome(&active, true, true), ExpectationOutcome::Upheld);
|
||||
// Consumed but trace did not change, not permitted neutral: violation.
|
||||
assert_eq!(metamorphic_outcome(&active, true, false), ExpectationOutcome::Violation);
|
||||
// Not consumed and nothing changed: legitimately neutral.
|
||||
assert_eq!(metamorphic_outcome(&active, false, false), ExpectationOutcome::ExplainedNeutral);
|
||||
}
|
||||
|
||||
/// Delta and future expectations are enforced as consumed-aggregate rates
|
||||
/// (per-case is unsound). A run whose consumed perturbations rarely change
|
||||
/// the delta or future must fail; the reference run is well above both.
|
||||
#[test]
|
||||
fn metamorphic_delta_future_rates_enforced() {
|
||||
let r = run_all(Scale::tiny());
|
||||
assert!(r.metamorphic.consumed_delta_rate >= CONSUMED_DELTA_MIN, "delta rate {}", r.metamorphic.consumed_delta_rate);
|
||||
assert!(r.metamorphic.consumed_future_rate >= CONSUMED_FUTURE_MIN, "future rate {}", r.metamorphic.consumed_future_rate);
|
||||
}
|
||||
|
||||
/// Finding 10: the causal-explanation gate measures real cause→effect, not
|
||||
@@ -1666,7 +1749,7 @@ mod tests {
|
||||
assert!(gate.failures.is_empty(), "reference fails causal gate: {:?}", gate.failures);
|
||||
assert!(gate.confirmed_fraction >= CAUSAL_CONFIRM_MIN);
|
||||
|
||||
let (t, c) = causal_confirmation(&cfg, 120, 8, true);
|
||||
let (t, c, _) = causal_confirmation(&cfg, 120, 8, true);
|
||||
let scrambled = c as f64 / t.max(1) as f64;
|
||||
assert!(
|
||||
scrambled < CAUSAL_CONFIRM_MIN,
|
||||
@@ -1679,6 +1762,32 @@ mod tests {
|
||||
gate.confirmed_fraction,
|
||||
scrambled
|
||||
);
|
||||
// Per-edge evidence is retained and independently recomputable: replay
|
||||
// each record from its seed and confirm base_dv/alt_dv reproduce.
|
||||
assert!(!gate.evidence.is_empty());
|
||||
let mut rechecked = 0;
|
||||
for rec in gate.evidence.iter().take(64) {
|
||||
let (case, _) = generate_accepted_case(rec.case_seed);
|
||||
let input = input_from_case(&case);
|
||||
let base = execute(&cfg, &input);
|
||||
let mut w = input.world.clone();
|
||||
if rec.from_hidden {
|
||||
let l = rec.from_lane as usize % HIDDEN_LANES;
|
||||
w.domains[rec.from_domain as usize].hidden[l] =
|
||||
w.domains[rec.from_domain as usize].hidden[l].wrapping_add(0x9_27c1);
|
||||
} else {
|
||||
let l = rec.from_lane as usize % LANES;
|
||||
w.domains[rec.from_domain as usize].observed[l] =
|
||||
w.domains[rec.from_domain as usize].observed[l].wrapping_add(0x9_27c1);
|
||||
}
|
||||
let alt = execute(&cfg, &input_with_world(&case, w));
|
||||
let bdv = lane_delta(&base.delta.domain_deltas[rec.to_domain as usize], rec.to_lane as usize, rec.to_hidden);
|
||||
let adv = lane_delta(&alt.delta.domain_deltas[rec.to_domain as usize], rec.to_lane as usize, rec.to_hidden);
|
||||
assert_eq!(bdv, rec.base_dv, "retained base_dv not recomputable");
|
||||
assert_eq!(adv, rec.alt_dv, "retained alt_dv not recomputable");
|
||||
rechecked += 1;
|
||||
}
|
||||
assert!(rechecked >= 64);
|
||||
}
|
||||
|
||||
/// Finding 5: mutants are killed by the SAME acceptance-gate predicates the
|
||||
@@ -1687,52 +1796,15 @@ mod tests {
|
||||
/// real predicate it targets.
|
||||
#[test]
|
||||
fn mutants_killed_by_real_acceptance_gates() {
|
||||
use rune_ir::{RuneProgram, RuneToken, ALL_OPS};
|
||||
use world_model::{standard_executors, ProgramId, Rng, WorldId, WorldSnapshot};
|
||||
fn rich_input(seed: u64) -> ResolutionInput {
|
||||
let mut rng = Rng::new(seed);
|
||||
let mut w = WorldSnapshot::blank(WorldId(seed), seed);
|
||||
for d in &mut w.domains {
|
||||
for l in 0..LANES {
|
||||
d.observed[l] = rng.range_i64(-5000, 5000);
|
||||
}
|
||||
for l in 0..HIDDEN_LANES {
|
||||
d.hidden[l] = rng.range_i64(-5000, 5000);
|
||||
}
|
||||
}
|
||||
for j in 0..NUM_DOMAINS {
|
||||
for i in 0..NUM_DOMAINS {
|
||||
w.causal_state.coupling[j][i] = rng.range_i64(-17, 17);
|
||||
}
|
||||
}
|
||||
let tokens: Vec<RuneToken> = (0..40)
|
||||
.map(|i| RuneToken {
|
||||
op: ALL_OPS[i % ALL_OPS.len()],
|
||||
a: ((i * 3) % NUM_DOMAINS) as u8,
|
||||
b: ((i * 5 + 1) % NUM_DOMAINS) as u8,
|
||||
c: rng.next_u64() as u8,
|
||||
imm: rng.range_i64(-100000, 100000),
|
||||
})
|
||||
.collect();
|
||||
ResolutionInput {
|
||||
world: w,
|
||||
program: RuneProgram { id: ProgramId(seed), tokens, seed },
|
||||
contexts: standard_executors(seed, 4),
|
||||
contract_seed: seed,
|
||||
perturbation_seed: seed,
|
||||
}
|
||||
}
|
||||
let inputs: Vec<ResolutionInput> = (0..16).map(|s| rich_input(s + 1)).collect();
|
||||
// Reference passes every per-config acceptance predicate.
|
||||
// The reference passes the FULL engine-behavior acceptance gates over a
|
||||
// real generated-case corpus (not 64 fixed inputs).
|
||||
let refcfg = EngineConfig::reference();
|
||||
let rc: Vec<Canonical> = inputs.iter().map(|i| canonical(&execute(&refcfg, i))).collect();
|
||||
let rf: Vec<Hash> = inputs.iter().map(|i| execute(&refcfg, i).replay.future_hash).collect();
|
||||
assert!(!config_causal_fails(&refcfg, &inputs));
|
||||
assert!(!config_domain_fails(&refcfg, &inputs));
|
||||
assert!(!config_temporal_fails(&refcfg, &inputs, &rf));
|
||||
assert!(!config_equivalence_fails(&refcfg, &inputs, &rc));
|
||||
// Every mutant is rejected by the real acceptance gate it targets.
|
||||
let outcome = evaluate_mutants(520, &inputs);
|
||||
assert!(
|
||||
engine_acceptance(&refcfg, MUTATION_GATE_CASES).is_empty(),
|
||||
"reference fails an acceptance gate"
|
||||
);
|
||||
// Every mutant is rejected by those same full gates.
|
||||
let outcome = evaluate_mutants(520, &[]);
|
||||
assert!(outcome.passed(), "survivors: {:?}", outcome.survivors);
|
||||
assert_eq!(outcome.killed, outcome.total);
|
||||
}
|
||||
|
||||
@@ -59,6 +59,58 @@ fn write_evidence(dir: &Path, r: &CiResults) {
|
||||
r.provenance.engines_agree,
|
||||
);
|
||||
fs::write(ev.join("claims.tsv"), claims).expect("write claims");
|
||||
|
||||
// Per-edge causal intervention evidence (finding 7): one recomputable record
|
||||
// per tested edge.
|
||||
let mut causal = String::from(
|
||||
"seed\tfrom_domain\tfrom_lane\tfrom_hidden\tto_domain\tto_lane\tto_hidden\tbase_dv\talt_dv\n",
|
||||
);
|
||||
for rec in &r.causal_explanation.evidence {
|
||||
causal.push_str(&format!(
|
||||
"{:016x}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\n",
|
||||
rec.case_seed,
|
||||
rec.from_domain,
|
||||
rec.from_lane,
|
||||
rec.from_hidden as u8,
|
||||
rec.to_domain,
|
||||
rec.to_lane,
|
||||
rec.to_hidden as u8,
|
||||
rec.base_dv,
|
||||
rec.alt_dv,
|
||||
));
|
||||
}
|
||||
fs::write(ev.join("causal_evidence.tsv"), causal).expect("write causal evidence");
|
||||
|
||||
// Collapse feature rows (finding 4): the summaries the collapse gate consumes,
|
||||
// in the same order as the first base trace records. Stored as f64 bits so an
|
||||
// attestor can recompute each row from the full trace and compare bit-exact.
|
||||
let mut crows = String::new();
|
||||
for row in &r.collapse_feature_rows {
|
||||
let cells: Vec<String> = row.iter().map(|v| v.to_bits().to_string()).collect();
|
||||
crows.push_str(&cells.join(" "));
|
||||
crows.push('\n');
|
||||
}
|
||||
fs::write(ev.join("collapse_feature_rows.tsv"), crows).expect("write collapse rows");
|
||||
|
||||
// Artifact bundle manifest (finding 1): the merge-scale claim is only valid
|
||||
// if this complete, content-hashed bundle is retained. The attestor verifies
|
||||
// every listed file exists and its hash + length match.
|
||||
let bundle = [
|
||||
"leaves.tsv",
|
||||
"claims.tsv",
|
||||
"causal_evidence.tsv",
|
||||
"collapse_feature_rows.tsv",
|
||||
"traces.tsv",
|
||||
];
|
||||
let mut manifest = String::from("file\thash\tbytes\n");
|
||||
for name in bundle {
|
||||
let bytes = fs::read(ev.join(name)).unwrap_or_default();
|
||||
let mut h = world_model::Hasher::new();
|
||||
h.write_tag("evidence-file");
|
||||
h.write_bytes(&bytes);
|
||||
manifest.push_str(&format!("{}\t{:016x}\t{}\n", name, h.finish().0, bytes.len()));
|
||||
}
|
||||
fs::write(ev.join("MANIFEST.tsv"), manifest).expect("write manifest");
|
||||
// Note: evidence/traces.tsv (the FULL per-execution trace corpus) is streamed
|
||||
// during the run in main(), covering 100% of base executions — not written
|
||||
// here from a capped sample.
|
||||
@@ -147,6 +199,8 @@ fn build_reports(dir: &Path, r: &CiResults) {
|
||||
("altered_delta".into(), Json::Num(r.metamorphic.altered_delta)),
|
||||
("altered_future".into(), Json::Num(r.metamorphic.altered_future)),
|
||||
("consumed_perturbation_trace_violations".into(), Json::Num(r.metamorphic.expectation_violations)),
|
||||
("consumed_delta_change_rate".into(), Json::Num(r.metamorphic.consumed_delta_rate)),
|
||||
("consumed_future_change_rate".into(), Json::Num(r.metamorphic.consumed_future_rate)),
|
||||
("legitimately_neutral".into(), Json::Num(r.metamorphic.explained_neutral)),
|
||||
("consumed_perturbations".into(), Json::Int(r.metamorphic.consumed as i64)),
|
||||
("failures".into(), fails(&r.metamorphic.failures)),
|
||||
|
||||
Reference in New Issue
Block a user