diff --git a/CHANGELOG.md b/CHANGELOG.md index def6fbf..bd9c8af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,14 @@ VERSIONING.md. rule, and a shared conformance corpus (122 family vectors, 5 edge positives, 44 refusals) with a shell generator. Extracted from the running Rust reference; no new format features. +- `specs/execution-transcript`: TRN1 contract 0.2.0. Adds wire schema 3 + with record types 17 CAUSE, 18 RECEIPT_BIND, 19 RUN_LINK and 21 RESOURCE + (32-byte cause id); type 20 TRAIN_DISPATCH reserved without a layout. + Schema 1 files and every 0.1.0 vector keep their outcomes; schema 2 stays + unassigned. Reference verifier accepts schemas 1 and 3; 0.2 goldens, + forged histories, 23 refusal vectors and a join expectation list + (`vectors/join.txt`). Sources: aien-architecture causal-id-join-v0 + (fa46a26) and resource-contract-v0 (ddc17b7). ## [v0.1.0] - 2026-09-23 diff --git a/specs/execution-transcript/TRN1_TRANSCRIPT_SPEC.md b/specs/execution-transcript/TRN1_TRANSCRIPT_SPEC.md index ee92bfa..8b8d4b9 100644 --- a/specs/execution-transcript/TRN1_TRANSCRIPT_SPEC.md +++ b/specs/execution-transcript/TRN1_TRANSCRIPT_SPEC.md @@ -1,8 +1,9 @@ # Execution Transcript: TRN1 -**Status**: Draft v0 (hardening lane LB, 2026-10-01). Not yet produced by any runtime. -**Contract version**: 0.1.0 (major zero: may change by minor bump, see VERSIONING.md) -**Wire schema version**: 1 (the `schema` field below) +**Status**: Draft v0 (hardening lane LB, 2026-10-01); 0.2.0 adds the causal and resource records (hardening cut S1, lane HD-08, 2026-10-01). Not yet produced by any runtime. +**Contract version**: 0.2.0 (major zero: may change by minor bump, see VERSIONING.md) +**Wire schema versions**: 1 (contract 0.1 record registry) and 3 (contract 0.2 record registry), in the `schema` field below; rule in section 10 +**0.2.0 sources**: aien-architecture `docs/hardening/causal-id-join-v0.md` (merged `fa46a26`: sections 2.1, 3.1 to 3.3, 3.5, 4) and `docs/hardening/resource-contract-v0.md` (merged `ddc17b7`: section 4) **License**: Community Specification License 1.0 **Reference verifier**: [`tools/trn1_verify.c`](tools/trn1_verify.c), C99, self-contained (own SHA-256, libc only) **Planned implementations**: omega `tools/replay` (C verifier and replayer, lane LD); sovereign-core `crates/aien-replay` (Rust reader, lane LE) @@ -53,7 +54,7 @@ complement). Offsets are from the start of the buffer. | Offset | Size | Field | Valid values | |---|---|---|---| | 0 | 4 | magic | ASCII `TRN1` (`54 52 4E 31`) | -| 4 | 2 | schema | `1` | +| 4 | 2 | schema | `1` or `3` (section 10); every other value is refused | | 6 | 2 | flags | `0` (no flags defined) | | 8 | 32 | run_id | opaque; the root causal id of this run (plan item P5). Any value. | | 40 | 2 | producer | subsystem id (section 5.2) of the writer; not 0 | @@ -126,8 +127,16 @@ Fields named `reserved` must be zero (NONCANONICAL otherwise). | 14 | CHECKPOINT | 40 | scope u32, reserved u32, subsystem state digest | | 15 | RX_CRUMB | 32 + n | crumb digest, then the canonical crumb bytes (section 5.3) | | 16 | ARGUS_EVENT | 200 | event[128], chained u8 (0 or 1, SHAPE otherwise), reserved[7], chain_before digest, chain_after digest (section 5.4) | +| 17 | CAUSE | 80 | schema 3 only: cause[32], mode u32, local_kind u32, local u64, root digest (section 5.5) | +| 18 | RECEIPT_BIND | 40 | schema 3 only: cause[32], format u32, reserved u32 (section 5.5) | +| 19 | RUN_LINK | 48 | schema 3 only: relation u32, reserved u32, parent branch u64, parent create digest (section 5.5) | +| 20 | TRAIN_DISPATCH | none | number reserved; no layout in 0.2.0, so refused as UNKNOWN under every schema (section 5.5) | +| 21 | RESOURCE | 96 | schema 3 only: op u8, reason u8, field u16, reserved u32, unit u64, cause[32], contract digest, declared u64, used u64 (section 5.5) | | 0xFFFF | END | 16 | record_count u64 (must equal this record's seq, GAP otherwise), reserved u64 | +Under schema 1 the registry is types 1 to 16 and END; types 17 to 21 are +unknown there and refused with UNKNOWN (vectors `m030`, `m070`). + ### 5.2 Subsystems | Id | Name | Id | Name | @@ -201,6 +210,95 @@ aienos main `33927b1`. The ARGUS `tick` field is the authority's logical clock, not a wall clock, and stays in the identity. +### 5.5 Causal and resource records (contract 0.2.0, schema 3 only) + +Source of truth: aien-architecture `docs/hardening/causal-id-join-v0.md` +(merged `fa46a26`) sections 2.1, 3.1 to 3.3 and 3.5 (the joint number +table), and `docs/hardening/resource-contract-v0.md` (merged `ddc17b7`) +section 4, with the 32-byte cause required by causal-id-join section 3.5. +All integers little-endian; "digest" is 32 bytes. These types exist only in +a file whose header schema is 3; under schema 1 they are UNKNOWN. + +**Cause id.** A 32-byte value, +`SHA-256("AIEN_CAUSE_V0" (13 ASCII bytes) || subsystem u16 || local_kind u32 || local u64 || root digest)`, +where `subsystem` is the CAUSE record's own subsystem field, not the file +header producer (aien-architecture#102 Q5), +minted once where an outside input enters AIEN and copied, never re-minted, +downstream (causal-id-join section 2.1 and 2.3). A TRN1 verifier carries it; +it does not recompute it (see "Verifier rules versus join rules" below). + +**Type 17 CAUSE (80 bytes).** + +| Offset | Size | Field | Rule | +|---|---|---|---| +| 0 | 32 | cause | the cause id | +| 32 | 4 | mode | 1 MINT, 2 ADOPT, 3 REF; else SHAPE | +| 36 | 4 | local_kind | 1 omega episode, 2 aienos admission, 3 sovcore request, 4 train run (causal-id-join table 2.2 and section 3.4). MINT and ADOPT: 1 to 4, else SHAPE. REF: 0 exactly, else SHAPE (aien-architecture#102 Q3) | +| 40 | 8 | local | MINT and ADOPT: not 0, else SHAPE. REF: 0 exactly, else SHAPE (aien-architecture#102 Q3) | +| 48 | 32 | root digest | MINT: the digest the cause was minted over. ADOPT and REF: all zero, else NONCANONICAL | + +Annotation (never compared, not checked by the verifier): an ADOPT carries +origin run id (32) then origin seq (u64). + +**Type 18 RECEIPT_BIND (40 bytes).** + +| Offset | Size | Field | Rule | +|---|---|---|---| +| 0 | 32 | cause | a cause opened earlier in this run (a join rule, below) | +| 32 | 4 | format | 1 aienos `cka_receipt`, 2 omega evidence receipt, 3 sovereign-core `aien-proof`; else SHAPE | +| 36 | 4 | reserved | zero, else NONCANONICAL | + +Annotation: the receipt digest (32). It is chained but never compared, +because receipt bytes may differ between correct runs (vector `g008` +MATCHes `g006` with a different receipt digest). + +**Type 19 RUN_LINK (48 bytes).** Allowed only as record 1 (SHAPE otherwise). + +| Offset | Size | Field | Rule | +|---|---|---|---| +| 0 | 4 | relation | 1 CHILD_OF; else SHAPE | +| 4 | 4 | reserved | zero, else NONCANONICAL | +| 8 | 8 | parent branch | the `branch` of the parent's `BRANCH_CREATE` | +| 16 | 32 | parent create digest | the compared digest (section 4.2) of that `BRANCH_CREATE` record | + +Annotation: parent run id (32) then parent seq (u64). + +**Type 20 TRAIN_DISPATCH.** The number is reserved by the joint table +(causal-id-join section 3.5). Its identity layout is not fixed in 0.2.0, so +every reader refuses type 20 as UNKNOWN (vector `m071`). A later minor +version defines it. + +**Type 21 RESOURCE (96 bytes).** + +| Offset | Size | Field | Rule | +|---|---|---|---| +| 0 | 1 | op | 1 CHARGE, 2 REFUND, 3 REFUSE, 4 CANCEL, 5 OVERRUN, 6 OVER_OBSERVED; else SHAPE | +| 1 | 1 | reason | REFUSE: 1 BUSY, 2 OVER_BUDGET, 3 UNKNOWN, 4 QUOTA. CANCEL: 1 DEADLINE, 2 PARENT, 3 EXPLICIT. Every other op: 0. Else SHAPE | +| 2 | 2 | field | contract field number 1 to 10 (resource-contract section 1.2), or 0 for a whole-need charge or refund; above 10 SHAPE | +| 4 | 4 | reserved | zero, else NONCANONICAL | +| 8 | 8 | unit | the reaction or task id the outcome applies to | +| 16 | 32 | cause | the cause id this outcome serves | +| 48 | 32 | contract | digest of the contract record in force | +| 80 | 8 | declared | the declared limit for `field` (0 when absent) | +| 88 | 8 | used | the deterministic amount used, 0 for a measured field | + +Measured amounts (CPU, wall, GPU, energy) go in the annotation, never the +identity (resource-contract section 4). The 8-byte cause of the first +arch#96 draft is refused by length (vector `m073`). + +**Verifier rules versus join rules.** A TRN1 verifier checks the rules in +the tables above, one file at a time, with the refusal codes of section 6. +It does **not** check: that a minted cause recomputes, that a cause is +minted once, CAUSE placement and adjacency, that a RESOURCE or RECEIPT_BIND +names a cause opened earlier in the run, that an effect or branch is +preceded by a CAUSE REF, ADOPT origins, RUN_LINK parents, or receipt +contents. Those are steps 3 to 10 of the causal join (causal-id-join section +4), which has its own outcome line and codes (`CAUSE_DIGEST`, `REF_UNKNOWN` +and the rest), and some of which need more than one file (a child run's +causes are opened by its parent). A transcript that breaks only a join rule +**verifies**; the corpus lists the join refusals it expects in +`vectors/join.txt` (section 9). + ## 6. Refusal codes Zero means accept. A refusal is a negative integer from this table, and only @@ -209,7 +307,7 @@ from this table. | Code | Name | Meaning | |---|---|---| | -1 | MAGIC | first four bytes are not `TRN1` | -| -2 | VERSION | schema is not 1 (unknown version, older or newer) | +| -2 | VERSION | schema is not 1 or 3 (unknown version, older or newer; section 10) | | -3 | LENGTH | buffer ends inside the header or a record; a length above its limit; bytes after END | | -4 | NONCANONICAL | a flag or reserved field is not zero | | -5 | UNKNOWN | unknown record type, unknown subsystem, or producer 0 or unknown | @@ -227,7 +325,7 @@ order. "event" is the position k of the record being checked (0 = header). Header: 1. Fewer than 4 bytes: LENGTH. Magic not `TRN1`: MAGIC. -2. Fewer than 6 bytes: LENGTH. schema not 1: VERSION. +2. Fewer than 6 bytes: LENGTH. schema not 1 and not 3: VERSION. 3. Fewer than 48 bytes: LENGTH. flags not 0: NONCANONICAL. 4. producer 0 or unknown: UNKNOWN. 5. reserved not zero: NONCANONICAL. @@ -235,7 +333,8 @@ Header: Then for record k = 1, 2, ...: 1. Buffer ends exactly here: TRUNCATED. Fewer than 56 bytes left, or k above 4096: LENGTH. -2. type unknown: UNKNOWN. subsystem unknown: UNKNOWN. +2. type unknown for the file's schema (types 17 to 21 under schema 1, type 20 + under every schema): UNKNOWN. subsystem unknown: UNKNOWN. 3. reserved not zero: NONCANONICAL. 4. ident_len or annot_len above 65536: LENGTH. 5. seq not k: GAP. @@ -243,9 +342,14 @@ Then for record k = 1, 2, ...: 7. identity plus annotation not fully present: LENGTH. 8. Shape, in this order: ident_len rule for the type; END-and-only-END has subsystem 0; CAP_TRANSITION op; CRASH_BOUNDARY last_durable_seq < k; - RX_CRUMB canonical bytes; ARGUS_EVENT chained flag; END annot_len 0. - Any failure: SHAPE. -9. Reserved fields inside the identity: NONCANONICAL. + RX_CRUMB canonical bytes; ARGUS_EVENT chained flag; END annot_len 0; + then (schema 3) CAUSE mode, CAUSE local_kind (MINT and ADOPT), + REF local_kind zero, CAUSE local (MINT and ADOPT), REF local zero, RECEIPT_BIND + format, RUN_LINK relation, RUN_LINK is record 1, RESOURCE op, RESOURCE + reason, RESOURCE field. Any failure: SHAPE. +9. Reserved fields inside the identity, then (schema 3) CAUSE root digest + zero for ADOPT and REF, RECEIPT_BIND reserved, RUN_LINK reserved, + RESOURCE reserved: NONCANONICAL. 10. Embedded digests: RX_CRUMB digest, EXTERNAL_INPUT content, ARGUS continuity then ARGUS link. Any failure: DIGEST. 11. If END: record_count not k: GAP. Bytes remain after END: LENGTH with @@ -292,7 +396,11 @@ digest against an independently stored copy. Consumers must not treat ## 9. Conformance corpus `vectors/expected.txt` lists every transcript as ` `; -`vectors/compare.txt` lists pairs as ` `. +`vectors/compare.txt` lists pairs as ` `; +`vectors/join.txt` lists ` JOIN_REFUSED reason= run=<64 hex> event=` +for transcripts that verify but that the causal join (section 5.5) must +refuse, the join set being that one file. The reference verifier does not +read `join.txt`; it is input for a joiner, and NOT_RUN until one checks it. Lines starting with `#` are comments. Plain text, so C, shell, Rust and Omega harnesses can read them without a JSON parser. @@ -303,6 +411,11 @@ Omega harnesses can read them without a JSON parser. | Forged replays | `f001` .. `f006` | valid chains with a different history: omission, reorder, changed seed, changed capability generation inside a crumb, extra record, early stop. Each verifies alone and DIVERGEs from g001 at the named record | | Byte damage | `m001` .. `m018` | g001 damaged after writing: omission, reorder, bit flips (identity, annotation, prev, seq, run id, magic, crumb bytes, END), truncation (header, mid record, inside END, at a record boundary), empty file, trailing byte, duplicate | | Built refusals | `m020` .. `m065` | rechained so only the named check can fire: unknown versions (2 and 0), flags, producer, reserved fields, unknown type and subsystem, check order cases, oversize identity, every SHAPE rule, every DIGEST rule including an omitted ARGUS event the writer rechained | +| 0.2 golden | `g006` .. `g008` | schema 3. g006 one sovcore request start to receipt: CAUSE MINT, RESOURCE charge, CAUSE REF before a branch and before an effect, refund, RECEIPT_BIND; g007 a child run (RUN_LINK as record 1 naming g006's BRANCH_CREATE, CAUSE ADOPT, RESOURCE cancel); g008 a replay of g006 with another run id and receipt digest, which MATCHes g006 | +| 0.2 edge positive | `p003` | top of each range: local_kind 4, REFUSE reason 4, CANCEL reason 3, OVERRUN, OVER_OBSERVED on field 10, receipt format 1 | +| 0.2 forged | `f007` .. `f009` | rechained: cause bit flip in a RESOURCE, RESOURCE before its MINT (reorder), MINT omitted before the RESOURCE. Each verifies and DIVERGEs from g006 | +| Join only | `j001` .. `j005` | verify under TRN1; `join.txt` names the join refusal: CAUSE_DIGEST, DOUBLE_MINT, REF_MISSING, COMMIT_ORPHAN, RECEIPT_CAUSE (f007 and f009 are listed there too, REF_UNKNOWN; f008 is CAUSE_PLACEMENT at its late MINT, aien-architecture#102 Q7) | +| 0.2 refusals | `m070` .. `m094` | a valid 0.2 record under a schema 1 header (UNKNOWN); type 20 (UNKNOWN); wrong lengths (CAUSE 79 bytes, RESOURCE with the old 8-byte cause); every 0.2 SHAPE and NONCANONICAL rule; a check-order case; byte damage on g006 (cause bit flip, reorder); a CAUSE REF with nonzero local_kind (m093) and nonzero local (m094) | Regenerate with `tools/make-corpus.sh vectors`. The generator is shell plus coreutils (`sha256sum`, `od`, `sed`) and builds every byte from the tables @@ -321,18 +434,29 @@ TRN1_CONFORMANCE impl= pass=N fail=0 ## 10. Versioning -- Wire schema 1 is the only accepted schema. A verifier refuses every other - schema value with VERSION; it never reinterprets an older or newer file. +- The header `schema` names the record registry in force. Schema 1: contract + 0.1 registry (types 1 to 16 and END). Schema 3: contract 0.2 registry + (schema 1 plus types 17, 18, 19, 21). Schema 2 is never assigned: vector + `m020` has pinned it as an unknown schema since 0.1.0, and existing + vectors keep their outcomes. +- Version negotiation is by the header only. A reader accepts exactly the + schemas it implements and refuses every other value with VERSION at event + 0; it never reinterprets an older or newer file. So a 0.1 reader refuses a + schema 3 file cleanly (VERSION, event 0), and a 0.2 reader refuses a + 0.2 record inside a schema 1 file (UNKNOWN at that record, vector `m070`). + A 0.2 reader accepts both schema 1 and schema 3 files. +- A writer writes schema 1 when it emits only 0.1 record types, so 0.1 + readers keep reading it, and schema 3 when it emits any 0.2 type. - While the contract is 0.Y.Z, a new record type, subsystem or field is a minor version with new vectors; existing vectors keep their outcomes or the change is recorded as breaking in CHANGELOG.md. - Adding vectors the reference already decides is a patch version. Changing a refusal code or the check order is a breaking change. -- No feature negotiation: one schema, checked exactly. A writer that needs a +- No feature negotiation beyond the schema value: each schema is checked exactly. A writer that needs a record this spec lacks proposes it here first; it does not invent a type number. -## 11. Limits of v0 (stated, not hidden) +## 11. Limits (stated, not hidden) - No runtime writes TRN1 yet. RX_CRUMB and ARGUS_EVENT layouts were checked against the live omega and aienos sources named above, and a host-only @@ -343,6 +467,8 @@ TRN1_CONFORMANCE impl= pass=N fail=0 exists (sovereign-core is scaffolding, omega has none). - Cross-record checks beyond ARGUS continuity are left to replayers: a crumb's parent digest is not checked against an earlier RX_CRUMB record in - the same file, and effect commits are not matched to intents. + the same file, and effect commits are not matched to intents. In 0.2.0 + the causal checks are join rules (section 5.5), not verifier rules. +- TRAIN_DISPATCH (type 20) has a number and no layout. - No signature over the final digest. Anchoring the final digest in a signed receipt belongs to the receipt format, not to TRN1. diff --git a/specs/execution-transcript/tools/README.md b/specs/execution-transcript/tools/README.md new file mode 100644 index 0000000..1283ce4 --- /dev/null +++ b/specs/execution-transcript/tools/README.md @@ -0,0 +1,23 @@ +# TRN1 tools + +All scripts here are host-only (no hardware, no QEMU) and use shell plus +coreutils and a C99 compiler. No Python. + +**Run them with bash.** `make-corpus.sh`, `check-corpus.sh` and +`mutate-verifier.sh` are bash scripts (`#!/bin/bash`; `make-corpus.sh` uses bash arrays and C-style `for` loops, +`check-corpus.sh` uses `${PIPESTATUS[0]}`). On systems where `/bin/sh` is +dash, `sh check-corpus.sh` fails with a syntax error that says nothing about +the corpus. `test-check-corpus.sh` is POSIX sh and calls `bash` itself, so +either `sh` or `bash` works for it. + +| Script | Run as | What it does | +|---|---|---| +| `make-corpus.sh OUT_DIR` | `bash tools/make-corpus.sh vectors` | regenerates every vector and manifest (`expected.txt`, `compare.txt`, `join.txt`, `.gitattributes`) from the spec tables | +| `check-corpus.sh [CC]` | `bash tools/check-corpus.sh` | regenerates into a temp dir, requires it byte-identical to `vectors/`, builds `trn1_verify.c` (warnings as errors, plus ASan/UBSan when available) and checks every `expected.txt` and `compare.txt` line | +| `test-check-corpus.sh [CC]` | `sh tools/test-check-corpus.sh` | proves `check-corpus.sh` ignores only the crumb tool's `.crumb` and `.crumb.local` files | +| `mutate-verifier.sh [CC]` | `bash tools/mutate-verifier.sh` | builds one verifier per check with that check disabled; any mutant the corpus does not catch is a SURVIVOR and fails the run | +| `trn1_verify.c` | `cc -std=c99 -o trn1_verify tools/trn1_verify.c` | reference verifier: `FILE`, `--compare EXP ACT`, `--corpus DIR` | + +`vectors/join.txt` is not read by any tool here. It lists the causal-join +refusals a joiner must produce (spec section 5.5) and stays NOT_RUN until +one exists. diff --git a/specs/execution-transcript/tools/make-corpus.sh b/specs/execution-transcript/tools/make-corpus.sh index a64f616..a0175e2 100755 --- a/specs/execution-transcript/tools/make-corpus.sh +++ b/specs/execution-transcript/tools/make-corpus.sh @@ -1,6 +1,7 @@ #!/bin/bash -# make-corpus.sh: regenerate the TRN1 (execution transcript, wire schema 1) -# shared conformance corpus. Language-neutral spec: ../TRN1_TRANSCRIPT_SPEC.md. +# make-corpus.sh: regenerate the TRN1 (execution transcript) +# shared conformance corpus (contract 0.2.0: wire schemas 1 and 3). +# Language-neutral spec: ../TRN1_TRANSCRIPT_SPEC.md. # # Usage: make-corpus.sh OUT_DIR (normally specs/execution-transcript/vectors) # @@ -15,12 +16,14 @@ # fNNN.trn forged replays: valid chain, different history (accepted alone, # DIVERGENCE when compared with their golden) # mNNN.trn mutated transcripts (refused with a named code and event) +# jNNN.trn contract 0.2.0: accepted by TRN1, refused by the causal join +# (expected join refusals in OUT_DIR/join.txt, NOT_RUN here) # Shell only: no Python, no tools beyond coreutils. set -eu export LC_ALL=C OUT=${1:?OUT_DIR} mkdir -p "$OUT" -rm -f "$OUT"/*.trn "$OUT"/expected.txt "$OUT"/compare.txt "$OUT"/.gitattributes +rm -f "$OUT"/*.trn "$OUT"/expected.txt "$OUT"/compare.txt "$OUT"/join.txt "$OUT"/.gitattributes # Vectors are exact bytes (digests cover every byte), so git must never apply # line-ending or text conversion to them. This file is part of the corpus and # is checked by check-corpus.sh like any vector. @@ -411,4 +414,174 @@ end; save m065.trn; refuse m065.trn -9 2 pair g001.trn m001.trn "refuse actual -7 event=3" pair m008.trn g001.trn "refuse expected -1 event=0" + +# =========================================================================== +# Contract 0.2.0 (wire schema 3): causal and resource records, types 17, 18, +# 19 and 21 (section 5.5). Type 20 is reserved and still refused. Sources: +# aien-architecture docs/hardening/causal-id-join-v0.md (fa46a26) sections +# 2.1, 3.1 to 3.3, 3.5 and 4; docs/hardening/resource-contract-v0.md +# (ddc17b7) section 4. Everything below is appended, so every 0.1.0 vector +# and manifest line above keeps its bytes. +# =========================================================================== +V2=3 # wire schema of contract 0.2.x +{ + echo "# Contract 0.2.0 (wire schema 3) vectors: causal and resource records, types 17 to 21." +} >>"$OUT/expected.txt" +{ + echo "# Contract 0.2.0 (wire schema 3) pairs." +} >>"$OUT/compare.txt" +{ + echo "# TRN1 0.2.0 join expectations (causal-id-join-v0 section 4, aien-architecture fa46a26)." + echo "# Every file here VERIFIES under TRN1 (see expected.txt); the join must refuse it." + echo "# Line: JOIN_REFUSED reason= run=<64 hex> event=" + echo "# The join set is that one file alone. No join implementation lives in this" + echo "# repository: these lines are NOT_RUN until a joiner (omega cut O3/O4," + echo "# sovereign-core cut C1) checks them. The reference verifier does not read this file." + echo "# Generated by tools/make-corpus.sh; do not edit by hand." +} >"$OUT/join.txt" +jrefuse() { echo "$1 JOIN_REFUSED reason=$2 run=$3 event=$4" >>"$OUT/join.txt"; } + +# cause_id SUBSYSTEM LOCAL_KIND LOCAL ROOT_HEX (causal-id-join-v0 section 2.1) +cause_id() { sha "$(txt AIEN_CAUSE_V0)$(h16 "$1")$(h32 "$2")$(h64 "$3")$4"; } +# cause_rec CAUSE MODE LOCAL_KIND LOCAL ROOT_HEX (type 17, 80 bytes) +cause_rec() { printf '%s' "$1$(h32 "$2")$(h32 "$3")$(h64 "$4")$5"; } +# receipt_bind CAUSE FORMAT [RESERVED] (type 18, 40 bytes) +receipt_bind() { printf '%s' "$1$(h32 "$2")$(h32 "${3:-0}")"; } +# run_link RELATION PARENT_BRANCH PARENT_CREATE_CMP [RESERVED] (type 19, 48 bytes) +run_link() { printf '%s' "$(h32 "$1")$(h32 "${4:-0}")$(h64 "$2")$3"; } +# resource OP REASON FIELD UNIT CAUSE CONTRACT DECLARED USED [RESERVED] (type 21, 96 bytes) +resource() { printf '%s' "$(h8 "$1")$(h8 "$2")$(h16 "$3")$(h32 "${9:-0}")$(h64 "$4")$5$6$(h64 "$7")$(h64 "$8")"; } +MINT=1 ADOPT=2 CREF=3 + +ROOT6=$(dig "sovcore request 1 bytes") +CA=$(cause_id $SUB_RUNTIME 3 1 "$ROOT6") # minted by sovcore-runtime, local_kind 3, local 1 +CON6=$(dig "contract reaction 1") + +# g006: one sovcore request, start to receipt (producer sovcore-runtime). +# MINT, a charge, a referenced branch, a referenced effect, a refund, and a +# receipt bind whose receipt digest is in the annotation. +RUN6=$(dig "run g006") +g006() { # g006 RUN_ID RECEIPT_DIGEST + start $SUB_RUNTIME "$1" $V2 + rec 17 $SUB_RUNTIME "$(cause_rec "$CA" $MINT 3 1 "$ROOT6")" "" + rec 21 $SUB_RUNTIME "$(resource 1 0 0 1 "$CA" "$CON6" 0 0)" "" + rec 17 $SUB_RUNTIME "$(cause_rec "$CA" $CREF 0 0 "$Z32")" "" + rec 2 $SUB_KV "$(branch_create 2 0 1)" "" + rec 17 $SUB_RUNTIME "$(cause_rec "$CA" $CREF 0 0 "$Z32")" "" + rec 9 $SUB_RUNTIME "$(effect_intent 1 2 4 10 "$(dig "effect g006 request")")" "" + rec 10 $SUB_RUNTIME "$(effect_commit 1 0 "$(dig "effect g006 result")")" "" + rec 21 $SUB_RUNTIME "$(resource 2 0 0 1 "$CA" "$CON6" 0 0)" "" + rec 18 $SUB_RUNTIME "$(receipt_bind "$CA" 3)" "$2" +} +g006 "$RUN6" "$(dig "receipt g006")"; end; save g006.trn; ok g006.trn 10 "$RUN6" +G6=$T +G6CMP=(); for i in $(seq 1 10); do G6CMP[i]=$(cmpd "$i"); done +pair g006.trn g006.trn "MATCH through 10" + +# g008: replay of g006: other run id, other receipt digest (annotation). MATCHes. +RUN8=$(dig "run g008 replay of g006") +g006 "$RUN8" "$(dig "receipt g008")"; end; save g008.trn; ok g008.trn 10 "$RUN8" +pair g006.trn g008.trn "MATCH through 10" + +# g007: a child World transcript. RUN_LINK as record 1 names g006's +# BRANCH_CREATE (record 4, branch 2); the cause is ADOPTed (annotation: origin +# run id, origin seq), then a cancel because the parent was cancelled. +RUN7=$(dig "run g007 child of g006") +start $SUB_RUNTIME "$RUN7" $V2 +rec 19 $SUB_RUNTIME "$(run_link 1 2 "${G6CMP[4]}")" "$RUN6$(h64 4)" +rec 17 $SUB_RUNTIME "$(cause_rec "$CA" $ADOPT 3 1 "$Z32")" "$RUN6$(h64 1)" +rec 21 $SUB_RUNTIME "$(resource 4 2 1 2 "$CA" "$(dig "contract reaction 2")" 5 0)" "" +end; save g007.trn; ok g007.trn 4 "$RUN7" + +# p003: top of every valid range: local_kind 4 (train run), REFUSE reason 4, +# CANCEL reason 3, OVERRUN, OVER_OBSERVED on field 10 with a measured value in +# the annotation, receipt format 1. +CB=$(cause_id $SUB_SCHED 4 7 "$(dig "generation 0 digest")") +start $SUB_SCHED "$(dig "run p003")" $V2 +rec 17 $SUB_SCHED "$(cause_rec "$CB" $MINT 4 7 "$(dig "generation 0 digest")")" "" +rec 21 $SUB_SCHED "$(resource 3 4 7 3 "$CB" "$(dig "contract p003")" 8 0)" "" +rec 21 $SUB_SCHED "$(resource 4 3 1 3 "$CB" "$(dig "contract p003")" 9 0)" "" +rec 21 $SUB_SCHED "$(resource 5 0 9 3 "$CB" "$(dig "contract p003")" 16 17)" "" +rec 21 $SUB_SCHED "$(resource 6 0 10 3 "$CB" "$(dig "contract p003")" 100 0)" "$(h64 140)" +rec 18 $SUB_SCHED "$(receipt_bind "$CB" 1)" "$(dig "receipt p003")" +end; save p003.trn; ok p003.trn 7 "$(dig "run p003")" + +# Forged 0.2 histories: valid chains (accepted alone), caught by comparison +# with g006 and by the join (join.txt). +div6() { pair g006.trn "$1" "DIVERGENCE event=$2 expected=${G6CMP[$2]} actual=$(cmpd "$2") subsystem=$3"; } +CAX=$(flip "$CA" 0) +# f007 cause bit flip in the charge (record 2), rechained. +start $SUB_RUNTIME "$RUN6" $V2 +rec 17 $SUB_RUNTIME "$(cause_rec "$CA" $MINT 3 1 "$ROOT6")" "" +rec 21 $SUB_RUNTIME "$(resource 1 0 0 1 "$CAX" "$CON6" 0 0)" "" +end; save f007.trn; ok f007.trn 3 "$RUN6"; div6 f007.trn 2 sovcore-runtime +jrefuse f007.trn REF_UNKNOWN "$RUN6" 2 +# f008 reorder: the charge written before its MINT, rechained. +start $SUB_RUNTIME "$RUN6" $V2 +rec 21 $SUB_RUNTIME "$(resource 1 0 0 1 "$CA" "$CON6" 0 0)" "" +rec 17 $SUB_RUNTIME "$(cause_rec "$CA" $MINT 3 1 "$ROOT6")" "" +end; save f008.trn; ok f008.trn 3 "$RUN6"; div6 f008.trn 1 sovcore-runtime +# The MINT comes after a record that names its cause: CAUSE_PLACEMENT at the +# MINT (step 4 runs before step 7; aien-architecture#102 Q7). +jrefuse f008.trn CAUSE_PLACEMENT "$RUN6" 2 +# f009 omission: g006 without its CAUSE MINT, renumbered, rechained. +start $SUB_RUNTIME "$RUN6" $V2 +rec 21 $SUB_RUNTIME "$(resource 1 0 0 1 "$CA" "$CON6" 0 0)" "" +rec 17 $SUB_RUNTIME "$(cause_rec "$CA" $CREF 0 0 "$Z32")" "" +rec 2 $SUB_KV "$(branch_create 2 0 1)" "" +end; save f009.trn; ok f009.trn 4 "$RUN6"; div6 f009.trn 1 sovcore-runtime +jrefuse f009.trn REF_UNKNOWN "$RUN6" 1 + +# Join-only refusals (single file, TRN1 accepts each). +J() { start $SUB_RUNTIME "$(dig "run $1")" $V2; } +jr() { jrefuse "$1.trn" "$2" "$(dig "run $1")" "$3"; } +J j001; rec 17 $SUB_RUNTIME "$(cause_rec "$CAX" $MINT 3 1 "$ROOT6")" ""; rec 21 $SUB_RUNTIME "$(resource 1 0 0 1 "$CAX" "$CON6" 0 0)" "" +end; save j001.trn; ok j001.trn 3 "$(dig "run j001")"; jr j001 CAUSE_DIGEST 1 # minted cause does not recompute +J j002; rec 17 $SUB_RUNTIME "$(cause_rec "$CA" $MINT 3 1 "$ROOT6")" ""; rec 21 $SUB_RUNTIME "$(resource 1 0 0 1 "$CA" "$CON6" 0 0)" "" +rec 17 $SUB_RUNTIME "$(cause_rec "$CA" $MINT 3 1 "$ROOT6")" ""; rec 21 $SUB_RUNTIME "$(resource 2 0 0 1 "$CA" "$CON6" 0 0)" "" +end; save j002.trn; ok j002.trn 5 "$(dig "run j002")"; jr j002 DOUBLE_MINT 3 # same cause minted twice +J j003; rec 17 $SUB_RUNTIME "$(cause_rec "$CA" $MINT 3 1 "$ROOT6")" ""; rec 9 $SUB_RUNTIME "$(effect_intent 1 2 4 10 "$(dig "effect g006 request")")" "" +end; save j003.trn; ok j003.trn 3 "$(dig "run j003")"; jr j003 REF_MISSING 2 # effect intent with no CAUSE REF before it +J j004; rec 17 $SUB_RUNTIME "$(cause_rec "$CA" $MINT 3 1 "$ROOT6")" ""; rec 21 $SUB_RUNTIME "$(resource 1 0 0 1 "$CA" "$CON6" 0 0)" "" +rec 10 $SUB_RUNTIME "$(effect_commit 9 0 "$(dig "effect 9 result")")" "" +end; save j004.trn; ok j004.trn 4 "$(dig "run j004")"; jr j004 COMMIT_ORPHAN 3 # commit with no intent +J j005; rec 17 $SUB_RUNTIME "$(cause_rec "$CA" $MINT 3 1 "$ROOT6")" ""; rec 21 $SUB_RUNTIME "$(resource 1 0 0 1 "$CA" "$CON6" 0 0)" "" +rec 18 $SUB_RUNTIME "$(receipt_bind "$CAX" 3)" "$(dig "receipt j005")" +end; save j005.trn; ok j005.trn 4 "$(dig "run j005")"; jr j005 RECEIPT_CAUSE 3 # receipt bound to a cause not open + +# Built 0.2 refusals: rechained, so only the named check can catch them. +V() { H "${1:-$SUB_RUNTIME}" "$2" $V2; } +CM=$(cause_rec "$CA" $MINT 3 1 "$ROOT6") +RS=$(resource 1 0 0 1 "$CA" "$CON6" 0 0) +H $SUB_RUNTIME m070; rec 17 $SUB_RUNTIME "$CM" ""; end; save m070.trn; refuse m070.trn -5 1 # valid 0.2 CAUSE under a schema 1 header +V "" m071; rec 20 $SUB_RUNTIME "$(zeros 160)" ""; end; save m071.trn; refuse m071.trn -5 1 # type 20 reserved in 0.2.0 +V "" m072; rec 17 $SUB_RUNTIME "${CM:0:158}" ""; end; save m072.trn; refuse m072.trn -6 1 # CAUSE 79 bytes +V "" m073; rec 21 $SUB_RUNTIME "$(h8 1)$(h8 0)$(h16 0)$(h32 0)$(h64 1)$(h64 7)$CON6$(h64 0)$(h64 0)" ""; end; save m073.trn; refuse m073.trn -6 1 # RESOURCE with the old 8-byte cause (72 bytes) +V "" m074; rec 17 $SUB_RUNTIME "$(cause_rec "$CA" 4 3 1 "$ROOT6")" ""; end; save m074.trn; refuse m074.trn -6 1 # mode 4 +V "" m075; rec 17 $SUB_RUNTIME "$(cause_rec "$CA" $MINT 0 1 "$ROOT6")" ""; end; save m075.trn; refuse m075.trn -6 1 # MINT local_kind 0 +V "" m076; rec 17 $SUB_RUNTIME "$(cause_rec "$CA" $ADOPT 5 1 "$Z32")" ""; end; save m076.trn; refuse m076.trn -6 1 # ADOPT local_kind 5 +V "" m077; rec 17 $SUB_RUNTIME "$(cause_rec "$CA" $MINT 3 0 "$ROOT6")" ""; end; save m077.trn; refuse m077.trn -6 1 # MINT local 0 +V "" m078; rec 17 $SUB_RUNTIME "$(cause_rec "$CA" $ADOPT 3 1 "$ROOT6")" ""; end; save m078.trn; refuse m078.trn -4 1 # ADOPT root digest not zero +V "" m079; rec 17 $SUB_RUNTIME "$(cause_rec "$CA" $CREF 0 0 "$(flip "$Z32" 31)")" ""; end; save m079.trn; refuse m079.trn -4 1 # REF root digest not zero +V "" m080; rec 18 $SUB_RUNTIME "$(receipt_bind "$CA" 4)" ""; end; save m080.trn; refuse m080.trn -6 1 # receipt format 4 +V "" m081; rec 18 $SUB_RUNTIME "$(receipt_bind "$CA" 3 1)" ""; end; save m081.trn; refuse m081.trn -4 1 # receipt bind reserved +V "" m082; rec 19 $SUB_RUNTIME "$(run_link 2 2 "${G6CMP[4]}")" ""; end; save m082.trn; refuse m082.trn -6 1 # relation 2 +V "" m083; rec 19 $SUB_RUNTIME "$(run_link 1 2 "${G6CMP[4]}" 1)" ""; end; save m083.trn; refuse m083.trn -4 1 # run link reserved +V "" m084; rec 17 $SUB_RUNTIME "$CM" ""; rec 19 $SUB_RUNTIME "$(run_link 1 2 "${G6CMP[4]}")" ""; end; save m084.trn; refuse m084.trn -6 2 # RUN_LINK not record 1 +V "" m085; rec 21 $SUB_RUNTIME "$(resource 7 0 0 1 "$CA" "$CON6" 0 0)" ""; end; save m085.trn; refuse m085.trn -6 1 # op 7 +V "" m086; rec 21 $SUB_RUNTIME "$(resource 3 5 0 1 "$CA" "$CON6" 0 0)" ""; end; save m086.trn; refuse m086.trn -6 1 # REFUSE reason 5 +V "" m087; rec 21 $SUB_RUNTIME "$(resource 1 1 0 1 "$CA" "$CON6" 0 0)" ""; end; save m087.trn; refuse m087.trn -6 1 # CHARGE with a reason +V "" m088; rec 21 $SUB_RUNTIME "$(resource 5 0 11 1 "$CA" "$CON6" 0 0)" ""; end; save m088.trn; refuse m088.trn -6 1 # field 11 +V "" m089; rec 21 $SUB_RUNTIME "$(resource 1 0 0 1 "$CA" "$CON6" 0 0 1)" ""; end; save m089.trn; refuse m089.trn -4 1 # resource reserved +V "" m090; rec 17 $SUB_RUNTIME "$(cause_rec "$CA" $CREF 9 0 "$ROOT6")" ""; end; save m090.trn; refuse m090.trn -6 1 # check order: SHAPE before NONCANONICAL + +# Byte damage on g006 (not rechained). +g006 "$RUN6" "$(dig "receipt g006")" >/dev/null; end # refresh OFF/LEN for g006 +# m091 cause bit flip inside the charge (record 2): record 3's prev breaks. +mb "$(flip "$G6" $(($(R 2) + 56 + 16)))" m091.trn; refuse m091.trn -8 3 +# m092 reorder: records 1 (MINT) and 2 (charge) swapped. +mb "${G6:0:$(($(R 1) * 2))}$(cut_hex "$G6" "$(R 2)" "${LEN[2]}")$(cut_hex "$G6" "$(R 1)" "${LEN[1]}")${G6:$(($(R 3) * 2))}" m092.trn; refuse m092.trn -7 1 +# CAUSE REF carries local_kind 0 and local 0 exactly (aien-architecture#102 Q3). +V "" m093; rec 17 $SUB_RUNTIME "$(cause_rec "$CA" $CREF 3 0 "$Z32")" ""; end; save m093.trn; refuse m093.trn -6 1 # REF local_kind 3 +V "" m094; rec 17 $SUB_RUNTIME "$(cause_rec "$CA" $CREF 0 5 "$Z32")" ""; end; save m094.trn; refuse m094.trn -6 1 # REF local 5 echo "corpus written to $OUT: $(ls "$OUT"/*.trn | wc -l) transcripts" diff --git a/specs/execution-transcript/tools/trn1_verify.c b/specs/execution-transcript/tools/trn1_verify.c index ad5d4ee..4ca49ce 100644 --- a/specs/execution-transcript/tools/trn1_verify.c +++ b/specs/execution-transcript/tools/trn1_verify.c @@ -1,5 +1,6 @@ /* trn1_verify.c: reference verifier for the TRN1 execution transcript, - * wire schema 1, contract 0.1.0. Spec: ../TRN1_TRANSCRIPT_SPEC.md. + * contract 0.2.0: wire schema 1 (0.1 registry) and wire schema 3 (0.2 + * registry, adds types 17, 18, 19, 21). Spec: ../TRN1_TRANSCRIPT_SPEC.md. * * Self-contained C99: its own SHA-256 (FIPS 180-4), libc only, no imports * from any implementation repository. It exists to prove the corpus, not to @@ -35,7 +36,11 @@ enum { CHK_IDENT_LEN, CHK_END_SUBSYS, CHK_BODY_RESERVED, CHK_CAP_OP, CHK_CRASH_SEQ, CHK_CRUMB_SHAPE, CHK_CRUMB_DIGEST, CHK_ARGUS_FLAG, CHK_ARGUS_LINK, CHK_ARGUS_CONT, CHK_INPUT_DIGEST, CHK_END_ANNOT, - CHK_END_COUNT, CHK_TRAILING, CHK_TRUNCATED, CHK_LAST + CHK_END_COUNT, CHK_TRAILING, CHK_TRUNCATED, + CHK_SCHEMA_GATE, CHK_CAUSE_MODE, CHK_CAUSE_KIND, CHK_CAUSE_LOCAL, + CHK_CAUSE_ROOT, CHK_RBIND_FORMAT, CHK_RBIND_RESERVED, CHK_RLINK_REL, + CHK_RLINK_RESERVED, CHK_RLINK_FIRST, CHK_RES_OP, CHK_RES_REASON, + CHK_RES_FIELD, CHK_RES_RESERVED, CHK_REF_KIND, CHK_REF_LOCAL, CHK_LAST }; /* ---- refusal codes (spec section 6) ------------------------------------ */ @@ -132,8 +137,11 @@ static const char *subsys_name(uint16_t s) { return s < sizeof n / sizeof n[0] ? n[s] : NULL; } -/* Fixed identity length per record type; -1 = variable (rule in code), 0 = unknown type. */ -static long ident_rule(uint16_t t) { +/* Fixed identity length per record type; -1 = variable (rule in code), 0 = unknown type. + * v02 is nonzero when the file declares wire schema 3 (contract 0.2 registry). */ +#define SCHEMA_V01 1u +#define SCHEMA_V02 3u +static long ident_rule(uint16_t t, int v02) { switch (t) { case 1: return 32; /* SCHED_DECISION */ case 2: return 24; /* BRANCH_CREATE */ @@ -151,6 +159,11 @@ static long ident_rule(uint16_t t) { case 14: return 40; /* CHECKPOINT */ case 15: return -1; /* RX_CRUMB: 32 + canonical crumb bytes */ case 16: return 200; /* ARGUS_EVENT */ + case 17: return v02 ? 80 : 0; /* CAUSE (0.2) */ + case 18: return v02 ? 40 : 0; /* RECEIPT_BIND (0.2) */ + case 19: return v02 ? 48 : 0; /* RUN_LINK (0.2) */ + /* 20 TRAIN_DISPATCH: number reserved, layout not fixed in 0.2.0: unknown. */ + case 21: return v02 ? 96 : 0; /* RESOURCE (0.2) */ case T_END: return 16; default: return 0; } @@ -196,7 +209,7 @@ static int refuse(Verdict *v, int code, uint64_t ev) { v->code = code; v->event static int verify(const uint8_t *b, size_t n, Verdict *v) { size_t o = 0; uint8_t prev[32], argus_after[32]; - int have_argus = 0; + int have_argus = 0, v02 = 0; uint64_t seq = 0; memset(v, 0, sizeof *v); @@ -208,7 +221,9 @@ static int verify(const uint8_t *b, size_t n, Verdict *v) { if (n < 4) return refuse(v, R_LENGTH, 0); if (CHECK(CHK_MAGIC) && memcmp(b, "TRN1", 4) != 0) return refuse(v, R_MAGIC, 0); if (n < 6) return refuse(v, R_LENGTH, 0); - if (CHECK(CHK_VERSION) && g16(b + 4) != 1) return refuse(v, R_VERSION, 0); + if (CHECK(CHK_VERSION) && g16(b + 4) != SCHEMA_V01 && g16(b + 4) != SCHEMA_V02) return refuse(v, R_VERSION, 0); + /* With the gate disabled (mutant) a schema 1 file also gets the 0.2 types. */ + v02 = g16(b + 4) == SCHEMA_V02 || !CHECK(CHK_SCHEMA_GATE); if (n < HDR_SIZE) return refuse(v, R_LENGTH, 0); if (CHECK(CHK_HDR_FLAGS) && g16(b + 6) != 0) return refuse(v, R_NONCANONICAL, 0); if (CHECK(CHK_PRODUCER) && (g16(b + 40) == 0 || !subsys_name(g16(b + 40)))) return refuse(v, R_UNKNOWN, 0); @@ -231,7 +246,7 @@ static int verify(const uint8_t *b, size_t n, Verdict *v) { r = b + o; type = g16(r); sub = g16(r + 2); ilen = g32(r + 4); alen = g32(r + 8); /* 2. known type and subsystem */ - rule = ident_rule(type); + rule = ident_rule(type, v02); if (CHECK(CHK_TYPE) && rule == 0) return refuse(v, R_UNKNOWN, pos); if (CHECK(CHK_SUBSYS) && !subsys_name(sub)) return refuse(v, R_UNKNOWN, pos); /* 3. reserved */ @@ -258,6 +273,27 @@ static int verify(const uint8_t *b, size_t n, Verdict *v) { if (CHECK(CHK_CRUMB_SHAPE) && type == 15 && ilen >= 32 && !crumb_shape(id + 32, ilen - 32)) return refuse(v, R_SHAPE, pos); if (CHECK(CHK_ARGUS_FLAG) && type == 16 && id[128] > 1) return refuse(v, R_SHAPE, pos); if (CHECK(CHK_END_ANNOT) && type == T_END && alen != 0) return refuse(v, R_SHAPE, pos); + /* contract 0.2.0 shape rules (section 5.5); types 17..21 only reach + * here under schema 3 (or with the schema gate mutant). */ + if (type == 17) { + uint32_t mode = g32(id + 32), kind = g32(id + 36); + if (CHECK(CHK_CAUSE_MODE) && (mode < 1 || mode > 3)) return refuse(v, R_SHAPE, pos); + if (CHECK(CHK_CAUSE_KIND) && mode != 3 && (kind < 1 || kind > 4)) return refuse(v, R_SHAPE, pos); + /* REF: local_kind and local are 0 exactly (arch#102 Q3). */ + if (CHECK(CHK_REF_KIND) && mode == 3 && kind != 0) return refuse(v, R_SHAPE, pos); + if (CHECK(CHK_CAUSE_LOCAL) && mode != 3 && g64(id + 40) == 0) return refuse(v, R_SHAPE, pos); + if (CHECK(CHK_REF_LOCAL) && mode == 3 && g64(id + 40) != 0) return refuse(v, R_SHAPE, pos); + } + if (CHECK(CHK_RBIND_FORMAT) && type == 18 && (g32(id + 32) < 1 || g32(id + 32) > 3)) return refuse(v, R_SHAPE, pos); + if (CHECK(CHK_RLINK_REL) && type == 19 && g32(id) != 1) return refuse(v, R_SHAPE, pos); + if (CHECK(CHK_RLINK_FIRST) && type == 19 && pos != 1) return refuse(v, R_SHAPE, pos); + if (type == 21) { + uint8_t op = id[0], why = id[1]; + if (CHECK(CHK_RES_OP) && (op < 1 || op > 6)) return refuse(v, R_SHAPE, pos); + if (CHECK(CHK_RES_REASON) && (op == 3 ? (why < 1 || why > 4) : op == 4 ? (why < 1 || why > 3) : why != 0)) + return refuse(v, R_SHAPE, pos); + if (CHECK(CHK_RES_FIELD) && g16(id + 2) > 10) return refuse(v, R_SHAPE, pos); + } if (CHECK(CHK_BODY_RESERVED)) { int bad = 0; switch (type) { @@ -273,6 +309,11 @@ static int verify(const uint8_t *b, size_t n, Verdict *v) { } if (bad) return refuse(v, R_NONCANONICAL, pos); } + /* contract 0.2.0 reserved and must-be-zero fields (section 5.5) */ + if (CHECK(CHK_CAUSE_ROOT) && type == 17 && g32(id + 32) != 1 && !all_zero(id + 48, 32)) return refuse(v, R_NONCANONICAL, pos); + if (CHECK(CHK_RBIND_RESERVED) && type == 18 && g32(id + 36) != 0) return refuse(v, R_NONCANONICAL, pos); + if (CHECK(CHK_RLINK_RESERVED) && type == 19 && g32(id + 4) != 0) return refuse(v, R_NONCANONICAL, pos); + if (CHECK(CHK_RES_RESERVED) && type == 21 && g32(id + 4) != 0) return refuse(v, R_NONCANONICAL, pos); if (type == 15 && ilen >= 32) { uint8_t d[32]; sha2("AIEN_RX_CAUSAL_V1", 17, id + 32, ilen - 32, d); diff --git a/specs/execution-transcript/vectors/compare.txt b/specs/execution-transcript/vectors/compare.txt index 84e7c1f..bd40f37 100644 --- a/specs/execution-transcript/vectors/compare.txt +++ b/specs/execution-transcript/vectors/compare.txt @@ -14,3 +14,9 @@ g001.trn f005.trn DIVERGENCE event=11 expected=527723c59673130672775773c5c0915ca g001.trn f006.trn DIVERGENCE event=6 expected=a731fd198172bb345490827dfe2d3c4f5db41ec179c633d1e10a8d4b12564125 actual=b6877b58278d02422bdac96fd2e85eca59d1975635f97c2f2d6f5e2b079cd112 subsystem=omega-world g001.trn m001.trn refuse actual -7 event=3 m008.trn g001.trn refuse expected -1 event=0 +# Contract 0.2.0 (wire schema 3) pairs. +g006.trn g006.trn MATCH through 10 +g006.trn g008.trn MATCH through 10 +g006.trn f007.trn DIVERGENCE event=2 expected=6f80691db1c9726251d0420c1761c511d5aeb037e09cdcf29ee7b5f169a63c87 actual=8ddc47e04dfb36d8825db8f0695556886f0ea80efa976d192e2641c0ec4c3a80 subsystem=sovcore-runtime +g006.trn f008.trn DIVERGENCE event=1 expected=2a68bae2eae0bdad70cedc8db413f6e532bb3ebd6f7a6a3b2b6cdd4396f68064 actual=282eb7893d45b8ab0b2fd40b34b2602a445e71f51e5f531ddcebe21b99a04c4d subsystem=sovcore-runtime +g006.trn f009.trn DIVERGENCE event=1 expected=2a68bae2eae0bdad70cedc8db413f6e532bb3ebd6f7a6a3b2b6cdd4396f68064 actual=282eb7893d45b8ab0b2fd40b34b2602a445e71f51e5f531ddcebe21b99a04c4d subsystem=sovcore-runtime diff --git a/specs/execution-transcript/vectors/expected.txt b/specs/execution-transcript/vectors/expected.txt index ca9c84c..3ec5e18 100644 --- a/specs/execution-transcript/vectors/expected.txt +++ b/specs/execution-transcript/vectors/expected.txt @@ -70,3 +70,41 @@ m062.trn refuse -9 event=1 m063.trn refuse -9 event=2 m064.trn refuse -9 event=1 m065.trn refuse -9 event=2 +# Contract 0.2.0 (wire schema 3) vectors: causal and resource records, types 17 to 21. +g006.trn ok records=10 run=c6140e706e62613e2e7b30568f6b925f46627420591ade3d8957eddfc7eb8a14 final=af8d2ef413f65add9657b8f91b2378e24e88a956270f671983b113d826d21a6d +g008.trn ok records=10 run=e76ee8f2c37ddfa70d46a906a04293b682f89b77342389a5152825125f2b15f7 final=d5e64eb5f276ef2b486c8dcbdd725f9756c7377c3b78dd9c02a5f5e896c3f643 +g007.trn ok records=4 run=084d0375dcced6a8368c13d63ed5801421d36e7825c42de143bced8da5f2686d final=87e9b9a9b813824cf4628c05bbf2c5fee57763a077f13f8000edcc9018ab2fc2 +p003.trn ok records=7 run=231d8705a1d95780e983fd67059142fc896bd8a666b52e05425399b7b94f4c85 final=cf841d4f1e555afdbf4d372322a1a1541ceceab5f62b944d5403ec25ff0c4a6f +f007.trn ok records=3 run=c6140e706e62613e2e7b30568f6b925f46627420591ade3d8957eddfc7eb8a14 final=5a3fee5e3a42e09b16863a757a6f49a53b74e495621cc863d7b45bde809ef3f1 +f008.trn ok records=3 run=c6140e706e62613e2e7b30568f6b925f46627420591ade3d8957eddfc7eb8a14 final=3bac8f545e401c96ac0c0c7d9b248365fd023b097f02beac79cf85777cdeabe2 +f009.trn ok records=4 run=c6140e706e62613e2e7b30568f6b925f46627420591ade3d8957eddfc7eb8a14 final=32bdaa3df54253edf9632e79db59de062abdfd221d2917f320793986a49050d4 +j001.trn ok records=3 run=4339abf3a317ce51a3f121e988765b61d757f6a6fc9cf8e068cb13695af4c167 final=a27e28641f95294a3370953079fc3edf7e3863f3df253b90c2d2cefaded75cc8 +j002.trn ok records=5 run=5efad6350e730837f6b15c5379125e0de82a1550001ab7a773df9a341ed3f703 final=05ac109dae7089de4c558eba12e973dc745679285a6a9db5c8af7a8abb93ab05 +j003.trn ok records=3 run=95f1d7ae4665165c8a530972e8b62b8dfd30f02bcb9600e46884fb663a998411 final=06f6b49beb589c1312e6f9873df797557ca1812f41a8e6298f3d8461cde2d3f2 +j004.trn ok records=4 run=58811e096e63b93b802bc5d6ba15ea85224f5cd978215df4dfa255f8eb95344a final=88da5921df2cc9eed5b8c2f3100599b556d3eea7309c5adf51bc831f35aa4526 +j005.trn ok records=4 run=c79cc3e30de831e7c65dd5d20523c093ed56d010e3f7caa3b65812ae2878f89f final=d3f2211693f14fa66c94569c0aa390c4a77c648f4598e5cdee8c03d133121d63 +m070.trn refuse -5 event=1 +m071.trn refuse -5 event=1 +m072.trn refuse -6 event=1 +m073.trn refuse -6 event=1 +m074.trn refuse -6 event=1 +m075.trn refuse -6 event=1 +m076.trn refuse -6 event=1 +m077.trn refuse -6 event=1 +m078.trn refuse -4 event=1 +m079.trn refuse -4 event=1 +m080.trn refuse -6 event=1 +m081.trn refuse -4 event=1 +m082.trn refuse -6 event=1 +m083.trn refuse -4 event=1 +m084.trn refuse -6 event=2 +m085.trn refuse -6 event=1 +m086.trn refuse -6 event=1 +m087.trn refuse -6 event=1 +m088.trn refuse -6 event=1 +m089.trn refuse -4 event=1 +m090.trn refuse -6 event=1 +m091.trn refuse -8 event=3 +m092.trn refuse -7 event=1 +m093.trn refuse -6 event=1 +m094.trn refuse -6 event=1 diff --git a/specs/execution-transcript/vectors/f007.trn b/specs/execution-transcript/vectors/f007.trn new file mode 100644 index 0000000..f1b18a9 Binary files /dev/null and b/specs/execution-transcript/vectors/f007.trn differ diff --git a/specs/execution-transcript/vectors/f008.trn b/specs/execution-transcript/vectors/f008.trn new file mode 100644 index 0000000..63d382e Binary files /dev/null and b/specs/execution-transcript/vectors/f008.trn differ diff --git a/specs/execution-transcript/vectors/f009.trn b/specs/execution-transcript/vectors/f009.trn new file mode 100644 index 0000000..e28a9a0 Binary files /dev/null and b/specs/execution-transcript/vectors/f009.trn differ diff --git a/specs/execution-transcript/vectors/g006.trn b/specs/execution-transcript/vectors/g006.trn new file mode 100644 index 0000000..1115f74 Binary files /dev/null and b/specs/execution-transcript/vectors/g006.trn differ diff --git a/specs/execution-transcript/vectors/g007.trn b/specs/execution-transcript/vectors/g007.trn new file mode 100644 index 0000000..d04b314 Binary files /dev/null and b/specs/execution-transcript/vectors/g007.trn differ diff --git a/specs/execution-transcript/vectors/g008.trn b/specs/execution-transcript/vectors/g008.trn new file mode 100644 index 0000000..cf8eeaf Binary files /dev/null and b/specs/execution-transcript/vectors/g008.trn differ diff --git a/specs/execution-transcript/vectors/j001.trn b/specs/execution-transcript/vectors/j001.trn new file mode 100644 index 0000000..e2fad8b Binary files /dev/null and b/specs/execution-transcript/vectors/j001.trn differ diff --git a/specs/execution-transcript/vectors/j002.trn b/specs/execution-transcript/vectors/j002.trn new file mode 100644 index 0000000..6ddcd63 Binary files /dev/null and b/specs/execution-transcript/vectors/j002.trn differ diff --git a/specs/execution-transcript/vectors/j003.trn b/specs/execution-transcript/vectors/j003.trn new file mode 100644 index 0000000..c25ff8d Binary files /dev/null and b/specs/execution-transcript/vectors/j003.trn differ diff --git a/specs/execution-transcript/vectors/j004.trn b/specs/execution-transcript/vectors/j004.trn new file mode 100644 index 0000000..58788ff Binary files /dev/null and b/specs/execution-transcript/vectors/j004.trn differ diff --git a/specs/execution-transcript/vectors/j005.trn b/specs/execution-transcript/vectors/j005.trn new file mode 100644 index 0000000..d1480ab Binary files /dev/null and b/specs/execution-transcript/vectors/j005.trn differ diff --git a/specs/execution-transcript/vectors/join.txt b/specs/execution-transcript/vectors/join.txt new file mode 100644 index 0000000..d5fb7d3 --- /dev/null +++ b/specs/execution-transcript/vectors/join.txt @@ -0,0 +1,15 @@ +# TRN1 0.2.0 join expectations (causal-id-join-v0 section 4, aien-architecture fa46a26). +# Every file here VERIFIES under TRN1 (see expected.txt); the join must refuse it. +# Line: JOIN_REFUSED reason= run=<64 hex> event= +# The join set is that one file alone. No join implementation lives in this +# repository: these lines are NOT_RUN until a joiner (omega cut O3/O4, +# sovereign-core cut C1) checks them. The reference verifier does not read this file. +# Generated by tools/make-corpus.sh; do not edit by hand. +f007.trn JOIN_REFUSED reason=REF_UNKNOWN run=c6140e706e62613e2e7b30568f6b925f46627420591ade3d8957eddfc7eb8a14 event=2 +f008.trn JOIN_REFUSED reason=CAUSE_PLACEMENT run=c6140e706e62613e2e7b30568f6b925f46627420591ade3d8957eddfc7eb8a14 event=2 +f009.trn JOIN_REFUSED reason=REF_UNKNOWN run=c6140e706e62613e2e7b30568f6b925f46627420591ade3d8957eddfc7eb8a14 event=1 +j001.trn JOIN_REFUSED reason=CAUSE_DIGEST run=4339abf3a317ce51a3f121e988765b61d757f6a6fc9cf8e068cb13695af4c167 event=1 +j002.trn JOIN_REFUSED reason=DOUBLE_MINT run=5efad6350e730837f6b15c5379125e0de82a1550001ab7a773df9a341ed3f703 event=3 +j003.trn JOIN_REFUSED reason=REF_MISSING run=95f1d7ae4665165c8a530972e8b62b8dfd30f02bcb9600e46884fb663a998411 event=2 +j004.trn JOIN_REFUSED reason=COMMIT_ORPHAN run=58811e096e63b93b802bc5d6ba15ea85224f5cd978215df4dfa255f8eb95344a event=3 +j005.trn JOIN_REFUSED reason=RECEIPT_CAUSE run=c79cc3e30de831e7c65dd5d20523c093ed56d010e3f7caa3b65812ae2878f89f event=3 diff --git a/specs/execution-transcript/vectors/m070.trn b/specs/execution-transcript/vectors/m070.trn new file mode 100644 index 0000000..8a56c70 Binary files /dev/null and b/specs/execution-transcript/vectors/m070.trn differ diff --git a/specs/execution-transcript/vectors/m071.trn b/specs/execution-transcript/vectors/m071.trn new file mode 100644 index 0000000..97cba04 Binary files /dev/null and b/specs/execution-transcript/vectors/m071.trn differ diff --git a/specs/execution-transcript/vectors/m072.trn b/specs/execution-transcript/vectors/m072.trn new file mode 100644 index 0000000..6d7cca4 Binary files /dev/null and b/specs/execution-transcript/vectors/m072.trn differ diff --git a/specs/execution-transcript/vectors/m073.trn b/specs/execution-transcript/vectors/m073.trn new file mode 100644 index 0000000..4380599 Binary files /dev/null and b/specs/execution-transcript/vectors/m073.trn differ diff --git a/specs/execution-transcript/vectors/m074.trn b/specs/execution-transcript/vectors/m074.trn new file mode 100644 index 0000000..4984073 Binary files /dev/null and b/specs/execution-transcript/vectors/m074.trn differ diff --git a/specs/execution-transcript/vectors/m075.trn b/specs/execution-transcript/vectors/m075.trn new file mode 100644 index 0000000..107d459 Binary files /dev/null and b/specs/execution-transcript/vectors/m075.trn differ diff --git a/specs/execution-transcript/vectors/m076.trn b/specs/execution-transcript/vectors/m076.trn new file mode 100644 index 0000000..08fd512 Binary files /dev/null and b/specs/execution-transcript/vectors/m076.trn differ diff --git a/specs/execution-transcript/vectors/m077.trn b/specs/execution-transcript/vectors/m077.trn new file mode 100644 index 0000000..48afe21 Binary files /dev/null and b/specs/execution-transcript/vectors/m077.trn differ diff --git a/specs/execution-transcript/vectors/m078.trn b/specs/execution-transcript/vectors/m078.trn new file mode 100644 index 0000000..e3f282e Binary files /dev/null and b/specs/execution-transcript/vectors/m078.trn differ diff --git a/specs/execution-transcript/vectors/m079.trn b/specs/execution-transcript/vectors/m079.trn new file mode 100644 index 0000000..9c00498 Binary files /dev/null and b/specs/execution-transcript/vectors/m079.trn differ diff --git a/specs/execution-transcript/vectors/m080.trn b/specs/execution-transcript/vectors/m080.trn new file mode 100644 index 0000000..ee7ad90 Binary files /dev/null and b/specs/execution-transcript/vectors/m080.trn differ diff --git a/specs/execution-transcript/vectors/m081.trn b/specs/execution-transcript/vectors/m081.trn new file mode 100644 index 0000000..a3a0e51 Binary files /dev/null and b/specs/execution-transcript/vectors/m081.trn differ diff --git a/specs/execution-transcript/vectors/m082.trn b/specs/execution-transcript/vectors/m082.trn new file mode 100644 index 0000000..afee49f Binary files /dev/null and b/specs/execution-transcript/vectors/m082.trn differ diff --git a/specs/execution-transcript/vectors/m083.trn b/specs/execution-transcript/vectors/m083.trn new file mode 100644 index 0000000..1c1441f Binary files /dev/null and b/specs/execution-transcript/vectors/m083.trn differ diff --git a/specs/execution-transcript/vectors/m084.trn b/specs/execution-transcript/vectors/m084.trn new file mode 100644 index 0000000..9c353bd Binary files /dev/null and b/specs/execution-transcript/vectors/m084.trn differ diff --git a/specs/execution-transcript/vectors/m085.trn b/specs/execution-transcript/vectors/m085.trn new file mode 100644 index 0000000..e7f5af5 Binary files /dev/null and b/specs/execution-transcript/vectors/m085.trn differ diff --git a/specs/execution-transcript/vectors/m086.trn b/specs/execution-transcript/vectors/m086.trn new file mode 100644 index 0000000..4063aa6 Binary files /dev/null and b/specs/execution-transcript/vectors/m086.trn differ diff --git a/specs/execution-transcript/vectors/m087.trn b/specs/execution-transcript/vectors/m087.trn new file mode 100644 index 0000000..02269fe Binary files /dev/null and b/specs/execution-transcript/vectors/m087.trn differ diff --git a/specs/execution-transcript/vectors/m088.trn b/specs/execution-transcript/vectors/m088.trn new file mode 100644 index 0000000..a2babae Binary files /dev/null and b/specs/execution-transcript/vectors/m088.trn differ diff --git a/specs/execution-transcript/vectors/m089.trn b/specs/execution-transcript/vectors/m089.trn new file mode 100644 index 0000000..37e48c8 Binary files /dev/null and b/specs/execution-transcript/vectors/m089.trn differ diff --git a/specs/execution-transcript/vectors/m090.trn b/specs/execution-transcript/vectors/m090.trn new file mode 100644 index 0000000..86e0536 Binary files /dev/null and b/specs/execution-transcript/vectors/m090.trn differ diff --git a/specs/execution-transcript/vectors/m091.trn b/specs/execution-transcript/vectors/m091.trn new file mode 100644 index 0000000..df936da Binary files /dev/null and b/specs/execution-transcript/vectors/m091.trn differ diff --git a/specs/execution-transcript/vectors/m092.trn b/specs/execution-transcript/vectors/m092.trn new file mode 100644 index 0000000..554dc9a Binary files /dev/null and b/specs/execution-transcript/vectors/m092.trn differ diff --git a/specs/execution-transcript/vectors/m093.trn b/specs/execution-transcript/vectors/m093.trn new file mode 100644 index 0000000..6501cff Binary files /dev/null and b/specs/execution-transcript/vectors/m093.trn differ diff --git a/specs/execution-transcript/vectors/m094.trn b/specs/execution-transcript/vectors/m094.trn new file mode 100644 index 0000000..e9880a4 Binary files /dev/null and b/specs/execution-transcript/vectors/m094.trn differ diff --git a/specs/execution-transcript/vectors/p003.trn b/specs/execution-transcript/vectors/p003.trn new file mode 100644 index 0000000..26c6502 Binary files /dev/null and b/specs/execution-transcript/vectors/p003.trn differ