interplane.Get Omega
Read in your language

aien-protocols-mv

Canonical specifications, wire protocols, and schemas for the AIEN sovereign ecosystem

Brought by drakestapleton

branch main Branches Tags History

aien-protocols-mv / specs / aienet / jobpath / parity.sh

51 lines · 2080 bytes Raw Blame History
1#!/usr/bin/env bash
2# Parity: the Omega recompute (Spark verifier) against the Rust worker kernel
3# (aien-microjob aienet0::matmul_u32_digest, i-k-j order) on fixed shapes,
4# then the .om refusal exits. Usage: parity.sh RECOMPUTE_BIN
5# Exit 0 only for parity, 1 for a behavioral mismatch, 2 for invalid setup/output.
6set -e -u -o pipefail
7bin=${1:?usage: parity.sh RECOMPUTE_BIN}
8root=$(cd "$(dirname "$0")/../../.." && pwd)
9cd "$root"
10invalid() { echo "PARITY INVALID: $*" >&2; exit 2; }
11for tool in cargo xxd; do
12 command -v "$tool" >/dev/null || invalid "missing $tool"
13done
14[ -x "$bin" ] || invalid "recompute is not executable"
15target=${CARGO_TARGET_DIR:-$root/target}
16cargo build -q -p aien-microjob --example an0_digest --target-dir "$target" || invalid 'Rust oracle build failed'
17ex=$target/debug/examples/an0_digest
18[ -x "$ex" ] || invalid 'Rust oracle is not executable'
19fail=0
20while read -r m k n seed; do
21 oracle=$("$ex" "$m" "$k" "$n" "$seed") || invalid 'Rust oracle failed'
22 [[ $oracle =~ ^[0-9a-f]{30}\ [0-9a-f]{64}$ ]] || invalid 'malformed Rust oracle output'
23 read -r payload want <<< "$oracle"
24 got=$(printf '%s' "$payload" | xxd -r -p | "$bin") || invalid 'recompute failed'
25 [[ $got =~ ^[0-9a-f]{64}$ ]] || invalid 'malformed recompute output'
26 if [ "$got" = "$want" ]; then
27 echo "MATCH $m $k $n $seed $got"
28 else
29 echo "MISMATCH $m $k $n $seed rust=$want om=$got"; fail=1
30 fi
31done <<'EOF'
321 1 1 0
337 5 3 2716205057
343 8 1 18446744073709551615
3516 9 31 42
3664 64 64 1311768467463790320
371 256 1 7
38256 1 256 7
39256 256 256 2716205057
40EOF
41# Refusals: payload kind 2 -> 3, a zero dimension -> 4, m=257 -> 4, short -> 2.
42check() {
43 local hex=$1 want=$2 rc
44 if printf '%s' "$hex" | xxd -r -p | "$bin" >/dev/null 2>&1; then rc=0; else rc=$?; fi
45 if [ "$rc" = "$want" ]; then echo "REFUSE_OK exit=$rc payload=$hex"; else echo "REFUSE_BAD want=$want got=$rc payload=$hex"; fail=1; fi
46}
47check 020001000100010000000000000001 3
48check 010000000100010000000000000001 4
49check 010101000100010000000000000001 4
50check 0100010001000100000000000000 2
51exit "$fail"