# CAIN-42 × TALOS Verification Protocol Specification
## Evolution 5 — Operation Double Sovereign
**Protocol Version:** `cain42.talos.v1`  
**Schema Identifier:** `cain42.talos.envelope.v1`  
**Signatures:** Ed25519 (RFC 8032)  
**Canonical Serialization:** RFC 8785 JSON (Integer-only, Surrogate-free UTF-16BE sorted keys)

---

### 1. Architectural Contract & Invariant

```
AGENT PROPOSES → CAIN-42 DECIDES → TALOS VERIFIES & ENFORCES → AUTHORIZED EXECUTION → TAMPER-EVIDENT EVIDENCE
                                ↓
                 NO VALID AUTHORIZATION → NO PROTECTED EXECUTION
```

#### Core Axioms:
1. **Separation of Concerns:** CAIN-42 is the decision authority (evaluating context, identity, policy, risk, preconditions). TALOS Verify Kernel is the execution-boundary gatekeeper (evaluating cryptographic proofs, single-use replay nonces, OS kernel boundaries).
2. **Independent Rejection Monopoly:** TALOS must never blindly trust a CAIN status string. TALOS independently validates Ed25519 signatures over the RFC 8785 canonical bytes. If any TALOS check fails, execution halts fail-closed.
3. **Mutual Denial Precedence:** Neither engine can override a denial from the other. A CAIN `DENY` decision is immutable and cannot be thawed by TALOS. A TALOS rejection (`REPLAYED`, `EXPIRED`, `INVALID_SIGNATURE`, `SCOPE_MISMATCH`, etc.) halts execution regardless of CAIN's decision.

---

### 2. Authorization Envelope Structure

Every authorization decision is encapsulated in a canonical JSON object:

```json
{
  "envelope_id": "env-3b8c45f1-825b-43d9-952a-e24a87c126d4",
  "decision_id": "dec-f87c1b22-44a1-4322-a9b1-0988cc2113ea",
  "request_id": "req-9912bc8e-128a-4422-b912-1188cc0012ef",
  "protocol_version": "cain42.talos.v1",
  "schema_version": "cain42.talos.envelope.v1",
  "principal_did": "did:cain:enterprise:agent_01",
  "tenant_id": "tenant-enterprise-prod",
  "agent_id": "agent-orchestrator",
  "action": "tool.run_command",
  "target": "system.shell",
  "resource_scope": {
    "allowed_read_paths": ["/workspace/project", "/tmp/sandbox"],
    "allowed_write_paths": ["/workspace/project/output"],
    "allow_network": false,
    "allowed_tcp_ports": [],
    "max_memory_bytes": 268435456,
    "timeout_seconds": 30
  },
  "policy_version": "pol-v1.0",
  "policy_digest": "4a7267104b901e138a0928a0cc31028e18290bcda12480182810a019280bca12",
  "decision": "ALLOW",
  "reason_code": "POLICY_EVALUATION_PASS",
  "iat": 1791784000,
  "exp": 1791784060,
  "nonce": "nonce-7b98c21a08b9e812a0f819",
  "kid": "cain-key-2026-prod-01",
  "signature_algorithm": "Ed25519",
  "approval_reference": null,
  "constraints": {
    "max_processes": 1
  },
  "signature": "base64(Ed25519_Signature)"
}
```

---

### 3. Verification State Machine

TALOS evaluates the envelope through an explicit 11-state state machine:

| State | Definition | Action |
|:---|:---|:---|
| `ALLOW` | All cryptographic, temporal, scope, identity, and nonce checks passed. | Proceed to OS-confined execution. |
| `DENY` | Explicit policy denial from CAIN or missing required human approval. | Halt execution fail-closed (code 126). |
| `EXPIRED` | Current timestamp exceeds envelope `exp`. | Reject as expired token. |
| `REPLAYED` | Nonce or decision_id already consumed in `TalosDurableLedger`. | Reject as duplicate/replay attack. |
| `INVALID_SIGNATURE` | Corrupt signature, key mismatch, unknown KID, or disallowed algorithm. | Reject fail-closed. |
| `IDENTITY_MISMATCH` | Runtime caller principal DID or tenant does not match envelope. | Reject privilege usurpation. |
| `SCOPE_MISMATCH` | Requested action or target differs from authorized envelope. | Reject scope escalation. |
| `POLICY_MISMATCH` | Required policy version or digest does not match active baseline. | Reject policy drift. |
| `REVOKED` | Decision ID or signing key listed in revocation ledger. | Immediate execution halt. |
| `INDETERMINATE` | Clock uncertainty, future-dated token (`iat > now + 5s`), or malformed envelope. | Reject ambiguity fail-closed. |
| `ENFORCEMENT_UNAVAILABLE` | Kernel LSM or ledger unavailable and downgrade forbidden. | Reject unconfined execution. |

---

### 4. Replay Prevention & Single-Use Ledger Semantics

- **Atomicity:** `consume_nonce_atomic()` utilizes SQLite WAL with `BEGIN IMMEDIATE` transactions.
- **Concurrency Safety:** If $N$ parallel threads submit the same envelope, exactly 1 thread transitions to `ALLOW`; the remaining $N-1$ threads are rejected with `REPLAYED`.
- **Durability Across Crashes:** Nonces are committed to disk before process spawn begins. A process restart cannot reset consumed nonces.
