Skip to content

Building 70 Projects ranging from beginner to advanced so anyone can — learn from, build upon, use as a reference, or even copy directly. Owned by my cybersecurity company đŸ‘‡

feat(lisdex): B51(b) - extend upward, and only trust the delta when both maps count the same edge

CarterPerez-dev30e0e2297be1
diff --git a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-harness/src/lib.rs b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-harness/src/lib.rs
index 569dc4bc..005f49f3 100644
--- a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-harness/src/lib.rs
+++ b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-harness/src/lib.rs
@@ -6,5 +6,6 @@ pub mod coverage;
pub mod emit;
pub mod oracle;
pub mod plan;
+pub mod search;
pub mod synth;
pub mod verify;
diff --git a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-harness/src/oracle.rs b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-harness/src/oracle.rs
index 160e274d..8db2b9a1 100644
--- a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-harness/src/oracle.rs
+++ b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-harness/src/oracle.rs
@@ -62,6 +62,11 @@ pub enum Rejection {
ParentMapIncomplete {
seed: PathBuf,
},
+ ParentMapIncomparable {
+ seed: PathBuf,
+ shared: usize,
+ parent: usize,
+ },
}
impl std::fmt::Display for Rejection {
@@ -121,6 +126,15 @@ impl std::fmt::Display for Rejection {
"the parent coverage map has no entry for seed {} - the linearity oracle cannot run and must not silently pass",
seed.display()
),
+ Rejection::ParentMapIncomparable {
+ seed,
+ shared,
+ parent,
+ } => write!(
+ formatter,
+ "on seed {} the shorter sequence reached {parent} edge(s) and the extended one shares only {shared} of them, so the two maps do not describe the same numbering and their difference is not a coverage gain; an LTO-bitcode archive is re-instrumented at every link, which renumbers every edge when the harness changes size - the oracle bench needs an archive whose instrumentation was fixed when the LIBRARY was built",
+ seed.display()
+ ),
}
}
}
@@ -228,6 +242,27 @@ pub fn judge_linear_increase(
seed: run.seed.clone(),
});
};
+ // A DELTA needs the shorter sequence's coverage to be contained in the longer one's.
+ // The extended body is the parent's body with further calls spliced in before the
+ // teardown, so on the same seed it must execute every block the parent did - and if it
+ // does not, `novel_against` counts what appeared while ignoring what vanished, which is
+ // not a gain in either direction.
+ //
+ // Measured, and it is why this guard exists rather than a comment: with an LTO-bitcode
+ // archive, `afl-clang-lto` re-instruments the WHOLE program at every link, so appending
+ // one call to the harness renumbered every library edge - a synthetic parent's
+ // {13, 15, 32} became the child's {12, 14, 31, 35} for the same seed, sharing NOTHING.
+ // The per-seed gains then vary with map size rather than with the input, and a call
+ // doing identical work on every seed was ACCEPTED. With the same library pre-instrumented
+ // by `afl-clang-fast` the parent's 15 edges were all 15 present in the child's 17.
+ if !run.map.covers(before) {
+ let shared = before.len() - before.novel_against(&run.map);
+ return Err(Rejection::ParentMapIncomparable {
+ seed: run.seed.clone(),
+ shared,
+ parent: before.len(),
+ });
+ }
gains.push(run.map.novel_against(before));
}
let first = gains[0];
@@ -533,6 +568,46 @@ mod tests {
);
}
+ // The liveness guard on the oracle itself. Without it the ID renumbering an LTO relink
+ // produces reads as a per-seed-varying gain, which is the ONE answer this oracle must never
+ // give by accident: it means "the added call depends on its input" and it accepts.
+ #[test]
+ fn a_parent_map_the_child_does_not_contain_cannot_be_a_delta() {
+ let parent = BTreeMap::from([
+ (PathBuf::from("a"), [13, 15, 32].into_iter().collect()),
+ (PathBuf::from("b"), [13, 15, 32, 40].into_iter().collect()),
+ ]);
+ // The measured renumbering: every ID shifted by one and one new edge appeared.
+ let valid = vec![run("a", &[12, 14, 31, 35]), run("b", &[12, 14, 31, 35, 39])];
+ assert_eq!(
+ judge_linear_increase(&valid, Some(&parent)),
+ Err(Rejection::ParentMapIncomparable {
+ seed: PathBuf::from("a"),
+ shared: 0,
+ parent: 3,
+ })
+ );
+ }
+
+ // Isolates the guard from the gain test: the same shapes, one edge of the parent's missing.
+ // A guard keyed on "shares nothing" would pass this and still accept a bad delta.
+ #[test]
+ fn losing_one_edge_of_the_parents_coverage_is_enough_to_refuse_the_verdict() {
+ let parent = BTreeMap::from([
+ (PathBuf::from("a"), [1, 2, 3].into_iter().collect()),
+ (PathBuf::from("b"), [3, 4].into_iter().collect()),
+ ]);
+ let valid = vec![run("a", &[1, 2, 90, 91]), run("b", &[3, 4, 92])];
+ assert_eq!(
+ judge_linear_increase(&valid, Some(&parent)),
+ Err(Rejection::ParentMapIncomparable {
+ seed: PathBuf::from("a"),
+ shared: 2,
+ parent: 3,
+ })
+ );
+ }
+
#[test]
fn an_input_dependent_gain_passes() {
let parent = BTreeMap::from([
diff --git a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-harness/src/plan.rs b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-harness/src/plan.rs
index b298cd4f..7710c3b0 100644
--- a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-harness/src/plan.rs
+++ b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-harness/src/plan.rs
@@ -137,6 +137,11 @@ pub struct HarnessPlan {
// rather than from our rules" is the one thing a reader of the emitted C cannot recover,
// and it is what has to be asserted to prove the replay happened at all.
pub replayed: Vec<String>,
+ // The same argument, for the calls the author made AFTER the entry point. These are kept
+ // apart from `replayed` because the two are judged differently: a replayed call is setup
+ // the entry point needs, while an extension is a longer sequence that has to earn its
+ // place against the shorter one it extends (D4 oracle 3b).
+ pub extended: Vec<String>,
}
impl HarnessPlan {
@@ -152,6 +157,7 @@ impl HarnessPlan {
callbacks: Vec::new(),
body: Vec::new(),
replayed: Vec::new(),
+ extended: Vec::new(),
}
}
diff --git a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-harness/src/search.rs b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-harness/src/search.rs
new file mode 100644
index 00000000..9f25b8cf
--- /dev/null
+++ b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-harness/src/search.rs
@@ -0,0 +1,547 @@
+// ©AngelaMos | 2026
+// search.rs
+
+use std::collections::BTreeMap;
+use std::path::{Path, PathBuf};
+
+use crate::coverage::EdgeSet;
+use crate::emit;
+use crate::plan::HarnessPlan;
+use crate::synth::{self, Extension, Refusal};
+use crate::verify::{Verdict, VerifyError};
+
+// The bench a trial runs on. `verify::Bench` is the real one - compile, run every seed,
+// showmap, judge - and the tests supply a fake, which is the only way the accumulation itself
+// can be tested: every property below (a survivor set that grows, a variant loop that stops at
+// the first acceptance, an extension judged against its parent's per-seed maps) needs a
+// controlled verdict rather than a real compiler.
+pub trait Bench {
+ fn verify(
+ &self,
+ source: &Path,
+ label: &str,
+ parent: Option<&BTreeMap<PathBuf, EdgeSet>>,
+ accepted: &EdgeSet,
+ ) -> Result<Verdict, VerifyError>;
+}
+
+impl Bench for crate::verify::Bench {
+ fn verify(
+ &self,
+ source: &Path,
+ label: &str,
+ parent: Option<&BTreeMap<PathBuf, EdgeSet>>,
+ accepted: &EdgeSet,
+ ) -> Result<Verdict, VerifyError> {
+ crate::verify::Bench::verify(self, source, label, parent, accepted)
+ }
+}
+
+// One ranked candidate, planned or refused. The refusals travel WITH the plans rather than in
+// a list beside them so the evidence trail stays in ranking order: a libarchive user handed a
+// date parser needs to read down the list and see the archive readers above it refuse.
+pub enum Attempt {
+ Planned {
+ name: String,
+ variants: Vec<HarnessPlan>,
+ steps: Vec<Extension>,
+ },
+ Refused {
+ name: String,
+ refusal: Refusal,
+ },
+}
+
+// What the oracles decided about one accepted entry point. `judged_against` is the size of the
+// accepted set at the moment this harness was judged: 0 means it was first and oracle 4 could
+// only reject a harness reaching nothing, which is the weak form B51 described. `steps` is how
+// far the author's own sequence was followed past the entry point, and it is what makes oracle
+// 3b's verdict a fact about this survivor rather than about the run.
+pub struct Survivor {
+ pub name: String,
+ pub plan: HarnessPlan,
+ pub verdict: Verdict,
+ pub edges: usize,
+ pub novel: usize,
+ pub judged_against: usize,
+ pub variants: usize,
+ pub steps: usize,
+}
+
+#[derive(Default)]
+pub struct Outcome {
+ pub survivors: Vec<Survivor>,
+ pub rejected: Vec<String>,
+ pub accepted: EdgeSet,
+}
+
+// Only the VALID seeds. `judge_linear_increase` compares per-seed gains and an invalid seed is
+// allowed to crash the library's error path, so a map from one would put a gain in the vector
+// that says nothing about how the added call reads its input.
+fn parent_maps(verdict: &Verdict) -> BTreeMap<PathBuf, EdgeSet> {
+ verdict
+ .observation
+ .as_ref()
+ .map_or_else(BTreeMap::new, |observation| {
+ observation
+ .valid
+ .iter()
+ .map(|run| (run.seed.clone(), run.map.clone()))
+ .collect()
+ })
+}
+
+fn write(dir: &Path, label: &str, plan: &HarnessPlan) -> Result<PathBuf, std::io::Error> {
+ let filename = format!("{label}.c");
+ let path = dir.join(&filename);
+ std::fs::write(&path, emit::render(plan, &filename))?;
+ Ok(path)
+}
+
+// The upward climb, and the direction is the whole design. The parent is an ACCEPTED harness,
+// never a truncation of one: D4's oracle 3b asks whether the added call raises every seed's
+// coverage by the same constant, and the only honest baseline for that question is a sequence
+// that already earned its place. Walking DOWN instead - judging the entry point against a
+// prefix of the author's setup - would put the baseline below the floor the ranked source
+// ladder established, where a harness that registers no format reads nothing at all.
+//
+// An accepted step REPLACES its parent as the survivor for this entry point rather than
+// standing beside it. The extended body is the parent's body plus further calls, so it reaches
+// everything the parent reached; keeping both would report one entry point twice and promote
+// two files with the same name.
+fn climb<B: Bench>(
+ outcome: &mut Outcome,
+ survivor: &mut Survivor,
+ steps: &[Extension],
+ bench: &B,
+ dir: &Path,
+) -> Result<(), std::io::Error> {
+ let mut parent = parent_maps(&survivor.verdict);
+ let base = survivor.plan.clone();
+ for depth in 1..=steps.len() {
+ let label = format!("{}.up{depth}", survivor.name);
+ let plan = synth::extend(&base, &steps[..depth]);
+ let source = write(dir, &label, &plan)?;
+ let against = outcome.accepted.len();
+ let verdict = match bench.verify(&source, &label, Some(&parent), &outcome.accepted) {
+ Ok(verdict) => verdict,
+ Err(err) => {
+ outcome
+ .rejected
+ .push(format!(" {label} - could not be judged: {err}"));
+ return Ok(());
+ }
+ };
+ let (edges, novel) = match &verdict.outcome {
+ Ok(reached) => {
+ let novel = reached.novel_against(&outcome.accepted);
+ let edges = reached.len();
+ outcome.accepted.absorb(reached);
+ (edges, novel)
+ }
+ Err(rejection) => {
+ // Names the call that was appended, because "this harness was rejected" and
+ // "this harness plus THIS call was rejected" are different statements and only
+ // the second one tells the reader which call to stop appending.
+ outcome.rejected.push(format!(
+ " {label} - appending {} - {rejection}",
+ steps[depth - 1].function
+ ));
+ return Ok(());
+ }
+ };
+ survivor.edges = edges;
+ survivor.novel = novel;
+ survivor.judged_against = against;
+ survivor.steps = depth;
+ survivor.plan = plan;
+ parent = parent_maps(&verdict);
+ survivor.verdict = verdict;
+ }
+ Ok(())
+}
+
+pub fn accumulate<B: Bench>(
+ attempts: &[Attempt],
+ bench: &B,
+ dir: &Path,
+) -> Result<Outcome, std::io::Error> {
+ let mut outcome = Outcome::default();
+ for attempt in attempts {
+ let (name, variants, steps) = match attempt {
+ Attempt::Refused { name, refusal } => {
+ outcome
+ .rejected
+ .push(format!(" {name} - refused: {refusal}"));
+ continue;
+ }
+ Attempt::Planned {
+ name,
+ variants,
+ steps,
+ } => (name, variants, steps),
+ };
+
+ // Every variant is written before any is judged: the rejected ones are the evidence
+ // trail, and the gate uses them as ready-made negative controls.
+ let mut emitted = Vec::with_capacity(variants.len());
+ for (index, plan) in variants.iter().enumerate() {
+ let label = format!("{name}.v{index}");
+ let source = write(dir, &label, plan)?;
+ emitted.push((label, source));
+ }
+
+ for ((label, source), plan) in emitted.iter().zip(variants) {
+ // No parent at depth 0: oracle 3b measures a candidate against the shorter call
+ // sequence it EXTENDS, and variants run most-populated first, so no later variant
+ // extends an earlier one. Feeding it a sibling would reject the fallback for a
+ // constant gain of zero, which is true and meaningless.
+ let against = outcome.accepted.len();
+ let verdict = match bench.verify(source, label, None, &outcome.accepted) {
+ Ok(verdict) => verdict,
+ Err(err) => {
+ // One candidate's toolchain failure must not kill the other nineteen.
+ outcome
+ .rejected
+ .push(format!(" {label} - could not be judged: {err}"));
+ continue;
+ }
+ };
+ match &verdict.outcome {
+ Ok(reached) => {
+ let novel = reached.novel_against(&outcome.accepted);
+ let mut survivor = Survivor {
+ name: name.clone(),
+ plan: plan.clone(),
+ verdict: verdict.clone(),
+ edges: reached.len(),
+ novel,
+ judged_against: against,
+ variants: variants.len(),
+ steps: 0,
+ };
+ outcome.accepted.absorb(reached);
+ climb(&mut outcome, &mut survivor, steps, bench, dir)?;
+ outcome.survivors.push(survivor);
+ // Variants of ONE candidate are alternatives, not distinct harnesses:
+ // they call the same entry point with more or less of its context
+ // populated. Taking the first that survives and moving on is what makes
+ // the accumulated set a set of ENTRY POINTS.
+ break;
+ }
+ Err(rejection) => outcome.rejected.push(format!(" {label} - {rejection}")),
+ }
+ }
+ }
+ Ok(outcome)
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use crate::oracle::{Observation, Rejection, RunStatus, SeedRun};
+ use crate::plan::{Stmt, Value};
+ use std::cell::RefCell;
+ use std::collections::BTreeSet;
+
+ struct Call {
+ label: String,
+ parent: Option<Vec<PathBuf>>,
+ }
+
+ // Accepts whatever it is told to and records what it was asked. The recorded PARENT is the
+ // point: without it, a run that never passes the parent maps through looks identical to
+ // one that does, and oracle 3b is unreachable code either way.
+ struct Fake {
+ accept: BTreeSet<String>,
+ edges: BTreeMap<String, Vec<u32>>,
+ seeds: Vec<PathBuf>,
+ calls: RefCell<Vec<Call>>,
+ }
+
+ impl Fake {
+ fn new(accept: &[&str]) -> Self {
+ Self {
+ accept: accept.iter().map(|label| (*label).to_owned()).collect(),
+ edges: BTreeMap::new(),
+ seeds: vec![PathBuf::from("valid-a"), PathBuf::from("valid-b")],
+ calls: RefCell::new(Vec::new()),
+ }
+ }
+
+ fn reaching(mut self, label: &str, edges: &[u32]) -> Self {
+ self.edges.insert(label.to_owned(), edges.to_vec());
+ self
+ }
+
+ fn labels(&self) -> Vec<String> {
+ self.calls
+ .borrow()
+ .iter()
+ .map(|call| call.label.clone())
+ .collect()
+ }
+
+ fn parent_of(&self, label: &str) -> Option<Vec<PathBuf>> {
+ self.calls
+ .borrow()
+ .iter()
+ .find(|call| call.label == label)
+ .and_then(|call| call.parent.clone())
+ }
+ }
+
+ impl Bench for Fake {
+ fn verify(
+ &self,
+ source: &Path,
+ label: &str,
+ parent: Option<&BTreeMap<PathBuf, EdgeSet>>,
+ _accepted: &EdgeSet,
+ ) -> Result<Verdict, VerifyError> {
+ self.calls.borrow_mut().push(Call {
+ label: label.to_owned(),
+ parent: parent.map(|maps| maps.keys().cloned().collect()),
+ });
+ let reached: Vec<u32> = self
+ .edges
+ .get(label)
+ .cloned()
+ .unwrap_or_else(|| vec![1, 2, 3]);
+ let observation = Observation {
+ valid: self
+ .seeds
+ .iter()
+ .map(|seed| SeedRun {
+ seed: seed.clone(),
+ map: reached.iter().copied().collect::<EdgeSet>(),
+ status: RunStatus::Clean,
+ stderr: String::new(),
+ })
+ .collect(),
+ invalid: Vec::new(),
+ };
+ let outcome = if self.accept.contains(label) {
+ Ok(EdgeSet::from_iter(reached))
+ } else {
+ Err(Rejection::NoInterSeedDivergence { best: 0 })
+ };
+ Ok(Verdict {
+ label: label.to_owned(),
+ source: source.to_path_buf(),
+ binary: PathBuf::from("/dev/null"),
+ outcome,
+ observation: Some(observation),
+ })
+ }
+ }
+
+ fn scratch(label: &str) -> PathBuf {
+ let dir =
+ std::env::temp_dir().join(format!("lisdex-search-{label}-{}", std::process::id()));
+ let _ = std::fs::remove_dir_all(&dir);
+ std::fs::create_dir_all(&dir).unwrap();
+ dir
+ }
+
+ fn planned(name: &str, variants: usize, steps: &[&str]) -> Attempt {
+ let plan = HarnessPlan::new(name).with(Stmt::Call {
+ function: name.to_owned(),
+ args: vec![Value::Data { cast: None }, Value::Size],
+ capture: None,
+ });
+ Attempt::Planned {
+ name: name.to_owned(),
+ variants: vec![plan; variants],
+ steps: steps
+ .iter()
+ .map(|function| Extension {
+ function: (*function).to_owned(),
+ call: Stmt::Call {
+ function: (*function).to_owned(),
+ args: vec![Value::Local("ctx".to_owned())],
+ capture: None,
+ },
+ })
+ .collect(),
+ }
+ }
+
+ #[test]
+ fn every_survivor_is_kept_so_the_accepted_set_grows() {
+ let dir = scratch("set");
+ let bench = Fake::new(&["one.v0", "two.v0"])
+ .reaching("one.v0", &[1, 2, 3])
+ .reaching("two.v0", &[3, 4, 5]);
+ let outcome = accumulate(
+ &[planned("one", 1, &[]), planned("two", 1, &[])],
+ &bench,
+ &dir,
+ )
+ .unwrap();
+ assert_eq!(outcome.survivors.len(), 2);
+ assert_eq!(outcome.accepted.len(), 5);
+ assert_eq!(outcome.survivors[0].judged_against, 0);
+ assert_eq!(
+ outcome.survivors[1].judged_against, 3,
+ "the second candidate must be judged against the first"
+ );
+ assert_eq!(outcome.survivors[1].novel, 2);
+ }
+
+ #[test]
+ fn only_the_first_surviving_variant_of_one_candidate_is_kept() {
+ let dir = scratch("variants");
+ let bench = Fake::new(&["one.v1"]);
+ let outcome = accumulate(&[planned("one", 3, &[])], &bench, &dir).unwrap();
+ assert_eq!(outcome.survivors.len(), 1);
+ assert_eq!(
+ bench.labels(),
+ vec!["one.v0", "one.v1"],
+ "the third variant must never be judged once the second survives"
+ );
+ }
+
+ #[test]
+ fn a_planner_refusal_is_reported_in_ranking_order() {
+ let dir = scratch("order");
+ let bench = Fake::new(&["two.v0"]);
+ let outcome = accumulate(
+ &[
+ Attempt::Refused {
+ name: "one".to_owned(),
+ refusal: Refusal::PathEntry,
+ },
+ planned("two", 1, &[]),
+ Attempt::Refused {
+ name: "three".to_owned(),
+ refusal: Refusal::NoDataInput,
+ },
+ ],
+ &bench,
+ &dir,
+ )
+ .unwrap();
+ assert_eq!(outcome.rejected.len(), 2);
+ assert!(
+ outcome.rejected[0].contains("one"),
+ "{:?}",
+ outcome.rejected
+ );
+ assert!(
+ outcome.rejected[1].contains("three"),
+ "{:?}",
+ outcome.rejected
+ );
+ }
+
+ // The B51(b) plumbing, and the only test that can see it: oracle 3b is passed None at
+ // depth 0 and the accepted parent's per-seed maps at depth 1. A run that forgot to thread
+ // them through would still accept the extension and still report a survivor.
+ #[test]
+ fn an_extension_is_judged_against_its_parents_per_seed_maps() {
+ let dir = scratch("parent");
+ let bench = Fake::new(&["one.v0", "one.up1"])
+ .reaching("one.v0", &[1, 2])
+ .reaching("one.up1", &[1, 2, 7]);
+ let outcome = accumulate(&[planned("one", 1, &["further"])], &bench, &dir).unwrap();
+ assert_eq!(bench.parent_of("one.v0"), None, "depth 0 has no parent");
+ assert_eq!(
+ bench.parent_of("one.up1"),
+ Some(vec![PathBuf::from("valid-a"), PathBuf::from("valid-b")]),
+ "the extension must be judged against the parent's own seeds"
+ );
+ assert_eq!(outcome.survivors.len(), 1);
+ }
+
+ #[test]
+ fn an_accepted_extension_replaces_its_parent_as_the_survivor() {
+ let dir = scratch("replace");
+ let bench = Fake::new(&["one.v0", "one.up1"])
+ .reaching("one.v0", &[1, 2])
+ .reaching("one.up1", &[1, 2, 7]);
+ let outcome = accumulate(&[planned("one", 1, &["further"])], &bench, &dir).unwrap();
+ assert_eq!(outcome.survivors.len(), 1, "not one survivor per depth");
+ let survivor = &outcome.survivors[0];
+ assert_eq!(survivor.steps, 1);
+ assert_eq!(survivor.edges, 3);
+ assert_eq!(survivor.plan.extended, vec!["further".to_owned()]);
+ assert!(outcome.rejected.is_empty(), "{:?}", outcome.rejected);
+ }
+
+ #[test]
+ fn a_rejected_extension_leaves_the_parent_standing_and_names_the_call() {
+ let dir = scratch("reject");
+ let bench = Fake::new(&["one.v0"]).reaching("one.v0", &[1, 2]);
+ let outcome = accumulate(&[planned("one", 1, &["further"])], &bench, &dir).unwrap();
+ assert_eq!(outcome.survivors.len(), 1);
+ assert_eq!(outcome.survivors[0].steps, 0);
+ assert_eq!(outcome.survivors[0].edges, 2);
+ assert_eq!(outcome.rejected.len(), 1);
+ assert!(
+ outcome.rejected[0].contains("appending further"),
+ "{:?}",
+ outcome.rejected
+ );
+ }
+
+ #[test]
+ fn the_climb_stops_at_the_first_rejected_step() {
+ let dir = scratch("stop");
+ let bench = Fake::new(&["one.v0", "one.up1"])
+ .reaching("one.v0", &[1])
+ .reaching("one.up1", &[1, 2]);
+ let outcome = accumulate(
+ &[planned("one", 1, &["first", "second", "third"])],
+ &bench,
+ &dir,
+ )
+ .unwrap();
+ assert_eq!(
+ bench.labels(),
+ vec!["one.v0", "one.up1", "one.up2"],
+ "up3 must never be built once up2 is rejected"
+ );
+ assert_eq!(outcome.survivors[0].steps, 1);
+ }
+
+ #[test]
+ fn a_candidate_with_no_step_is_never_extended() {
+ let dir = scratch("nosteps");
+ let bench = Fake::new(&["one.v0"]);
+ accumulate(&[planned("one", 1, &[])], &bench, &dir).unwrap();
+ assert_eq!(bench.labels(), vec!["one.v0"]);
+ }
+
+ #[test]
+ fn a_bench_error_on_one_candidate_does_not_stop_the_walk() {
+ struct Broken;
+ impl Bench for Broken {
+ fn verify(
+ &self,
+ _source: &Path,
+ label: &str,
+ _parent: Option<&BTreeMap<PathBuf, EdgeSet>>,
+ _accepted: &EdgeSet,
+ ) -> Result<Verdict, VerifyError> {
+ Err(VerifyError::NoCoverageMap {
+ seed: PathBuf::from(label),
+ })
+ }
+ }
+ let dir = scratch("broken");
+ let outcome = accumulate(
+ &[planned("one", 1, &[]), planned("two", 1, &[])],
+ &Broken,
+ &dir,
+ )
+ .unwrap();
+ assert!(outcome.survivors.is_empty());
+ assert_eq!(outcome.rejected.len(), 2);
+ assert!(
+ outcome.rejected[0].contains("could not be judged"),
+ "{:?}",
+ outcome.rejected
+ );
+ }
+}
diff --git a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-harness/src/synth.rs b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-harness/src/synth.rs
index a1121fb7..481a8442 100644
--- a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-harness/src/synth.rs
+++ b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-harness/src/synth.rs
@@ -17,6 +17,7 @@ pub const CONTEXT_LOCAL: &str = "ctx";
pub const RESULT_LOCAL: &str = "rc";
pub const MAX_POPULATED_FIELDS: usize = 4;
pub const MAX_PLAN_VARIANTS: usize = 16;
+pub const MAX_UPWARD_STEPS: usize = 4;
pub const EXTENT_WORDS: [&str; 15] = [
"size", "sz", "len", "length", "count", "capacity", "cap", "num", "nbytes", "bytes", "max",
"limit", "n", "buflen", "bufsize",
@@ -838,6 +839,221 @@ fn replay_setup(
replayed
}
+// One further call the author made AFTER the entry point, already bound to this plan's own
+// locals. It is a separate type from a plain `Stmt` because the search has to name it in a
+// rejection - "the harness plus THIS call was rejected" is a different statement from "the
+// harness was rejected".
+#[derive(Debug, Clone, PartialEq, Eq)]
+pub struct Extension {
+ pub function: String,
+ pub call: Stmt,
+}
+
+// The mirror of `setup_run`, and the asymmetry is the point. An entry point the authors never
+// call has NO tail: `position` returning None yields an empty slice rather than the whole
+// sequence, so nothing is invented for a candidate the authors said nothing about. The setup
+// side does the opposite deliberately - it scans the whole sequence for replayable plumbing -
+// which is why `archive_read_open_memory` replays six calls while having no tail at all.
+fn tail_run<'a>(sequence: &'a [String], entry: &str) -> &'a [String] {
+ match sequence.iter().position(|call| call == entry) {
+ Some(index) => &sequence[index + 1..],
+ None => &[],
+ }
+}
+
+// D4's oracle 3b measures a candidate against the shorter call sequence it EXTENDS, so the
+// parent has to be a harness that already passed - never a truncation of one. The extension
+// therefore only ever goes UP: start at the accepted entry point and append the next call the
+// authors made, bound by the same rules that bound the entry point itself.
+//
+// A step must TAKE a handle this plan is already holding. Without that requirement the rule
+// admits a second stateless entry point - lz4's own decompress_fuzzer.c calls
+// `LZ4_decompress_safe_usingDict`, `LZ4_decompress_safe_partial` and
+// `LZ4_decompress_safe_partial_usingDict` back to back over the same buffers, and fusing them
+// into one file would make a crash unattributable while oracle 4 already keeps them as
+// separate survivors. The handle is what makes a sequence a sequence.
+//
+// Censused over the seven analysable trees before this was built, because the population
+// bounds what the oracle can ever be worth. Only THREE candidates that plan appear in their
+// own author's sequence at all: libjpeg-turbo's `tj3DecompressHeader` (13-call tail),
+// libpng's `png_image_begin_read_from_memory` (tail `png_image_finish_read`) and lz4's two
+// partial decoders. The other four trees - brotli, libarchive, libwebp, zlib - plan an entry
+// point the chosen sequence never names, so their tail is empty by construction.
+pub fn upward_steps(
+ candidate: &Candidate,
+ vocabulary: &Vocabulary,
+ sequence: &[String],
+) -> Vec<Extension> {
+ let Ok(Contexts {
+ locals,
+ ordered,
+ opening,
+ }) = resolve_contexts(candidate, vocabulary)
+ else {
+ return Vec::new();
+ };
+ let mut scheduled: BTreeSet<String> = opening
+ .iter()
+ .filter_map(|statement| match statement {
+ Stmt::Call { function, .. } => Some(function.clone()),
+ _ => None,
+ })
+ .collect();
+ scheduled.extend(
+ ordered
+ .iter()
+ .flat_map(|(handle, held)| teardown_calls(handle, held, &candidate.name, vocabulary))
+ .map(|(function, _)| function),
+ );
+
+ let mut steps: Vec<Extension> = Vec::new();
+ for name in tail_run(sequence, &candidate.name) {
+ if steps.len() == MAX_UPWARD_STEPS {
+ break;
+ }
+ // The author's teardown ends the sequence: everything they wrote after it runs on a
+ // handle they had finished with, and appending it would run on one we had freed.
+ if is_teardown(name, vocabulary) {
+ break;
+ }
+ // Skipped rather than stopped on, because none of the three is a gap in the author's
+ // order: the entry point may appear twice in one sequence, a producer this plan
+ // already called is a call we HAVE made, and a repeat adds the same statement twice.
+ if name == &candidate.name
+ || scheduled.contains(name)
+ || steps.iter().any(|step| &step.function == name)
+ {
+ continue;
+ }
+ // An undeclared name is not a library call we can reason about at all - the miner
+ // yields macros, libc and even plain variables (`PNG_IMAGE_SIZE` and `buffer` are both
+ // in libpng's mined tail) - so it says nothing about the state of our handle and is
+ // skipped for the same reason the setup replay skips `inflateInit`'s macro.
+ let Some(params) = vocabulary.functions.get(name) else {
+ continue;
+ };
+ if params.is_empty() {
+ continue;
+ }
+ // Everything below STOPS the climb rather than skipping. A call we cannot copy is a
+ // gap in the only knowledge we have, and the calls after a gap were written against
+ // state we did not build. Measured on libarchive, whose real tail is
+ // `archive_read_next_header, archive_entry_pathname, archive_entry_size,
+ // archive_read_data`: `archive_read_next_header` takes `struct archive_entry **` and
+ // cannot bind, and appending `archive_read_data` over the gap would read data from a
+ // stream whose header was never read - B66's structurally-right-and-semantically-dead
+ // harness, arriving through the mechanism meant to add depth.
+ if !holds_a_handle(params, &locals) {
+ break;
+ }
+ let analysis = signature::analyze_named(name, params, &BTreeSet::new());
+ let bound: Result<Vec<Value>, Refusal> = params
+ .iter()
+ .zip(&analysis.roles)
+ .enumerate()
+ .map(|(index, (param, role))| bind(index, param, *role, &locals, &analysis))
+ .collect();
+ let Ok(args) = bound else {
+ break;
+ };
+ if !args.iter().all(is_replayable_value) {
+ break;
+ }
+ steps.push(Extension {
+ function: name.clone(),
+ call: Stmt::Call {
+ function: name.clone(),
+ args,
+ capture: None,
+ },
+ });
+ }
+ steps
+}
+
+// An extension is a COPY of a call the author wrote, so every argument has to be something
+// the harness already holds: a handle, the fuzzer's own bytes, or a buffer the harness itself
+// allocated and can state the size of. `Value::Zero` is the pinned Config - a number the
+// headers never state - and it is what the census caught. libjpeg-turbo's tail is the only
+// place any step was found at all, and all four of them were Config-bearing: the author writes
+// `tj3Set(handle, TJPARAM_SCANLIMIT, 500)` and this rule would write `tj3Set(ctx, 0, 0)`, which
+// is a different program wearing the same function name. `tj3SetScalingFactor` is worse - its
+// second parameter is a struct BY VALUE, so the invented 0 does not even compile.
+//
+// This is the same line `replay_setup` already draws on the setup side, where a call is copied
+// only when every parameter is a handle we hold, and it is why `png_sig_cmp(data, 0, 8)` is
+// never guessed at. An allow-list rather than a deny-list, so a new `Value` variant has to be
+// ruled on here instead of defaulting into an author's call it was never measured against.
+fn is_replayable_value(value: &Value) -> bool {
+ match value {
+ Value::Data { .. }
+ | Value::Size
+ | Value::Cursor
+ | Value::NulTerminated
+ | Value::OutBuffer { .. }
+ | Value::OutCapacity
+ | Value::AuxBuffer { .. }
+ | Value::AuxCapacity
+ | Value::Local(_)
+ | Value::AddressOf(_)
+ | Value::AddressOfField { .. } => true,
+ Value::Zero | Value::Null | Value::Literal(_) | Value::Callback(_) => false,
+ }
+}
+
+fn holds_a_handle(params: &[Param], locals: &BTreeMap<String, Held>) -> bool {
+ params.iter().any(|param| {
+ handle_key(&param.spelling, &param.shape).is_some_and(|handle| locals.contains_key(&handle))
+ })
+}
+
+// Where a further call goes: after the entry point and after the statement that discards its
+// result, but BEFORE the teardowns. Appending to the end instead would hand every step a
+// handle the plan has already freed, which is a use-after-free reported inside the library.
+fn insertion_point(plan: &HarnessPlan) -> usize {
+ let entry = plan.body.iter().position(
+ |statement| matches!(statement, Stmt::Call { function, .. } if function == &plan.entry),
+ );
+ let Some(entry) = entry else {
+ return plan.body.len();
+ };
+ let after = entry + 1;
+ match plan.body.get(after) {
+ Some(Stmt::Discard { local }) if local == RESULT_LOCAL => after + 1,
+ _ => after,
+ }
+}
+
+// Rebuilt through `with` rather than cloned and spliced, so the four scaffolding flags are
+// derived from the finished body exactly as they are for a plan that was never extended. A
+// step that binds the corpus or an output buffer therefore brings its own scaffolding with it.
+#[must_use]
+pub fn extend(plan: &HarnessPlan, steps: &[Extension]) -> HarnessPlan {
+ let mut built = HarnessPlan::new(plan.entry.clone());
+ built.includes.clone_from(&plan.includes);
+ built.replayed.clone_from(&plan.replayed);
+ built.extended = plan
+ .extended
+ .iter()
+ .cloned()
+ .chain(steps.iter().map(|step| step.function.clone()))
+ .collect();
+ for stub in &plan.callbacks {
+ built = built.with_callback(stub.clone());
+ }
+ let cut = insertion_point(plan);
+ for statement in &plan.body[..cut] {
+ built = built.with(statement.clone());
+ }
+ for step in steps {
+ built = built.with(step.call.clone());
+ }
+ for statement in &plan.body[cut..] {
+ built = built.with(statement.clone());
+ }
+ built
+}
+
pub fn plan_candidate(
candidate: &Candidate,
include: &str,
@@ -1185,6 +1401,25 @@ mod tests {
("archive_read_new".to_owned(), Vec::new()),
("archive_read_free".to_owned(), vec![archive_handle()]),
("archive_read_finish".to_owned(), vec![archive_handle()]),
+ // The one shape an upward step can legitimately be built from: our handle, a
+ // buffer the HARNESS allocated, and the capacity it declared. Its roles come from
+ // the real grader here rather than from a fixture, because an extension is bound
+ // by the same `bind` the entry point is and nothing hand-writes roles for it.
+ (
+ "archive_read_data".to_owned(),
+ vec![
+ archive_handle(),
+ param(
+ "buff",
+ "void *",
+ Shape::Pointer {
+ pointee: Pointee::Void,
+ is_const: false,
+ },
+ ),
+ param("len", "size_t", Shape::Integral),
+ ],
+ ),
]);
// TWO destructors, and the plan only schedules one. Keyed on a single destructor
// the teardown guard could be gutted with every test still green, because the one
@@ -1323,6 +1558,280 @@ mod tests {
assert!(replayed_calls(&[]).is_empty());
}
+ fn upward_of(sequence: &[&str]) -> Vec<String> {
+ let owned: Vec<String> = sequence.iter().map(|call| (*call).to_owned()).collect();
+ upward_steps(&open_memory(), &replayable_archive_vocabulary(), &owned)
+ .into_iter()
+ .map(|step| step.function)
+ .collect()
+ }
+
+ // B51(b), the accepting direction, and no tree in the validation set offers it: a call
+ // taking the handle we hold plus a buffer WE allocated and the capacity we declared. This
+ // is the shape that pays off - `archive_read_data` is where a libarchive harness stops
+ // being handle plumbing - and it is exactly what a real sequence would have to contain.
+ #[test]
+ fn the_authors_next_call_over_our_own_handle_is_appended_above_the_entry_point() {
+ assert_eq!(
+ upward_of(&[
+ "archive_read_new",
+ "archive_read_support_format_tar",
+ "archive_read_open_memory",
+ "archive_read_data",
+ ]),
+ ["archive_read_data"]
+ );
+ }
+
+ // The floor M5 step 4 established, stated as a property. `setup_run` deliberately scans
+ // the WHOLE sequence when the authors never name our entry point - that is why
+ // `archive_read_open_memory` replays six registrations mined from a target that calls
+ // `archive_read_open` instead - and the tail must NOT mirror that. If it did, the parent
+ // for oracle 3b would be a truncation of the author's program rather than an accepted
+ // harness, which is the prefix ladder this design rejects.
+ #[test]
+ fn an_entry_point_the_authors_never_call_has_no_upward_step() {
+ let sequence = &[
+ "archive_read_new",
+ "archive_read_support_format_tar",
+ "archive_read_open",
+ "archive_read_data",
+ ];
+ assert!(
+ !replayed_calls(sequence).is_empty(),
+ "the setup side must still replay, or this proves nothing about the tail"
+ );
+ assert!(upward_of(sequence).is_empty());
+ }
+
+ // `archive_read_finish` takes our handle and binds perfectly, so nothing but the teardown
+ // guard stops it. The plan schedules `archive_read_free`, so keying the guard on the
+ // scheduled set alone would let this one through and free the handle in front of every
+ // step after it.
+ #[test]
+ fn a_teardown_in_the_tail_is_never_appended() {
+ assert!(
+ upward_of(&[
+ "archive_read_new",
+ "archive_read_open_memory",
+ "archive_read_finish",
+ ])
+ .is_empty()
+ );
+ }
+
+ // Isolates the handle requirement, and the case is lz4's real fuzzer: it calls
+ // `LZ4_decompress_safe_usingDict`, `LZ4_decompress_safe_partial` and
+ // `LZ4_decompress_safe_partial_usingDict` back to back over the same buffers. Every
+ // argument of the second call BINDS - the corpus, an out buffer, two capacities - so bind
+ // cannot stop it. Nothing threads state between them, so fusing them into one file would
+ // make a crash unattributable, and oracle 4 already keeps them as separate survivors.
+ #[test]
+ fn a_stateless_call_beside_ours_is_not_a_sequence_step() {
+ let mut vocabulary = replayable_archive_vocabulary();
+ vocabulary.functions.insert(
+ "LZ4_decompress_safe_partial".to_owned(),
+ vec![
+ param(
+ "src",
+ "const char *",
+ Shape::Pointer {
+ pointee: Pointee::Char,
+ is_const: true,
+ },
+ ),
+ param(
+ "dst",
+ "char *",
+ Shape::Pointer {
+ pointee: Pointee::Char,
+ is_const: false,
+ },
+ ),
+ param("srcSize", "int", Shape::Integral),
+ param("dstCapacity", "int", Shape::Integral),
+ ],
+ );
+ // `archive_read_data` sits BEHIND the stateless call, so skipping instead of stopping
+ // would append it - a read from a stream the author had already advanced past.
+ let steps = upward_steps(
+ &open_memory(),
+ &vocabulary,
+ &[
+ "archive_read_open_memory".to_owned(),
+ "LZ4_decompress_safe_partial".to_owned(),
+ "archive_read_data".to_owned(),
+ ],
+ );
+ assert!(steps.is_empty(), "{steps:?}");
+ }
+
+ // The measured gap, and the reason the climb STOPS rather than skips. libarchive's real
+ // tail is `archive_read_next_header, archive_entry_pathname, archive_entry_size,
+ // archive_read_data`; the first call takes `struct archive_entry **`, which bind refuses,
+ // and `archive_read_data` behind it would read from a stream whose header was never read.
+ #[test]
+ fn a_call_the_climb_cannot_copy_stops_it_rather_than_being_skipped() {
+ let mut vocabulary = replayable_archive_vocabulary();
+ vocabulary.functions.insert(
+ "archive_read_next_header".to_owned(),
+ vec![
+ archive_handle(),
+ param(
+ "entry",
+ "struct archive_entry **",
+ Shape::Pointer {
+ pointee: Pointee::Pointer,
+ is_const: false,
+ },
+ ),
+ ],
+ );
+ let steps = upward_steps(
+ &open_memory(),
+ &vocabulary,
+ &[
+ "archive_read_open_memory".to_owned(),
+ "archive_read_next_header".to_owned(),
+ "archive_read_data".to_owned(),
+ ],
+ );
+ assert!(steps.is_empty(), "{steps:?}");
+ }
+
+ // Isolates the invented-value ban. `archive_read_set_format(a, int)` takes our handle and
+ // every argument resolves - the Config pins to 0 - so both other gates pass it. The author
+ // wrote a format constant there; a 0 is a different program wearing the same name, and the
+ // census found this to be the ONLY shape any tail in the validation set offers:
+ // libjpeg-turbo's `tj3Set(handle, TJPARAM_SCANLIMIT, 500)` would have been emitted as
+ // `tj3Set(ctx, 0, 0)`, and `tj3SetScalingFactor`'s struct-by-value would not even compile.
+ #[test]
+ fn a_step_that_needs_an_invented_constant_is_not_appended() {
+ let mut vocabulary = replayable_archive_vocabulary();
+ vocabulary.functions.insert(
+ "archive_read_set_format".to_owned(),
+ vec![archive_handle(), param("code", "int", Shape::Integral)],
+ );
+ assert!(
+ upward_steps(
+ &open_memory(),
+ &vocabulary,
+ &[
+ "archive_read_open_memory".to_owned(),
+ "archive_read_set_format".to_owned(),
+ ],
+ )
+ .is_empty()
+ );
+ }
+
+ #[test]
+ fn a_step_taking_a_string_is_not_appended_any_more_than_it_is_replayed() {
+ assert!(
+ upward_of(&[
+ "archive_read_open_memory",
+ "archive_read_set_options",
+ "archive_read_data",
+ ])
+ .is_empty(),
+ "the climb stops at the first call it cannot copy, exactly as the replay does"
+ );
+ }
+
+ #[test]
+ fn the_climb_is_capped_however_long_the_tail_is() {
+ let mut vocabulary = replayable_archive_vocabulary();
+ let mut sequence = vec!["archive_read_open_memory".to_owned()];
+ for index in 0..MAX_UPWARD_STEPS + 3 {
+ let name = format!("archive_read_step{index}");
+ vocabulary
+ .functions
+ .insert(name.clone(), vec![archive_handle()]);
+ sequence.push(name);
+ }
+ assert_eq!(
+ upward_steps(&open_memory(), &vocabulary, &sequence).len(),
+ MAX_UPWARD_STEPS
+ );
+ }
+
+ fn extended_body() -> HarnessPlan {
+ let plans = plan_candidate_with(
+ &open_memory(),
+ "archive.h",
+ &replayable_archive_vocabulary(),
+ &[
+ "archive_read_new".to_owned(),
+ "archive_read_open_memory".to_owned(),
+ "archive_read_data".to_owned(),
+ ],
+ )
+ .unwrap();
+ let steps = upward_steps(
+ &open_memory(),
+ &replayable_archive_vocabulary(),
+ &[
+ "archive_read_open_memory".to_owned(),
+ "archive_read_data".to_owned(),
+ ],
+ );
+ assert_eq!(steps.len(), 1, "the fixture must offer exactly one step");
+ extend(&plans[0], &steps)
+ }
+
+ // Isolates the insertion point. Appending to the end of the body instead would put the
+ // step after `archive_read_free`, which is a use-after-free reported inside the library -
+ // the D12 fabricated-crash class, arriving through a mechanism meant to add reach.
+ #[test]
+ fn an_appended_call_lands_after_the_entry_and_before_the_teardown() {
+ let plan = extended_body();
+ let order: Vec<&str> = plan
+ .body
+ .iter()
+ .filter_map(|statement| match statement {
+ Stmt::Call { function, .. } => Some(function.as_str()),
+ _ => None,
+ })
+ .collect();
+ let entry = order
+ .iter()
+ .position(|call| *call == "archive_read_open_memory")
+ .unwrap();
+ let step = order
+ .iter()
+ .position(|call| *call == "archive_read_data")
+ .unwrap();
+ let teardown = order
+ .iter()
+ .position(|call| *call == "archive_read_free")
+ .unwrap();
+ assert!(entry < step && step < teardown, "{order:?}");
+ }
+
+ // The reason `extend` rebuilds through `with` rather than cloning and splicing: the step
+ // binds an out buffer the base plan never needed, and the four scaffolding flags are what
+ // make the emitter declare it, size it and free it. A spliced body would call the step
+ // with a variable that was never declared.
+ #[test]
+ fn an_appended_call_brings_its_own_scaffolding() {
+ let plan = extended_body();
+ assert!(plan.needs_out_buffer);
+ let rendered = emit::render(&plan, "extended.c");
+ let out = crate::plan::OUT_LOCAL;
+ assert!(rendered.contains(out), "{rendered}");
+ assert!(rendered.contains(&format!("free({out});")), "{rendered}");
+ }
+
+ #[test]
+ fn the_appended_names_are_recorded_apart_from_the_replayed_ones() {
+ let plan = extended_body();
+ assert_eq!(plan.extended, ["archive_read_data"]);
+ assert!(
+ !plan.replayed.contains(&"archive_read_data".to_owned()),
+ "a call the author made AFTER the entry point is not setup"
+ );
+ }
+
// Isolates `is_configuration_shape`, the single test behind both halves of the ladder.
#[test]
fn a_call_taking_only_handles_configures_and_one_taking_a_buffer_does_not() {
diff --git a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex/src/main.rs b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex/src/main.rs
index c2c9de3d..89495c7b 100644
--- a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex/src/main.rs
+++ b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex/src/main.rs
@@ -17,6 +17,7 @@ use lisdex_core::store::Store;
use lisdex_fuzz::runner::{self, AflOptions};
use lisdex_harness::coverage::EdgeSet;
use lisdex_harness::emit;
+use lisdex_harness::search;
use lisdex_harness::synth;
use lisdex_harness::verify::{Bench, Corpus, Toolchain, Verdict};
use lisdex_ingest::acquire::{self, Source};
@@ -365,122 +366,84 @@ fn harness(args: &HarnessArgs) -> Result<(), Box<dyn Error>> {
return Ok(());
}
- let bench = if args.no_verify {
+ let sequence = authored_sequence(&analysis);
+ let ranked = ladder_ordered(&analysis);
+ let attempts: Vec<search::Attempt> = ranked
+ .into_iter()
+ .take(args.top)
+ .map(|candidate| {
+ let include = include_of(candidate, &root);
+ match synth::plan_candidate_with(candidate, &include, &vocabulary, sequence) {
+ Ok(variants) => search::Attempt::Planned {
+ name: candidate.name.clone(),
+ variants,
+ steps: synth::upward_steps(candidate, &vocabulary, sequence),
+ },
+ Err(refusal) => search::Attempt::Refused {
+ name: candidate.name.clone(),
+ refusal,
+ },
+ }
+ })
+ .collect();
+
+ // Created before either branch: `--no-verify` writes the promoted harness straight into it
+ // and used to depend on the candidates directory being made first for it to exist at all.
+ std::fs::create_dir_all(&args.out)?;
+
+ if args.no_verify {
println!("{UNVERIFIED_BANNER}");
- None
- } else {
- Some(
- args.oracle
- .bench(parse.includes.clone(), parse.defines.clone(), &args.out)?,
- )
- };
+ return unverified(&attempts, &args.out);
+ }
+ let bench = args
+ .oracle
+ .bench(parse.includes.clone(), parse.defines.clone(), &args.out)?;
let candidates = args.out.join(CANDIDATES_DIR);
// Stale variants from an earlier run are indistinguishable from this run's evidence.
let _ = std::fs::remove_dir_all(&candidates);
std::fs::create_dir_all(&candidates)?;
- let mut rejected = Vec::new();
- let mut accepted = EdgeSet::new();
- let mut survivors: Vec<Survivor> = Vec::new();
- let sequence = authored_sequence(&analysis);
-
- for candidate in ladder_ordered(&analysis).into_iter().take(args.top) {
- let include = include_of(candidate, &root);
- let plans = match synth::plan_candidate_with(candidate, &include, &vocabulary, sequence) {
- Ok(plans) => plans,
- Err(refusal) => {
- rejected.push(format!(" {} - refused: {refusal}", candidate.name));
- continue;
- }
- };
-
- // Every variant is written before any is judged: the rejected ones are the
- // evidence trail, and the gate uses them as ready-made negative controls.
- let mut emitted = Vec::with_capacity(plans.len());
- for (index, plan) in plans.iter().enumerate() {
- let label = format!("{}.v{index}", candidate.name);
- let filename = format!("{label}.c");
- let source = candidates.join(&filename);
- std::fs::write(&source, emit::render(plan, &filename))?;
- emitted.push((label, source));
- }
-
- for ((label, source), plan) in emitted.iter().zip(&plans) {
- let Some(bench) = &bench else {
- return promote(
- plan,
- candidate.name.as_str(),
- &args.out,
- plans.len(),
- None,
- 0,
- );
- };
-
- // No parent: D4's linearity oracle measures a candidate against the shorter
- // call sequence it EXTENDS, and variants run most-populated first, so no
- // later variant extends an earlier one. Feeding it a sibling would reject the
- // fallback for a constant gain of zero, which is true and meaningless.
- // One candidate's toolchain failure must not kill the other nineteen.
- let against = accepted.len();
- let verdict = match bench.verify(source, label, None, &accepted) {
- Ok(verdict) => verdict,
- Err(err) => {
- rejected.push(format!(" {label} - could not be judged: {err}"));
- continue;
- }
- };
- match &verdict.outcome {
- Ok(reached) => {
- let novel = reached.novel_against(&accepted);
- accepted.absorb(reached);
- promote(
- plan,
- candidate.name.as_str(),
- &args.out,
- plans.len(),
- Some(&verdict),
- against,
- )?;
- survivors.push(Survivor {
- name: candidate.name.clone(),
- edges: reached.len(),
- novel,
- judged_against: against,
- });
- // Variants of ONE candidate are alternatives, not distinct harnesses:
- // they call the same entry point with more or less of its context
- // populated. Taking the first that survives and moving on is what
- // makes the accumulated set a set of ENTRY POINTS.
- break;
- }
- Err(rejection) => rejected.push(format!(" {label} - {rejection}")),
- }
- }
+ let outcome = search::accumulate(&attempts, &bench, &candidates)?;
+ for survivor in &outcome.survivors {
+ promote(
+ &survivor.plan,
+ &survivor.name,
+ &args.out,
+ survivor.variants,
+ Some(&survivor.verdict),
+ survivor.judged_against,
+ survivor.steps,
+ )?;
}
-
- report_rejections(&rejected);
- if survivors.is_empty() {
+ report_rejections(&outcome.rejected);
+ if outcome.survivors.is_empty() {
println!("no candidate in the top {} survived the oracles:", args.top);
return Err("no harness synthesized".into());
}
- report_survivors(&survivors, accepted.len());
+ report_survivors(&outcome.survivors, outcome.accepted.len());
Ok(())
}
-// What the global-novelty oracle actually decided, per survivor. `judged_against` is the
-// size of the accepted set at the moment this candidate was judged: 0 means it was first
-// and the oracle could only reject a harness reaching nothing, which is the weak form B51
-// described. Anything above 0 is the oracle discriminating for real.
-struct Survivor {
- name: String,
- edges: usize,
- novel: usize,
- judged_against: usize,
+// `--no-verify` promotes the first candidate that plans and stops. It cannot climb: an
+// extension only earns its place against a parent that PASSED, and with no bench nothing has
+// passed. Saying so is the whole content of the banner above.
+fn unverified(attempts: &[search::Attempt], out: &std::path::Path) -> Result<(), Box<dyn Error>> {
+ for attempt in attempts {
+ if let search::Attempt::Planned {
+ name,
+ variants,
+ steps: _,
+ } = attempt
+ && let Some(plan) = variants.first()
+ {
+ return promote(plan, name, out, variants.len(), None, 0, 0);
+ }
+ }
+ Err("no harness synthesized".into())
}
-fn report_survivors(survivors: &[Survivor], total: usize) {
+fn report_survivors(survivors: &[search::Survivor], total: usize) {
println!(
"\n{} harness(es) survived the oracles, covering {total} edges in total:",
survivors.len()
@@ -494,7 +457,19 @@ fn report_survivors(survivors: &[Survivor], total: usize) {
survivor.novel, survivor.judged_against
)
};
- println!(" {} - {} edges, {novelty}", survivor.name, survivor.edges);
+ let climbed = if survivor.steps == 0 {
+ String::new()
+ } else {
+ format!(
+ ", extended by {} author call(s): {}",
+ survivor.steps,
+ survivor.plan.extended.join(", ")
+ )
+ };
+ println!(
+ " {} - {} edges, {novelty}{climbed}",
+ survivor.name, survivor.edges
+ );
}
}
@@ -581,12 +556,21 @@ fn plan_only(
" "
};
match synth::plan_candidate_with(candidate, &include, vocabulary, sequence) {
- Ok(plans) => println!(
- "{order:>3}. {authored} PLANS {} ({} variant(s)), replaying {:?}",
- candidate.name,
- plans.len(),
- plans.first().map_or(&[][..], |plan| &plan.replayed)
- ),
+ Ok(plans) => {
+ println!(
+ "{order:>3}. {authored} PLANS {} ({} variant(s)), replaying {:?}",
+ candidate.name,
+ plans.len(),
+ plans.first().map_or(&[][..], |plan| &plan.replayed)
+ );
+ // On its own line, because the replay line is what the M3 gate asserts a
+ // teardown never appears in, and a tail that legitimately contains one would
+ // have turned that assertion red from the other side of the entry point.
+ let steps = synth::upward_steps(candidate, vocabulary, sequence);
+ if !steps.is_empty() {
+ println!(" extending {:?}", step_names(&steps));
+ }
+ }
Err(refusal) => println!(
"{order:>3}. {authored} refused {} - {refusal}",
candidate.name
@@ -595,6 +579,10 @@ fn plan_only(
}
}
+fn step_names(steps: &[lisdex_harness::synth::Extension]) -> Vec<&str> {
+ steps.iter().map(|step| step.function.as_str()).collect()
+}
+
fn report_rejections(rejected: &[String]) {
// Printed on SUCCESS too: a libarchive user handed a date parser needs to see that the
// archive readers above it were refused, not just the winner.
@@ -614,6 +602,7 @@ fn promote(
variants: usize,
verdict: Option<&Verdict>,
judged_against: usize,
+ steps: usize,
) -> Result<(), Box<dyn Error>> {
// Rendered again rather than copied so the file header names the file it is in.
let filename = format!("{name}.c");
@@ -636,11 +625,12 @@ fn promote(
);
// Naming the oracles that actually ran, because saying "all four" was a lie
// while two of D4's four could not discriminate. Oracle 4 discriminates from
- // the SECOND acceptance onward, so what it did is a property of THIS verdict
- // rather than of the build, and it is reported per harness.
+ // the SECOND acceptance onward and oracle 3b only from the first upward step,
+ // so what they did is a property of THIS verdict rather than of the build, and
+ // both are reported per harness.
println!(
"oracles run: {}",
- oracles_run(invalid > 0, judged_against > 0)
+ oracles_run(invalid > 0, judged_against > 0, steps > 0)
);
}
None => println!("{UNVERIFIED_BANNER}"),
@@ -648,8 +638,11 @@ fn promote(
Ok(())
}
-fn oracles_run(differential: bool, novelty_discriminated: bool) -> String {
+fn oracles_run(differential: bool, novelty_discriminated: bool, climbed: bool) -> String {
let mut ran = vec!["1 compilation", "2 execution", "3a inter-seed divergence"];
+ if climbed {
+ ran.push("3b non-linear delta");
+ }
if differential {
ran.push("3c valid-vs-invalid differential");
}
@@ -666,10 +659,12 @@ fn oracles_run(differential: bool, novelty_discriminated: bool) -> String {
first acceptance, so there was no accepted set to be novel against",
);
}
- line.push_str(
- "; 3b non-linear delta needs a call-sequence parent, which a single-call harness \
- does not have",
- );
+ if !climbed {
+ line.push_str(
+ "; 3b non-linear delta needs a call-sequence parent, which a single-call harness \
+ does not have",
+ );
+ }
line
}
diff --git a/PROJECTS/advanced/zero-day-vulnerability-scanner/scripts/m3-gate.sh b/PROJECTS/advanced/zero-day-vulnerability-scanner/scripts/m3-gate.sh
index 4f85f817..9bebdcbb 100755
--- a/PROJECTS/advanced/zero-day-vulnerability-scanner/scripts/m3-gate.sh
+++ b/PROJECTS/advanced/zero-day-vulnerability-scanner/scripts/m3-gate.sh
@@ -450,6 +450,82 @@ else
bad "lz4 emitted nothing to check for B72"
fi
+# B51(b). The upward call-sequence search: the parent for oracle 3b comes from appending the
+# next call the AUTHOR made, never from truncating the setup in front of the entry point.
+#
+# The population was censused over all seven analysable trees before this was built and it is
+# ZERO: no candidate that plans has a tail this rule can copy. libjpeg-turbo's
+# `tj3DecompressHeader` is the only entry point whose own author sequence continues past it with
+# anything, and the next call is `tj3Get(handle, TJPARAM_...)` - a constant the headers do not
+# state. So the accepting direction has NO real tree and has to be asserted on a synthetic one,
+# exactly as B30's second assertion is. The rejecting direction is asserted on libarchive, whose
+# real tail leads with a call that cannot bind.
+banner "M5 UPWARD CALL-SEQUENCE SEARCH"
+
+UPTREE="$WORK/upward/mylib"
+rm -rf "$WORK/upward"
+mkdir -p "$UPTREE/include" "$UPTREE/fuzz"
+cat >"$UPTREE/include/mylib.h" <<'MYLIB_H'
+#include <stddef.h>
+
+struct mylib;
+
+struct mylib *mylib_new(void);
+int mylib_open_memory(struct mylib *m, const void *buff, size_t size);
+int mylib_read_data(struct mylib *m, void *out, size_t len);
+void mylib_free(struct mylib *m);
+MYLIB_H
+cat >"$UPTREE/fuzz/mylib_fuzzer.c" <<'MYLIB_FUZZ'
+#include <stdint.h>
+
+#include "mylib.h"
+
+int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
+{
+ struct mylib *m = mylib_new();
+ char out[64];
+
+ mylib_open_memory(m, data, size);
+ mylib_read_data(m, out, sizeof out);
+ mylib_free(m);
+ return 0;
+}
+MYLIB_FUZZ
+UPPLAN="$OUT/upward-plan.txt"
+"$LISDEX" harness "$UPTREE" --out "$OUT/upward-out" --plan-only --top 10 >"$UPPLAN" 2>&1
+if grep -q 'extending \["mylib_read_data"\]' "$UPPLAN"; then
+ ok "the author's next call over the handle we hold is appended above the entry point"
+else
+ bad "no upward step was found on a tree built to offer exactly one: $(cat "$UPPLAN")"
+fi
+# `mylib_read_data` binds an out buffer and a capacity the HARNESS owns, which is the only
+# argument shape a step may have besides a handle. It is not a candidate in its own right - it
+# takes no input - so this is reach the entry-point ranking cannot reach by itself.
+if grep -q 'PLANS mylib_read_data' "$UPPLAN"; then
+ bad "mylib_read_data planned as an entry point, so this asserts nothing about the climb"
+else
+ ok "and it is a call that cannot stand alone as an entry point"
+fi
+# The teardown ends the sequence. Appending past `mylib_free` would hand every later step a
+# handle the plan had already freed, which is a crash inside the library that we manufactured.
+if grep -q 'mylib_free' "$UPPLAN"; then
+ bad "the author's teardown was appended as a step: $(grep extending "$UPPLAN")"
+else
+ ok "the climb stops at the author's own teardown"
+fi
+# The measured gap, on a real tree: libarchive's tail is `archive_read_next_header,
+# archive_entry_pathname, archive_entry_size, archive_read_data`. The first takes
+# `struct archive_entry **` and cannot bind, and appending `archive_read_data` over that gap
+# would read from a stream whose header was never read - B66's semantically dead harness
+# arriving through the mechanism meant to add depth.
+if echo "$LADDER_ARCHIVE" | grep -q "extending"; then
+ bad "libarchive appended a step across a call it cannot copy: \
+$(echo "$LADDER_ARCHIVE" | grep extending | head -1)"
+else
+ ok "libarchive appends nothing, because the call in front of its tail cannot bind"
+fi
+rm -rf "$WORK/upward"
+
# The negative control the ladder must REFUSE to help: a tree with nothing to mine has no
# authored floor, so the ranking alone decides and no setup is invented.
BARE="$WORK/ladder-bare"
diff --git a/PROJECTS/advanced/zero-day-vulnerability-scanner/scripts/m4-gate.sh b/PROJECTS/advanced/zero-day-vulnerability-scanner/scripts/m4-gate.sh
index dc174e1d..3ae8c10a 100755
--- a/PROJECTS/advanced/zero-day-vulnerability-scanner/scripts/m4-gate.sh
+++ b/PROJECTS/advanced/zero-day-vulnerability-scanner/scripts/m4-gate.sh
@@ -41,11 +41,11 @@ fi
mkdir -p "$GATE"
-log "stage 1/11: build lisdex"
+log "stage 1/12: build lisdex"
cargo build -p lisdex
[ -x "$LISDEX_BIN" ] || die "lisdex binary not found at $LISDEX_BIN"
-log "stage 2/11: every oracle answers for itself"
+log "stage 2/12: every oracle answers for itself"
# The end-to-end controls below cannot isolate one coverage oracle from another: the stub
# and the unpopulated variant are each rejected by BOTH 3a and 3c, so either one alone
# keeps the gate green while the other is gutted. Each oracle owns unit tests that no
@@ -57,7 +57,7 @@ else
fail "the oracle crate's own tests do not pass - one of the four oracles is not doing its job"
fi
-log "stage 3/11: assemble the two corpora the oracles need"
+log "stage 3/12: assemble the two corpora the oracles need"
mkdir -p "$GATE"
rm -rf "$CORPUS" "$INVALID" "$CONTROLS"
mkdir -p "$CORPUS" "$INVALID" "$CONTROLS"
@@ -98,7 +98,7 @@ lisdex_verify() {
"$LISDEX_BIN" verify "$SRC" --include "$REPO" --work "$SCRATCH" "${FLAGS[@]}"
}
-log "stage 4/11: lisdex synthesizes AND self-verifies a harness with NO LLM"
+log "stage 4/12: lisdex synthesizes AND self-verifies a harness with NO LLM"
rm -rf "$SYNTH"
mapfile -d '' HARNESS_FLAGS < <(oracle_flags)
"$LISDEX_BIN" harness "$REPO" --out "$SYNTH" --top "$TOP" "${HARNESS_FLAGS[@]}" \
@@ -165,7 +165,7 @@ build_harness() {
)
}
-log "stage 5/11: independent cross-check - it compiles and every valid seed runs clean"
+log "stage 5/12: independent cross-check - it compiles and every valid seed runs clean"
if build_harness "$ENTRY" "$GATE/harness" afl 2>"$GATE/compile.log"; then
pass "synthesized harness compiles and links"
else
@@ -189,7 +189,7 @@ else
fail "$CRASHED/$SEEDS valid seeds crash or leak - the oracle would be unsound"
fi
-log "stage 6/11: the shipped judge ACCEPTS the harness it chose"
+log "stage 6/12: the shipped judge ACCEPTS the harness it chose"
if lisdex_verify "$ENTRY" "$GATE/verify-accepted" > "$GATE/verify-accepted.log" 2>&1; then
EDGES="$(grep -m1 -oE 'ACCEPTED.* - [0-9]+ edges' "$GATE/verify-accepted.log" \
| grep -oE '[0-9]+ edges' | grep -oE '^[0-9]+' || echo 0)"
@@ -203,7 +203,7 @@ else
fail "the shipped judge rejects the harness lisdex itself accepted"
fi
-log "stage 7/11: NEGATIVE CONTROL - a stub that ignores its input must be REJECTED"
+log "stage 7/12: NEGATIVE CONTROL - a stub that ignores its input must be REJECTED"
cat > "$CONTROLS/stub.c" <<'STUB'
// ©AngelaMos | 2026
// stub.c
@@ -231,7 +231,7 @@ else
fi
fi
-log "stage 8/11: NEGATIVE CONTROL - the unpopulated struct variant must be REJECTED"
+log "stage 8/12: NEGATIVE CONTROL - the unpopulated struct variant must be REJECTED"
VARIANTS="$(find "$SYNTH/candidates" -maxdepth 1 -name "$ENTRY_NAME.v*.c" | sort -V)"
VARIANT_COUNT="$(printf '%s\n' "$VARIANTS" | grep -c . || true)"
if [ "${VARIANT_COUNT:-0}" -lt 2 ]; then
@@ -246,7 +246,7 @@ else
fi
fi
-log "stage 9/11: NEGATIVE CONTROL - a harness that crashes on a valid seed must be REJECTED"
+log "stage 9/12: NEGATIVE CONTROL - a harness that crashes on a valid seed must be REJECTED"
cat > "$CONTROLS/crasher.c" <<'CRASHER'
// ©AngelaMos | 2026
// crasher.c
@@ -284,7 +284,7 @@ else
fi
fi
-log "stage 10/11: NEGATIVE CONTROL - a harness that leaks on a valid seed must be REJECTED"
+log "stage 10/12: NEGATIVE CONTROL - a harness that leaks on a valid seed must be REJECTED"
cat > "$CONTROLS/leaker.c" <<'LEAKER'
// ©AngelaMos | 2026
// leaker.c
@@ -321,7 +321,7 @@ else
fi
fi
-log "stage 11/11: lisdex drives a campaign against the SYNTHESIZED harness"
+log "stage 11/12: lisdex drives a campaign against the SYNTHESIZED harness"
rm -rf "$FINDINGS" "$DB"
"$LISDEX_BIN" fuzz \
--target "$GATE/harness" \
@@ -364,6 +364,205 @@ else
fail "crash is not an attributable magma canary trigger"
fi
+log "stage 12/12: oracle 3b judges an UPWARD extension, in both directions"
+# B51(b). Oracle 3b measures a candidate against the shorter call sequence it EXTENDS, so it
+# needs a library whose author sequence continues past the entry point with a call this harness
+# can copy. The census says no tree in the validation set has one - libpng's tail is
+# `png_image_finish_read`, whose pixel buffer needs a caller-supplied extent (B67) - so the
+# oracle is exercised on a synthetic library built here, the same way B30's second assertion
+# needs a synthetic tree. Everything below runs through the shipped `judge()`.
+#
+# TWO trees over ONE library, differing only in WHICH call the author appended. That is what
+# makes this a control rather than a demonstration: the harness shape, the seeds, the library and
+# the entry point are identical, so only the appended call's own behaviour can move the verdict.
+LAB="$GATE/upward"
+rm -rf "$LAB"
+mkdir -p "$LAB/lib" "$LAB/seeds" "$LAB/scan/include" "$LAB/scan/fuzz" "$LAB/touch/include" \
+ "$LAB/touch/fuzz"
+cat >"$LAB/lib/mylib.h" <<'LAB_H'
+#include <stddef.h>
+
+struct mylib;
+
+struct mylib *mylib_new(void);
+int mylib_open_memory(struct mylib *m, const void *buff, size_t size);
+int mylib_scan(struct mylib *m);
+int mylib_touch(struct mylib *m);
+void mylib_free(struct mylib *m);
+LAB_H
+cat >"$LAB/lib/mylib.c" <<'LAB_C'
+#include <stdlib.h>
+
+#include "mylib.h"
+
+struct mylib {
+ const unsigned char *data;
+ size_t size;
+ size_t pos;
+ unsigned long acc;
+};
+
+/* Eight distinct blocks per switch, because the base harness has to clear oracle 3a's
+ inter-seed divergence floor of 5 edges before there is anything to extend at all. */
+#define STEP(n) static void step##n(struct mylib *m) { m->acc += n * 7u + 1u; }
+STEP(0) STEP(1) STEP(2) STEP(3) STEP(4) STEP(5) STEP(6) STEP(7)
+#define EXTRA(n) static void extra##n(struct mylib *m) { m->acc ^= n * 11u + 3u; }
+EXTRA(0) EXTRA(1) EXTRA(2) EXTRA(3) EXTRA(4) EXTRA(5) EXTRA(6) EXTRA(7)
+
+struct mylib *mylib_new(void) { return (struct mylib *)calloc(1, sizeof(struct mylib)); }
+
+int mylib_open_memory(struct mylib *m, const void *buff, size_t size)
+{
+ size_t i;
+ const unsigned char *bytes = (const unsigned char *)buff;
+
+ if (m == NULL || bytes == NULL || size == 0) { return -1; }
+ m->data = bytes;
+ m->size = size;
+ m->pos = 1;
+ for (i = 0; i < size && i < 24; i++) {
+ switch (bytes[i] & 7u) {
+ case 0: step0(m); break;
+ case 1: step1(m); break;
+ case 2: step2(m); break;
+ case 3: step3(m); break;
+ case 4: step4(m); break;
+ case 5: step5(m); break;
+ case 6: step6(m); break;
+ default: step7(m); break;
+ }
+ }
+ return 0;
+}
+
+int mylib_scan(struct mylib *m)
+{
+ size_t i;
+
+ if (m == NULL || m->data == NULL) { return -1; }
+ for (i = m->pos; i < m->size && i < 40; i++) {
+ switch ((m->data[i] >> 5) & 7u) {
+ case 0: extra0(m); break;
+ case 1: extra1(m); break;
+ case 2: extra2(m); break;
+ case 3: extra3(m); break;
+ case 4: extra4(m); break;
+ case 5: extra5(m); break;
+ case 6: extra6(m); break;
+ default: extra7(m); break;
+ }
+ }
+ return 0;
+}
+
+/* The same four blocks on every input, which is the whole point of the control: oracle 3b has
+ to see one constant gain per seed and reject, where `mylib_scan` above varies. */
+int mylib_touch(struct mylib *m)
+{
+ if (m == NULL) { return -1; }
+ extra0(m);
+ extra1(m);
+ extra2(m);
+ extra3(m);
+ return 0;
+}
+
+void mylib_free(struct mylib *m) { free(m); }
+LAB_C
+lab_target() {
+ cat >"$LAB/$1/fuzz/mylib_fuzzer.c" <<LAB_FUZZ
+#include <stdint.h>
+
+#include "mylib.h"
+
+int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
+{
+ struct mylib *m = mylib_new();
+
+ mylib_open_memory(m, data, size);
+ mylib_$1(m);
+ mylib_free(m);
+ return 0;
+}
+LAB_FUZZ
+ cp "$LAB/lib/mylib.h" "$LAB/$1/include/mylib.h"
+}
+lab_target scan
+lab_target touch
+python3 - "$LAB/seeds" <<'LAB_SEEDS'
+import sys, os
+target = sys.argv[1]
+for index in range(8):
+ body = bytes((index * 37 + offset * 11) % 251 for offset in range(1 + index * 5))
+ with open(os.path.join(target, f"seed-{index:02d}"), "wb") as handle:
+ handle.write(body)
+LAB_SEEDS
+
+# The library is instrumented ONCE, by afl-clang-fast, and its edge IDs are baked into the
+# object file. This is load-bearing and was measured: with an LTO-BITCODE archive
+# `afl-clang-lto` re-instruments the whole program at every link, so appending one call to the
+# harness renumbered every library edge - a parent's {13, 15, 32} became the child's
+# {12, 14, 31, 35} for the same seed, sharing NOTHING - and the per-seed gains then varied with
+# map size rather than with the input, which ACCEPTED a call doing identical work on every seed.
+(
+ cd "$LAB/lib"
+ env AFL_USE_ASAN=1 AFL_USE_UBSAN=1 AFL_QUIET=1 \
+ afl-clang-fast -g -O1 -I. -c mylib.c -o mylib.o
+ llvm-ar rcs libmylib.a mylib.o
+) >"$LAB/build.log" 2>&1 || die "the synthetic oracle-3b library does not build"
+
+lab_run() {
+ "$LISDEX_BIN" harness "$LAB/$1" --out "$LAB/out-$1" --top 6 \
+ --seeds "$LAB/seeds" --archive "$LAB/lib/libmylib.a" --driver "$DRIVER" \
+ >"$LAB/$1.log" 2>&1
+}
+
+if lab_run scan && grep -q 'extended by 1 author call(s): mylib_scan' "$LAB/scan.log"; then
+ pass "an appended call whose coverage depends on the input is ACCEPTED by oracle 3b"
+else
+ tail -6 "$LAB/scan.log" >&2
+ fail "oracle 3b rejected an extension that genuinely reads the input"
+fi
+if grep -q '3b non-linear delta' "$LAB/scan.log"; then
+ pass "and the oracle report names 3b as having run, which no other run in this gate can"
+else
+ fail "the extension was accepted without oracle 3b being reported as run"
+fi
+# The rejecting direction, and the first one this project has ever measured end to end.
+lab_run touch
+if grep -q 'every seed gained the same' "$LAB/touch.log"; then
+ pass "$(grep -m1 'every seed gained the same' "$LAB/touch.log" | sed 's/^ *//' | cut -c1-108)"
+else
+ tail -6 "$LAB/touch.log" >&2
+ fail "oracle 3b ACCEPTED a call that does identical work on every seed"
+fi
+# The parent must still stand: an extension is judged, and losing that judgement costs the depth,
+# never the harness underneath it.
+if grep -qE '^1 harness\(es\) survived' "$LAB/touch.log" \
+ && ! grep -q 'extended by' "$LAB/touch.log"; then
+ pass "the rejected extension left its parent standing as the survivor"
+else
+ fail "a rejected extension took the accepted harness underneath it with it"
+fi
+# The guard on the oracle itself. Same tree, same seeds, an LTO-bitcode archive: the two maps no
+# longer share a numbering, and the oracle must REFUSE to give a verdict rather than read the
+# renumbering as an input-dependent gain.
+(
+ cd "$LAB/lib"
+ env AFL_USE_ASAN=1 AFL_USE_UBSAN=1 AFL_QUIET=1 \
+ afl-clang-lto -g -O1 -I. -c mylib.c -o mylib_lto.o
+ llvm-ar rcs libmylib_lto.a mylib_lto.o
+) >>"$LAB/build.log" 2>&1 || die "the LTO variant of the synthetic library does not build"
+"$LISDEX_BIN" harness "$LAB/touch" --out "$LAB/out-lto" --top 6 \
+ --seeds "$LAB/seeds" --archive "$LAB/lib/libmylib_lto.a" --driver "$DRIVER" \
+ >"$LAB/lto.log" 2>&1
+if grep -q 'do not describe the same numbering' "$LAB/lto.log"; then
+ pass "an LTO relink renumbers the map and the oracle refuses the verdict instead of guessing"
+else
+ tail -6 "$LAB/lto.log" >&2
+ fail "the incomparable-map guard did not fire on a relinked LTO archive"
+fi
+
printf '\n'
if [ "$FAILURES" -eq 0 ]; then
printf '[m4] M4 EXIT GATE PASSED - the none tier synthesized and self-verified a harness with no LLM\n'