aien-protocols-mv
Canonical specifications, wire protocols, and schemas for the AIEN sovereign ecosystem
Brought by drakestapleton
GitHub aien-dev/aien-protocols-mv#68 (code only)
Fetch it
curl -fsSL https://interplane.io/drakestapleton/aien-protocols-mv/patches/8757e36dbf095c98.bundle -o 8757e36dbf095c98.bundle git fetch 8757e36dbf095c98.bundle refs/pull/68/head
Provenance
github-import 1
aien-dev/aien-protocols-mv
68
ccfbb2d6806e0931bba5bfde30fe5254ab286505
{"kind":"github-import","owner":"aien-dev","repo":"aien-protocols-mv","number":68,"url":"https://github.com/aien-dev/aien-protocols-mv/pull/68","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:39:47Z","metadata":"unavailable","state_derived":true}
Changes
diff --git a/CHANGELOG.md b/CHANGELOG.md index 6021e8e..8e5ec12 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,31 @@ VERSIONING.md. ## [Unreleased] +### Security: Aienet-0 audit repairs (2026-10-28) + +- `aien-microjob` 0.2.0 closes A6/A7/A8: stored countersignatures must + bind the rebuilt commitment in both AN0V and MJR1; admission refuses + insufficient matmul fuel and expired nodes, including `DagRun` admission. + MJB1, MJR1, AN0B and AN0V wire bytes and versions are unchanged. +- A15 is a security API cutover: `DagRun::log` and `restore` now exchange + ordered receiver-local `LedgerEvent::Receipt` and `LedgerEvent::Cancelled` + values, preserving cancellation across restart. Receipt replay and repeated + cancellation remain idempotent; restoration rejects a new receipt after + cancellation. Migrate every persistence caller to store both event kinds + atomically in its own durable storage, bound to the accepted document. + No stable serialization is defined by this Rust enum. Historical + receipt-only logs do not establish cancellation history: do not silently + wrap them as receipt events and resume. Migration requires independently + trusted receiver state establishing cancellation status. The security + exception removes the receipt-only API without a compatibility fallback. +- A4/A5: `parity.sh` refuses failed builds, missing tools and malformed or + empty oracle output with exit 2; exit 1 denotes a behavioral mismatch. + `mutants.sh` requires the pinned Omega prerequisites, establishes baseline + parity, and never counts invalid setup/output as a killed Omega mutant. + `specs/aienet/jobpath/check-harness.sh` injects deterministic runner faults. + Historical evidence under `evidence/aienet0-20261028` is unchanged and is + not a receipt for these repairs. + ### Aienet-0 authenticated ledger test adapter - Restore the archived settlement runner as `scripts/aienet0/settle-run.sh` and diff --git a/Cargo.lock b/Cargo.lock index 1557ede..296f803 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -98,7 +98,7 @@ dependencies = [ [[package]] name = "aien-microjob" -version = "0.1.0" +version = "0.2.0" dependencies = [ "aien-provenance", "getrandom 0.4.3", diff --git a/crates/aien-microjob/Cargo.toml b/crates/aien-microjob/Cargo.toml index 4fd5577..c03890c 100644 --- a/crates/aien-microjob/Cargo.toml +++ b/crates/aien-microjob/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "aien-microjob" -version = "0.1.0" +version = "0.2.0" edition = "2021" license = "Apache-2.0" description = "MJB1 typed bounded microjob DAG and MJR1 receipt: reader, writer, checker and receipt ledger (specs/microjob)" diff --git a/crates/aien-microjob/src/aienet0.rs b/crates/aien-microjob/src/aienet0.rs index b095337..fa80bbc 100644 --- a/crates/aien-microjob/src/aienet0.rs +++ b/crates/aien-microjob/src/aienet0.rs @@ -404,6 +404,7 @@ pub fn admit_bundle( )?; guard(dag.nodes.len() == 1, An0Refusal::NotAllowlisted)?; let node = &dag.nodes[0]; + guard(node.expires_at >= now, An0Refusal::Mjb(Refusal::BadExpiry))?; // AN0-GUARD node-expiry guard( node.kind == kind::COMPUTE && node.op == compute_op::MATMUL, An0Refusal::NotAllowlisted, @@ -427,7 +428,10 @@ pub fn admit_bundle( let job = MatmulU32::decode(payload)?; guard(job.in_bounds(), An0Refusal::OverBudget)?; // AN0-GUARD dim-bounds guard( - node.work >= job.work() && node.memory >= job.memory(), + node.work >= job.work() + && node.fuel >= job.work() + && dag.header.budget_fuel >= job.work() + && node.memory >= job.memory(), An0Refusal::OverBudget, )?; // AN0-GUARD node-caps Ok(Admitted { @@ -565,6 +569,11 @@ pub fn check_countersign( rec[40..72] == r.dag_digest && rec[72..104] == r.output_digest, An0Refusal::BadCountersign, )?; + let commit = verdict_commitment(&r.dag_digest, &r.job_id, &r.output_digest); + guard( + rec[104..136] == commit && r.verifier_verdict == commit, + An0Refusal::BadCountersign, + )?; // AN0-GUARD countersign-commitment Ok(()) } @@ -825,6 +834,78 @@ mod tests { ); } + #[test] + fn admission_checks_fuel_and_node_expiry_boundaries() { + let original = admitted(); + for (fuel, expiry, expected) in [ + (job().work() - 1, NOW, Some(An0Refusal::OverBudget)), + ( + job().work(), + NOW - 1, + Some(An0Refusal::Mjb(Refusal::BadExpiry)), + ), + (job().work(), NOW, None), + ] { + let mut dag = original.dag.clone(); + dag.nodes[0].fuel = fuel; + dag.nodes[0].expires_at = expiry; + let document = encode(&dag).unwrap(); + let bundle = seal_bundle(&document, &original.payload, &key(1)); + let result = admit_bundle(&bundle, &public_key(&key(1)), NOW); + match expected { + Some(refusal) => assert_eq!(result.unwrap_err(), refusal), + None => { + let accepted = result.unwrap(); + let output = matmul_u32_digest(&accepted.job); + let receipt = receipt_for(&accepted, output, &key(3)); + check_receipt(&accepted.document, &receipt, public_key(&key(3)), NOW).unwrap(); + let verdict = countersign(&receipt, output, &key(4)).unwrap(); + check_countersign(&verdict, &receipt, &public_key(&key(4))).unwrap(); + } + } + } + } + + #[test] + fn refuses_validly_signed_inconsistent_countersign_commitments() { + let admitted = admitted(); + let output = matmul_u32_digest(&admitted.job); + let receipt = receipt_for(&admitted, output, &key(3)); + let honest = countersign(&receipt, output, &key(4)).unwrap(); + check_countersign(&honest, &receipt, &public_key(&key(4))).unwrap(); + + let mut verdict = honest; + verdict[104..136].fill(0xEE); + let signature = p256_sign_low_s(&key(4), &verdict_message(&verdict)); + verdict[VERDICT_SIGNED_LEN..].copy_from_slice(&signature); + assert_eq!( + check_countersign(&verdict, &receipt, &public_key(&key(4))), + Err(An0Refusal::BadCountersign) + ); + + // Even matching receipt/verdict fields cannot replace recomputation. + let mut decoded = decode_receipt(&receipt).unwrap(); + decoded.verifier_verdict = [0xEE; 32]; + sign_receipt(&mut decoded, &key(3)); + let receipt = encode_receipt(&decoded); + verdict[8..40].copy_from_slice(&sha(&[&receipt])); + let signature = p256_sign_low_s(&key(4), &verdict_message(&verdict)); + verdict[VERDICT_SIGNED_LEN..].copy_from_slice(&signature); + assert_eq!( + check_countersign(&verdict, &receipt, &public_key(&key(4))), + Err(An0Refusal::BadCountersign) + ); + + // A correct AN0V commitment still cannot bless a wrong MJR1 field. + verdict[104..136].copy_from_slice(&honest[104..136]); + let signature = p256_sign_low_s(&key(4), &verdict_message(&verdict)); + verdict[VERDICT_SIGNED_LEN..].copy_from_slice(&signature); + assert_eq!( + check_countersign(&verdict, &receipt, &public_key(&key(4))), + Err(An0Refusal::BadCountersign) + ); + } + #[test] fn full_path_verifies_and_countersigns() { let a = admitted(); diff --git a/crates/aien-microjob/src/lib.rs b/crates/aien-microjob/src/lib.rs index 9b8e350..469bcdd 100644 --- a/crates/aien-microjob/src/lib.rs +++ b/crates/aien-microjob/src/lib.rs @@ -984,6 +984,17 @@ pub enum Applied { Replay, } +/// Receiver-local persistence event, not a wire record or remote authority. +/// Store events durably, in order, bound to the accepted document. +#[derive(Debug, Clone, PartialEq, Eq)] +// Keep the fixed receipt inline: boxing would allocate per persisted receipt. +// Cancellation appears at most once in the canonical exported log. +#[allow(clippy::large_enum_variant)] +pub enum LedgerEvent { + Receipt([u8; RECEIPT_LEN]), + Cancelled, +} + #[derive(Debug, Clone, Default)] struct Slot { /// Every receipt applied to this node, in order. @@ -1003,7 +1014,7 @@ pub struct DagRun { trusted: Vec<[u8; 33]>, slots: Vec<Slot>, cancelled: bool, - log: Vec<[u8; RECEIPT_LEN]>, + log: Vec<LedgerEvent>, } impl DagRun { @@ -1011,7 +1022,7 @@ impl DagRun { /// receiver's own trusted executor keys. Expired documents are refused. pub fn admit(document: &[u8], trusted: Vec<[u8; 33]>, now: u64) -> Result<Self, Refusal> { let dag = decode(document)?; - if dag.header.expires_at < now { + if dag.header.expires_at < now || dag.nodes.iter().any(|node| node.expires_at < now) { return Err(Refusal::BadExpiry); } let n = dag.nodes.len(); @@ -1025,16 +1036,23 @@ impl DagRun { }) } - /// Rebuild the ledger after a restart by replaying the stored receipt log. + /// Rebuild from the receiver's ordered receipt and cancellation events. + /// Receipt-only historical logs cannot establish cancellation history; + /// migration requires independently trusted receiver state. pub fn restore( document: &[u8], trusted: Vec<[u8; 33]>, now: u64, - log: &[[u8; RECEIPT_LEN]], + log: &[LedgerEvent], ) -> Result<Self, Refusal> { let mut run = Self::admit(document, trusted, now)?; - for r in log { - run.apply(r)?; + for event in log { + match event { + LedgerEvent::Receipt(receipt) => { + run.apply(receipt)?; + } + LedgerEvent::Cancelled => run.cancel(), + } } Ok(run) } @@ -1049,9 +1067,9 @@ impl DagRun { self.digest } - /// Every newly applied receipt in order: what a receiver stores to - /// survive a restart. - pub fn log(&self) -> &[[u8; RECEIPT_LEN]] { + /// Every newly applied receipt and first cancellation, in order. + /// The caller must durably store events before acknowledging their effects. + pub fn log(&self) -> &[LedgerEvent] { &self.log } @@ -1074,7 +1092,10 @@ impl DagRun { /// Cancel the objective: every receipt applied so far stands, every later /// receipt is refused, every non-terminal node becomes CANCELLED. pub fn cancel(&mut self) { - self.cancelled = true; + if !self.cancelled { + self.log.push(LedgerEvent::Cancelled); + self.cancelled = true; + } } /// Apply one receipt (section 5.2). A refusal changes nothing. @@ -1141,7 +1162,7 @@ impl DagRun { slot.done = Some(receipt_digest(&r)); slot.output = Some(r.output_digest); } - self.log.push(stored); + self.log.push(LedgerEvent::Receipt(stored)); Ok(Applied::New) } diff --git a/crates/aien-microjob/tests/ledger.rs b/crates/aien-microjob/tests/ledger.rs index a4ae37c..425ce8c 100644 --- a/crates/aien-microjob/tests/ledger.rs +++ b/crates/aien-microjob/tests/ledger.rs @@ -367,7 +367,7 @@ fn offline_sample_eleven_nodes_with_restart_and_checked_answer() { } // Interrupt: the receiver loses its memory and replays its stored log. - let log: Vec<[u8; RECEIPT_LEN]> = run.log().to_vec(); + let log = run.log().to_vec(); assert_eq!(log.len(), 5); drop(run); let mut run = DagRun::restore(&s.document, trusted(), NOW, &log).expect("restore"); @@ -638,12 +638,77 @@ fn cancel_is_atomic_with_receipts() { let mut run = DagRun::admit(&s.document, trusted(), NOW).unwrap(); let r0 = execute(&mut run, 0, &s.store, &mut outputs); run.cancel(); + let log = run.log().to_vec(); + drop(run); + let mut run = DagRun::restore(&s.document, trusted(), NOW, &log).expect("cancel restore"); let late = signed(receipt(&run, 1, outcome::COMPLETED, 1, &int_bytes(75))); assert_eq!(run.apply(&late), Err(Refusal::Cancelled)); assert_eq!(run.apply(&r0), Ok(Applied::Replay)); assert_eq!(run.state(0), NodeState::Done); assert_eq!(run.state(1), NodeState::Cancelled); assert_eq!(run.state(10), NodeState::Cancelled); + run.cancel(); + assert_eq!(run.log(), log); +} + +#[test] +fn restore_preserves_empty_cancellation_and_event_order() { + let s = sample(); + let mut run = DagRun::admit(&s.document, trusted(), NOW).unwrap(); + let fresh = signed(receipt(&run, 0, outcome::COMPLETED, 1, &int_bytes(75))); + run.cancel(); + run.cancel(); + assert_eq!(run.log(), &[LedgerEvent::Cancelled]); + let mut restored = DagRun::restore(&s.document, trusted(), NOW, run.log()).unwrap(); + assert!(restored.states().iter().all(|s| *s == NodeState::Cancelled)); + assert_eq!(restored.apply(&fresh), Err(Refusal::Cancelled)); + let invalid = [LedgerEvent::Cancelled, LedgerEvent::Receipt(fresh)]; + assert_eq!( + DagRun::restore(&s.document, trusted(), NOW, &invalid).unwrap_err(), + Refusal::Cancelled + ); + + // The same fresh receipt is valid before, but not after, cancellation. + let ordered = [LedgerEvent::Receipt(fresh), LedgerEvent::Cancelled]; + let mut restored = DagRun::restore(&s.document, trusted(), NOW, &ordered).unwrap(); + assert_eq!(restored.state(0), NodeState::Done); + assert_eq!(restored.apply(&fresh), Ok(Applied::Replay)); + assert_eq!(restored.log(), ordered); + + // Existing duplicate receipt normalization remains idempotent. + let redundant = [ + LedgerEvent::Receipt(fresh), + LedgerEvent::Cancelled, + LedgerEvent::Receipt(fresh), + LedgerEvent::Cancelled, + ]; + let restored = DagRun::restore(&s.document, trusted(), NOW, &redundant).unwrap(); + assert_eq!(restored.log(), ordered); + let mut forged = fresh; + forged[RECEIPT_SIGNED_LEN] ^= 1; + assert_eq!( + DagRun::restore( + &s.document, + trusted(), + NOW, + &[LedgerEvent::Cancelled, LedgerEvent::Receipt(forged)] + ) + .unwrap_err(), + Refusal::ForgedReceipt + ); +} + +#[test] +fn admission_checks_each_node_expiry() { + let s = sample(); + let mut dag = decode(&s.document).unwrap(); + dag.nodes[0].expires_at = NOW - 1; + assert_eq!( + DagRun::admit(&encode(&dag).unwrap(), trusted(), NOW).unwrap_err(), + Refusal::BadExpiry + ); + dag.nodes[0].expires_at = NOW; + DagRun::admit(&encode(&dag).unwrap(), trusted(), NOW).unwrap(); } #[test] diff --git a/specs/aienet/jobpath/PROFILE.md b/specs/aienet/jobpath/PROFILE.md index 6759c83..ff51fbf 100644 --- a/specs/aienet/jobpath/PROFILE.md +++ b/specs/aienet/jobpath/PROFILE.md @@ -6,8 +6,8 @@ verifier, MacBook Air M2 worker) on 2026-10-28. Evidence: This profile is the job half of the Aienet-0 P0 interop profile (`specs/aienet/P0_INTEROP_PROFILE.md`, PR #63). It reuses MJB1/MJR1 and the -`aien-microjob` reader, validator and `DagRun` receipt ledger (PR #53) -unchanged, and the Open Humanity signed, encrypted transport +`aien-microjob` reader, validator and `DagRun` receipt ledger (PR #53), +with the audit corrections below, and the Open Humanity signed, encrypted transport (`aien-dev/open-humanity`, `oh-core::transport`). It adds no wallet, no currency, no compiler and no remote execution: the worker runs one allowlisted, integer-exact function and nothing else. @@ -73,11 +73,13 @@ In order, each a distinct refusal: 1. Well-formed bundle (`AN0_BAD_BUNDLE`). 2. Submitter key equals the pinned key and its signature verifies (`AN0_BAD_SUBMITTER`). -3. MJB1 decodes and validates (`MJB_*`), not expired (`MJB_BAD_EXPIRY`). +3. MJB1 decodes and validates (`MJB_*`); header and node are not expired + at the receiver's clock (`MJB_BAD_EXPIRY`). 4. Exactly one node of the allowlisted shape above (`AN0_NOT_ALLOWLISTED`). 5. The operand names this payload (`AN0_PAYLOAD_MISMATCH`). 6. The payload kind is `matmul_u32` (`AN0_NOT_ALLOWLISTED`). -7. Dimensions within bounds and node caps cover the job (`AN0_OVER_BUDGET`). +7. Dimensions within bounds, node work/fuel/memory caps cover the job, and + the header fuel budget covers the job (`AN0_OVER_BUDGET`). 8. `dag_digest` never admitted before (`AN0_REPLAY`). The worker appends it to `state/seen` and fsyncs before executing, so a crash cannot re-run it. @@ -132,8 +134,23 @@ sequence; evidence in `evidence/aienet0-20261028/settlement/`. | 172 | 64 | signature over `"AIENET0-MJR1-VERIFY-V1\0"` || bytes 0..172 | `check_countersign` (and `aienet0-run check`) re-verifies a stored triple -against pinned keys; a settlement ledger keys its `settle` on the dag_id and -the MJR1 SHA-256 printed in the VERIFIED line. +against pinned keys and rebuilds the verdict commitment from the MJR1 DAG, +job id and output digest. Both the AN0V commitment and MJR1 +`verifier_verdict` must equal it, otherwise `AN0_BAD_COUNTERSIGN`. +A settlement ledger keys its `settle` on the dag_id and the MJR1 SHA-256. + +## Runner checks + +`bash specs/aienet/jobpath/check-harness.sh` tests the runners with +deterministic fault injection, not the matmul kernel. `parity.sh RECOMPUTE` +must build the Rust oracle successfully and accept only one lowercase-hex +payload/digest pair and a lowercase-hex recompute digest. Missing tools, +failed processes and malformed output exit 2; behavioral mismatches exit 1. +`OMEGA_MV=... mutants.sh OMC` requires the pinned compiler and SHA unit, +establishes unmutated parity first, and counts an Omega mutant killed only +on parity exit 1, never an invalid setup. Missing Omega prerequisites print +`OM-MUTANTS NOT_RUN` and fail nonzero. Historical evidence below remains +unchanged; current checks do not retroactively validate it. ## Carrier (open-humanity `oh-core::carrier`) diff --git a/specs/aienet/jobpath/check-harness.sh b/specs/aienet/jobpath/check-harness.sh new file mode 100755 index 0000000..34f8446 --- /dev/null +++ b/specs/aienet/jobpath/check-harness.sh @@ -0,0 +1,74 @@ +#!/usr/bin/env bash +# Deterministic fault injection for the parity/mutant runners, not kernel parity. +set -euo pipefail +here=$(cd "$(dirname "$0")" && pwd) +scratch=$(mktemp -d) +trap 'rm -rf "$scratch"' EXIT +mkdir -p "$scratch/specs/aienet/jobpath" "$scratch/tools" "$scratch/target/debug/examples" +cp "$here/parity.sh" "$here/mutants.sh" "$scratch/specs/aienet/jobpath/" +cat > "$scratch/tools/cargo" <<'EOF' +#!/bin/sh +exit "${FIXTURE_CARGO_RC:-0}" +EOF +cat > "$scratch/target/debug/examples/an0_digest" <<'EOF' +#!/bin/bash +case ${FIXTURE_ORACLE:-valid} in + empty) exit 0 ;; + fail) exit 101 ;; + invalid) echo 'not hex'; exit 0 ;; +esac +printf '010001000100010000000000000000 %064d\n' 0 +case ${FIXTURE_ORACLE:-valid} in + extra) echo extra ;; +esac +EOF +cat > "$scratch/recompute" <<'EOF' +#!/bin/bash +hex=$(xxd -p -c 256) +case "$hex" in + 020001000100010000000000000001) exit 3 ;; + 010000000100010000000000000001|010101000100010000000000000001) exit 4 ;; + 0100010001000100000000000000) exit 2 ;; +esac +case ${FIXTURE_RECOMPUTE:-valid} in + empty) exit 0 ;; + fail) exit 1 ;; + invalid) echo bad; exit 0 ;; + mismatch) printf '%064d\n' 1; exit 0 ;; +esac +printf '%064d\n' 0 +EOF +chmod +x "$scratch/tools/cargo" "$scratch/recompute" "$scratch/target/debug/examples/an0_digest" +export CARGO_TARGET_DIR=$scratch/target +export PATH=$scratch/tools:$PATH +parity=$scratch/specs/aienet/jobpath/parity.sh +expect() { + local name=$1 want=$2 rc + shift 2 + if "$@" >"$scratch/$name.log" 2>&1; then rc=0; else rc=$?; fi + if [ "$rc" != "$want" ]; then + cat "$scratch/$name.log" + echo "FAIL $name expected=$want observed=$rc"; exit 1 + fi + echo "PASS $name exit=$rc" +} +expect fixture-baseline 0 bash "$parity" "$scratch/recompute" +expect cargo-failure 2 env FIXTURE_CARGO_RC=101 bash "$parity" "$scratch/recompute" +if grep -q '^MATCH' "$scratch/cargo-failure.log"; then echo 'FAIL cargo-failure matched stale output'; exit 1; fi +for mode in empty fail invalid extra; do + expect "oracle-$mode" 2 env FIXTURE_ORACLE=$mode bash "$parity" "$scratch/recompute" +done +for mode in empty fail invalid; do + expect "recompute-$mode" 2 env FIXTURE_RECOMPUTE=$mode bash "$parity" "$scratch/recompute" +done +expect digest-mismatch 1 env FIXTURE_RECOMPUTE=mismatch bash "$parity" "$scratch/recompute" +expect missing-recompute 2 bash "$parity" "$scratch/absent" +expect missing-omc 2 env -u OMEGA_OMC -u OMEGA_MV bash "$scratch/specs/aienet/jobpath/mutants.sh" +grep -q '^OM-MUTANTS NOT_RUN:' "$scratch/missing-omc.log" +# Hide a prerequisite without relying on what the host has installed. +mkdir "$scratch/limited" +ln -s "$(command -v dirname)" "$scratch/limited/dirname" +expect missing-cargo 2 env PATH="$scratch/limited" /bin/bash "$parity" "$scratch/recompute" +ln -s "$scratch/tools/cargo" "$scratch/limited/cargo" +expect missing-xxd 2 env PATH="$scratch/limited" /bin/bash "$parity" "$scratch/recompute" +echo 'HARNESS PASS' diff --git a/specs/aienet/jobpath/mutants.sh b/specs/aienet/jobpath/mutants.sh index 5a1f165..436d08b 100755 --- a/specs/aienet/jobpath/mutants.sh +++ b/specs/aienet/jobpath/mutants.sh @@ -4,11 +4,16 @@ # executor-pin, made to trust the receipt's own signer) in a scratch copy of # the crate, and the unit tests must then FAIL. A mutant that still passes # means the guard is not tested. Two Omega mutants of the recompute must make -# parity.sh fail. Usage: mutants.sh [OMC] ; exit 0 only when every mutant is -# killed. -set -u -o pipefail +# parity.sh fail. Usage: mutants.sh OMC (or set OMEGA_OMC and OMEGA_MV). +# Exit 0 only when the baseline passes and every Rust and Omega mutant is killed. +set -e -u -o pipefail here=$(cd "$(dirname "$0")" && pwd) root=$(cd "$here/../../.." && pwd) +omc=${1:-${OMEGA_OMC:-}} +if [ -z "$omc" ] || [ ! -x "$omc" ] || [ -z "${OMEGA_MV:-}" ]; then + echo "OM-MUTANTS NOT_RUN: set executable OMEGA_OMC (or OMC argument) and OMEGA_MV" + exit 2 +fi scratch=$(mktemp -d /tmp/an0-mutants.XXXXXX) trap 'rm -rf "$scratch"' EXIT export CARGO_TARGET_DIR=${CARGO_TARGET_DIR:-$root/target/mutants} @@ -17,6 +22,14 @@ cp -a "$root/Cargo.toml" "$root/Cargo.lock" "$root/crates" "$scratch/" pristine=$(cat "$root/$src") killed=0; survived=0 +# Establish the exact parity path before counting any failed mutant as killed. +if ! OMEGA_OMC=$omc "$here/build.sh" "$scratch/recompute"; then + echo "OM-MUTANTS NOT_RUN: baseline build failed"; exit 2 +fi +if ! "$here/parity.sh" "$scratch/recompute"; then + echo "OM-MUTANTS INVALID: baseline parity failed"; exit 2 +fi + run_tests() { (cd "$scratch" && cargo test -q -p aien-microjob --lib aienet0 >/dev/null 2>&1) } @@ -47,9 +60,7 @@ done # Omega recompute mutants: a changed splitmix constant and a dropped # accumulate. Built with the same pinned build.sh; parity.sh must fail. -omc=${1:-${OMEGA_OMC:-}} -if [ -n "$omc" ]; then - om=$here/matmul_u32_recompute.om +om=$here/matmul_u32_recompute.om for spec in 'splitmix-constant|s/0xbf58476d1ce4e5b9/0xbf58476d1ce4e5b8/' 'drop-accumulate|s/^acc = add acc mul x get b q$/acc = mul x get b q/'; do name=${spec%%|*}; expr=${spec#*|} mkdir -p "$scratch/om-$name" @@ -59,8 +70,16 @@ if [ -n "$omc" ]; then if ! OMEGA_OMC=$omc OMEGA_MV=${OMEGA_MV:?set OMEGA_MV} "$scratch/om-$name/build.sh" "$scratch/om-$name/bin" >/dev/null 2>&1; then echo "OM-MUTANT $name BUILD-FAILED (not counted)"; exit 2 fi - if "$here/parity.sh" "$scratch/om-$name/bin" >/dev/null 2>&1; then echo "OM-MUTANT $name SURVIVED"; survived=$((survived + 1)); else echo "OM-MUTANT $name KILLED"; killed=$((killed + 1)); fi + if "$here/parity.sh" "$scratch/om-$name/bin" >"$scratch/om-$name/parity.log" 2>&1; then + echo "OM-MUTANT $name SURVIVED"; survived=$((survived + 1)) + else + rc=$? + if [ "$rc" != 1 ]; then + cat "$scratch/om-$name/parity.log" + echo "OM-MUTANT $name INVALID parity rc=$rc (not counted)"; exit 2 + fi + echo "OM-MUTANT $name KILLED"; killed=$((killed + 1)) + fi done -fi echo "killed=$killed survived=$survived" [ "$survived" = 0 ] diff --git a/specs/aienet/jobpath/parity.sh b/specs/aienet/jobpath/parity.sh index 5ee2d3a..bc05d9f 100755 --- a/specs/aienet/jobpath/parity.sh +++ b/specs/aienet/jobpath/parity.sh @@ -2,17 +2,27 @@ # Parity: the Omega recompute (Spark verifier) against the Rust worker kernel # (aien-microjob aienet0::matmul_u32_digest, i-k-j order) on fixed shapes, # then the .om refusal exits. Usage: parity.sh RECOMPUTE_BIN -# Exit 0 only when every digest matches and every refusal exit is exact. -set -u -o pipefail +# Exit 0 only for parity, 1 for a behavioral mismatch, 2 for invalid setup/output. +set -e -u -o pipefail bin=${1:?usage: parity.sh RECOMPUTE_BIN} root=$(cd "$(dirname "$0")/../../.." && pwd) cd "$root" -cargo build -q -p aien-microjob --example an0_digest -ex=$root/target/debug/examples/an0_digest +invalid() { echo "PARITY INVALID: $*" >&2; exit 2; } +for tool in cargo xxd; do + command -v "$tool" >/dev/null || invalid "missing $tool" +done +[ -x "$bin" ] || invalid "recompute is not executable" +target=${CARGO_TARGET_DIR:-$root/target} +cargo build -q -p aien-microjob --example an0_digest --target-dir "$target" || invalid 'Rust oracle build failed' +ex=$target/debug/examples/an0_digest +[ -x "$ex" ] || invalid 'Rust oracle is not executable' fail=0 while read -r m k n seed; do - read -r payload want < <("$ex" "$m" "$k" "$n" "$seed") - got=$(printf '%s' "$payload" | xxd -r -p | "$bin") + oracle=$("$ex" "$m" "$k" "$n" "$seed") || invalid 'Rust oracle failed' + [[ $oracle =~ ^[0-9a-f]{30}\ [0-9a-f]{64}$ ]] || invalid 'malformed Rust oracle output' + read -r payload want <<< "$oracle" + got=$(printf '%s' "$payload" | xxd -r -p | "$bin") || invalid 'recompute failed' + [[ $got =~ ^[0-9a-f]{64}$ ]] || invalid 'malformed recompute output' if [ "$got" = "$want" ]; then echo "MATCH $m $k $n $seed $got" else @@ -31,11 +41,11 @@ EOF # Refusals: payload kind 2 -> 3, a zero dimension -> 4, m=257 -> 4, short -> 2. check() { local hex=$1 want=$2 rc - printf '%s' "$hex" | xxd -r -p | "$bin" >/dev/null 2>&1; rc=$? + if printf '%s' "$hex" | xxd -r -p | "$bin" >/dev/null 2>&1; then rc=0; else rc=$?; fi if [ "$rc" = "$want" ]; then echo "REFUSE_OK exit=$rc payload=$hex"; else echo "REFUSE_BAD want=$want got=$rc payload=$hex"; fail=1; fi } check 020001000100010000000000000001 3 check 010000000100010000000000000001 4 check 010101000100010000000000000001 4 check 0100010001000100000000000000 2 -exit $fail +exit "$fail" diff --git a/specs/microjob/SPEC.md b/specs/microjob/SPEC.md index 7807d9f..b151094 100644 --- a/specs/microjob/SPEC.md +++ b/specs/microjob/SPEC.md @@ -224,6 +224,20 @@ From the document and the ledger a receiver derives, per node: DONE (COMPLETED r Cancellation is atomic with respect to receipts: a receipt applied before the cancel stands, a receipt arriving after it is refused with `MJB_CANCELLED`, and every non-terminal node becomes CANCELLED. +Receiver-local persistence MUST retain the ordered history of newly applied +receipts and objective cancellation, not only receipt bytes. On restore, +replay that history in order using the same checks: an earlier byte-identical +receipt remains a replay after cancellation, but a new receipt following +cancellation MUST fail with `MJB_CANCELLED`. Repeated cancellations and +receipt replays add no new events. The Rust reference exposes +`LedgerEvent::Receipt([u8; RECEIPT_LEN])` and `LedgerEvent::Cancelled`; +these are local values, not a stable byte encoding, signed wire receipt or +remote cancellation authority. A receiver MUST bind its durable history to +the accepted document and commit cancellation before acknowledging it. +Receipt-only historical logs do not prove absence of cancellation; migration +requires independently trusted receiver state, never a missing-state default. +This does not provide rollback protection or undo an external effect. + Dependency-version invalidation: a node whose inputs change takes a higher `generation`, and every node that depends on it must name the new generation (rule 26), which changes the document and so its `dag_digest`. Receipts of the old document are refused (`MJB_WRONG_DAG`). A pure node whose bytes and whose ancestors' bytes are unchanged may be recomputed deterministically and must give the same `output_digest`. ## 6. Refusal codes @@ -232,7 +246,7 @@ Dependency-version invalidation: a node whose inputs change takes a higher `gene ## 7. Expiry -Expiry is checked by the receiver against its own clock at admission (`MJB_BAD_EXPIRY` when `expires_at` is in the past). The C checker has no clock and checks only the static rules of section 4.4. +Expiry is checked for the header and every node by the receiver against its own clock at admission (`MJB_BAD_EXPIRY` when any `expires_at` is in the past; equality is admissible). The C checker has no clock and checks only the static rules of section 4.4. ## 8. Relation to the Turing Compute Network