# Pure receipt creation and replay v1
Status: next M2 increment. This implements deterministic byte identity and re-evaluation, NOT receipt persistence, signatures, verified world observations or authorization. Existing `check run` and `observe` behavior is unchanged.
## Commands
- `instinct check receipt --input FILE|-`: input is the existing pure check request. Evaluate with the same kernel and return a bounded receipt.
- `instinct check replay --input FILE|-`: input is exactly `{"request": <pure check request>, "receipt": <receipt object>}`. Re-evaluate the current supplied request, rebuild the expected receipt and compare every field.
Both commands read at most 1 MiB, create no bank/sidecar/temp file, have no ambient scope, and do not read artifact paths or run commands. Explicit `check receipt --help` and `check replay --help` are side-effect-free.
## Receipt schema
Exactly these keys (unknown or duplicate keys rejected):
```json
{
"schema": "instinct.check-receipt/v1",
"verifier": "instinct.check-kernel/v1",
"check_id": "artifact-membership",
"revision": 1,
"input_sha256": "<64 lowercase hex>",
"result_sha256": "<64 lowercase hex>",
"verdict": "pass",
"authorization": "not_evaluated",
"evidence_origin": "caller_reported"
}
```
Receipt creation accepts pass/fail/abstain kernel results; malformed requests/output-limit errors yield the existing structured `instinct.check-error/v1` exit 2. A receipt carries no raw facts, witness, scope, paths or private content. Its digests may still leak low-entropy values, so it remains private evidence, not automatically exportable metadata. No clock or random fields.
## Canonical input identity
Validate the entire request using the current kernel BEFORE canonicalizing. Reuse its strict JSON parser and exact type rules; never hash invalid/coerced input.
Create canonical input using these explicit equivalences:
- decoded object keys sorted by Unicode scalar order; Unicode values kept exact;
- declared `set<string>` facts sorted; duplicates have already been rejected;
- `required_conditions` sorted (its order is nonsemantic); duplicates rejected;
- ordered expression arrays retain order;
- omitted top-level facts/conditions/scope equal their documented empty-object defaults;
- omitted definition required_conditions/scope equal documented empty defaults;
- missing facts remain missing, never null or invented false;
- canonical int strings remain exact; revision integer literal remains exact;
- no additional normalization (case, whitespace within strings, path normalization, condition false versus missing).
Serialize the canonical JSON tree to a typed length-framed binary encoding: Null tag0, Bool tag1 then byte0/1, Number tag2 then u64 big-endian byte-length+UTF8 literal, String tag3 then same length+bytes, Array tag4 then u64 count+each encoded element, Object tag5 then u64 count+each key encoded as String followed by value. Container/key ordering as above. No ambiguous concatenation.
Hash preimage: ASCII `instinct.check-input/v1` + a zero byte + canonical binary bytes. Use existing pure `digest::sha256`, not a shell or weak lesson ID hash.
## Canonical result identity
A semantically equivalent set/condition ordering must not fail replay merely because evaluation steps differ. Form the result core from the existing parsed kernel result by removing only `steps`; retain schema, check_id, revision, verdict, reason, witness, missing, scope, authorization and evidence_origin. Run mode only (no explanation). Encode with the same sorted-object binary format, preserving any ordered arrays. Hash ASCII `instinct.check-result-core/v1` + zero byte + encoded core.
This is a digest of a supplied-fact decision. It does not claim that a real filesystem or remote service has stayed unchanged. Steps remain execution telemetry, not evidence identity.
## Replay results
Validate receipt field types, fixed schema/verifier/authority/origin strings, ID/revision types, lowercase hex digests and pass/fail/abstain verdict. Recompute expected receipt from supplied request.
If all fields match, output:
`{"schema":"instinct.check-replay/v1","status":"consistent","verdict":<current verdict>,"input_sha256":...,"result_sha256":...,"authorization":"not_evaluated","evidence_origin":"caller_reported","meaning":"matches_recomputed_supplied_facts_not_world_truth"}`.
If a well-shaped receipt differs, output the same replay schema with `status:"mismatch"`, `verdict:"abstain"`, `reason:"receipt_mismatch"`, authority/origin and the same meaning string. Do not echo the old mismatched receipt or raw inputs. Exit0 for consistent/mismatch; exit2 for malformed input or unsupported revision. Recomputing a forged receipt with changed facts can legitimately be consistent: this mechanism is not authentication.
Total output <=65536bytes; input nesting/size and check limits remain enforced. Default/check legacy commands do not change and hooks do not consume receipts in this increment.
## Independent gates
- Known SHA vectors; deterministic repeated receipts.
- Object key order and set/required-condition permutations preserve digests/replay.
- Ordered logic, missing versus supplied fact, false versus missing condition, exact scope/check revision/fact changes alter input identity even if verdict stays same.
- One-byte digest mutation, forged verdict/ID/revision or changed fact causes mismatch, never a false consistent result.
- Malformed/unknown/duplicate receipt fields or unsupported verifier are errors.
- Missing evidence yields abstain receipt, never PASS.
- No private sentinel appears in receipt/replay output except a predeclared public check ID; no filesystem writes or ambient environment scope.
- A consistent receipt still explicitly says authorization not evaluated and does not claim observation or authentication.
First implementation uses no ledger. Durable attachment, observation-bound receipts and cache invalidation remain later M2/M3 work.