# H33 Verifier Track

External credibility layer for Authority Infrastructure. **Not UI first.** Four artifacts that must exist before any verifier UI:

1. **Corpus** — named scenarios covering every verdict class, every edge
2. **Fixtures** — `(input, expected output)` tuples, byte-comparable
3. **Second implementation** — independent verifier (TypeScript reference)
4. **Determinism tests** — every implementation runs the corpus, byte-compares

These are the four things the verifier checks.

## Why it matters

Authority Infrastructure makes a strong claim: every receipt is replayable, and the same receipt produces the same answer regardless of which implementation runs it. The corpus + fixtures + independent implementations + determinism tests are how that claim becomes provable, not just asserted.

Without these, the platform fragments at exactly the moment it tries to demonstrate independence:

- A regulator running their own verifier and seeing a different `state_id` from the server-stored receipt → audit trail destroyed
- An adversarial third party compiling their own verifier → no reference truth to verify against
- A cached browser verdict diverging from the server's recompute → silently corrupts investigations

The corpus is the conformance contract.

## Directory layout

```
verifier/
├── README.md                       ← this file
├── corpus/
│   ├── manifest.json              ← index of scenarios + verdict-class coverage
│   ├── 00_single_grant.json       ← per-scenario fixture
│   ├── 01_grant_then_revoke.json
│   ├── 02_two_tier_chain.json
│   ├── 03_orphan_grant.json
│   ├── 04_policy_missing.json
│   ├── 05_authority_conflict.json
│   ├── 06_open_challenge.json
│   └── 07_revoked_chain.json
└── reference-impl-ts/             ← independent TypeScript implementation
    ├── package.json
    ├── tsconfig.json
    ├── src/
    │   ├── replay.ts              ← TypeScript port of astate_replay.rs
    │   └── verify.ts              ← CLI: runs corpus, asserts byte-identical output
    └── test/
        └── conformance.test.ts    ← runs every fixture; exits non-zero on divergence
```

## How to run the corpus

### Browser engine (already shipped)
Open `/agent-zero/replay-engine/determinism-test.html` — runs the original 4 fixtures.

### TypeScript reference impl (this track)
```
cd agent-zero/verifier/reference-impl-ts
npm install
npm run conformance
```

Expected: every fixture passes byte-for-byte. Any failure is a verifier-track violation that must be investigated before any feature ships.

### Rust canonical engine (scif-backend)
```
cd scif-backend
cargo run --example dump_replay_fixtures > /tmp/regenerated.json
diff <(jq -S . agent-zero/verifier/corpus/all.json) <(jq -S . /tmp/regenerated.json)
```

Expected: zero diff.

## Verdict class coverage

| Verdict | Fixture(s) | Why it matters |
|---|---|---|
| `Valid` | `00_single_grant`, `01_grant_then_revoke`, `02_two_tier_chain` | Happy path — grants present, chain valid, revocations honored |
| `ProvenanceBroken` | `03_orphan_grant` | Grant's grantor cannot trace to tenant root |
| `PolicyMissing` | `04_policy_missing` | Grant references a policy that was never registered |
| `AuthorityConflict` | `05_authority_conflict` | Duplicate authority_id observed → first kept, second flagged |
| `Incomplete` | `06_open_challenge` | Open challenge at query time → snapshot is incomplete |
| `RevokedChain` | `07_revoked_chain` | Ancestor in delegation chain was revoked before query time |

Coverage is intentional. Every verdict class the Rust engine can emit appears in the corpus.

## Provenance of the corpus

Fixtures 00–03 are generated by the Rust canonical engine (`scif-backend/src/agent_zero/astate_replay.rs`) via `examples/dump_replay_fixtures.rs`. These are the **byte-canonical truth** for browser, TypeScript, and any future implementation.

Fixtures 04–07 are added by this MR using the same canonical-form rules. They must be round-tripped through Rust before declaring canonical — that round-trip is the second deliverable of this track.

## What is NOT in scope yet

- UI for browsing the corpus
- Public verifier endpoint
- Anchor verification (H33-74 chain)
- PQ signature verification

The verifier UI is the LAST thing built, after the corpus, fixtures, second implementation, and determinism tests have settled.

> The verifier becomes the platform's external credibility layer. Built quietly, in the right order.

## Cross-links

- `/agent-zero/replay-engine/` — browser implementation (v1, JavaScript)
- `/agent-zero/replay-engine/determinism-fixtures.json` — original 4 Rust-canonical fixtures
- `scif-backend/src/agent_zero/astate_replay.rs` — Rust canonical engine
- `scif-backend/src/api/qsign_authority_state.rs` — Authority State API (5A) + What Changed API (5B)
