File size: 11,406 Bytes
518343a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
/**
 * @file runtime/src/rae1/schema.ts
 * @description RAE-1 v1.0 — Receipt-Attested Evaluation Protocol
 *
 * DSSE envelope schema and RAE-1 payload types.
 *
 * Lean ref:  SZL.AGI.PACBayes.capability_improvement_rate_bound
 * Lean file: Lutar/PACBayes/CapabilityImprovementRate.lean
 * Lean commit: c4d1379568... (pinned at proof time)
 * Lean repo:   szl-holdings/lutar-lean
 * Lean build:  sorry_disclosed (2 named sorries: AsymptoticTightness, KLMonotonicity)
 *
 * Protocol spec: RAE_1_PROTOCOL.md §2
 * Schema version: rae1.0
 *
 * Doctrine v7 — no fake lake-green, no new axioms.
 * Signed-off-by: SZL Engineering <eng@szl-holdings.com>
 */

// ─── Constants ───────────────────────────────────────────────────────────────

/** Current RAE-1 protocol schema version. Bump minor for backward-compatible extensions. */
export const RAE1_SCHEMA_VERSION = "rae1.0" as const;

/** MIME type for the DSSE payload. MUST match exactly across all implementations. */
export const RAE1_PAYLOAD_TYPE = "application/vnd.szl.rae1+json" as const;

/** Minimum number of judges required for a RAE-1-compliant ensemble (§3.1). */
export const RAE1_MIN_JUDGES = 3 as const;

/** Lean theorem name referenced in all receipts. Verified at commit c4d1379568. */
export const LEAN_THEOREM_NAME = "SZL.AGI.PACBayes.capability_improvement_rate_bound" as const;

/** Lean file path within szl-holdings/lutar-lean. */
export const LEAN_THEOREM_FILE = "Lutar/PACBayes/CapabilityImprovementRate.lean" as const;

/** Genesis sentinel for the first receipt in any chain. */
export const CHAIN_GENESIS = "GENESIS" as const;

// ─── Judge Types ──────────────────────────────────────────────────────────────

/** System prompt variant that defines a judge's evaluation bias. */
export type JudgePromptVariant = "rigorous" | "creative" | "verification";

/** Verdict options for a single judge or the ensemble. */
export type Verdict = "SOLVED" | "UNCLEAR" | "WRONG";

/**
 * Single judge evaluation record.
 *
 * Lean ref: SZL.AGI.PACBayes.capability_improvement_rate_bound
 *           file: Lutar/PACBayes/CapabilityImprovementRate.lean
 *           commit: c4d1379568
 *
 * Per RAE-1 §3.1: judges MUST run in parallel (non-collusion property).
 */
export interface RAE1JudgeRecord {
  /** Unique identifier for this judge invocation, e.g. "judge-0-rigorous". */
  judge_id: string;

  /** Model name with version, e.g. "claude-3-5-sonnet-20241022". */
  model_name: string;

  /**
   * System prompt variant used. Determines evaluation bias:
   * - rigorous: conservative, strict correctness, prefer UNCLEAR over WRONG
   * - creative: liberal, accepts non-standard approaches
   * - verification: answer-extraction + arithmetic check
   */
  system_prompt_variant: JudgePromptVariant;

  /** This judge's verdict on the problem. */
  verdict: Verdict;

  /** Calibrated confidence in [0.0, 1.0]. */
  confidence_01: number;

  /** Wall-clock latency for this judge call in milliseconds. */
  latency_ms: number;

  /** Token usage breakdown for this call. */
  token_usage: {
    input: number;
    output: number;
    total: number;
  };
}

// ─── RAE-1 Payload ───────────────────────────────────────────────────────────

/**
 * Inner JSON payload, base64url-encoded inside the DSSE envelope.
 *
 * This is the attestation record for a single benchmark problem evaluation.
 * Every field is required unless marked optional; validators MUST reject
 * receipts with missing required fields (see validate.ts).
 *
 * Lean ref: SZL.AGI.PACBayes.capability_improvement_rate_bound
 *           file: Lutar/PACBayes/CapabilityImprovementRate.lean
 *           commit: c4d1379568
 *
 * Schema: RAE_1_PROTOCOL.md §2.2
 */
export interface RAE1Payload {
  // ── Schema identification ─────────────────────────────────────────────────

  /** Protocol version. MUST equal "rae1.0". */
  schema_version: typeof RAE1_SCHEMA_VERSION;

  // ── Run-level metadata ───────────────────────────────────────────────────

  /** UUIDv4 — unique per evaluation run (all receipts in a run share this). */
  run_id: string;

  /** ISO 8601 UTC timestamp of this evaluation run, e.g. "2026-05-27T18:34:00Z". */
  run_timestamp: string;

  /** Benchmark name, e.g. "bench-2024". */
  benchmark_name: string;

  /** Benchmark year as a number, e.g. 2024. */
  benchmark_year: number;

  /** Evaluation harness semver, e.g. "v2.0.0". */
  harness_version: string;

  /** Git SHA of the harness code at run time (allows deterministic replay). */
  harness_commit_sha: string;

  // ── Problem-level fields ─────────────────────────────────────────────────

  /** Problem identifier, e.g. "bench-2024-A1". */
  problem_id: string;

  /**
   * SHA-256 hex digest of the UTF-8 problem text.
   * Allows auditors to verify the exact problem version evaluated.
   */
  problem_sha256: string;

  /** Domain classifier output, e.g. "combinatorics". */
  domain: string;

  // ── Judge ensemble ───────────────────────────────────────────────────────

  /**
   * Judge records — MUST have length >= RAE1_MIN_JUDGES (3).
   * Judges MUST run in parallel to ensure non-collusion (§3.3).
   */
  judges: RAE1JudgeRecord[];

  // ── Ensemble decision ────────────────────────────────────────────────────

  /** Majority-vote verdict. Ties → "UNCLEAR". */
  ensemble_verdict: Verdict;

  /** Count of judges that voted SOLVED. */
  votes_solved: number;

  /** Count of judges that voted UNCLEAR. */
  votes_unclear: number;

  /** Count of judges that voted WRONG. */
  votes_wrong: number;

  // ── Score contribution ───────────────────────────────────────────────────

  /** True iff ensemble_verdict === "SOLVED". Contributes 1 to n_solved. */
  is_solved: boolean;

  // ── Receipt chain linkage ────────────────────────────────────────────────

  /**
   * SHA-256 hex digest of the previous receipt's raw JSON line (compact),
   * or "GENESIS" for the first receipt in a run.
   *
   * Chain integrity: hash(R_i) = SHA-256(JSON.stringify(envelope_i))
   *                  R_{i+1}.payload.prev_hash = hex(hash(R_i))
   * See RAE_1_PROTOCOL.md §4.1
   */
  prev_hash: string;

  /** 0-based position of this receipt in the chain. MUST equal line index. */
  receipt_index: number;

  // ── Lean theorem reference ───────────────────────────────────────────────

  /**
   * Name of the Lean theorem bounding what this score means.
   *
   * MUST be "SZL.AGI.PACBayes.capability_improvement_rate_bound"
   * for RAE-1 v1.0 compliant receipts.
   *
   * Lean ref: SZL.AGI.PACBayes.capability_improvement_rate_bound
   *           commit: c4d1379568
   */
  lean_theorem_name: string;

  /** Path to the theorem file within lean_repo, e.g. "Lutar/PACBayes/CapabilityImprovementRate.lean". */
  lean_theorem_file: string;

  /** Git SHA of szl-holdings/lutar-lean at the time this receipt was created. */
  lean_commit_sha: string;

  /** GitHub slug of the Lean repository, e.g. "szl-holdings/lutar-lean". */
  lean_repo: string;

  /**
   * Build status of the Lean file at lean_commit_sha.
   *
   * Doctrine v7: "sorry_undisclosed" is FORBIDDEN and will cause validation failure.
   *
   * - "green": all proofs complete, 0 sorries
   * - "sorry_disclosed": sorries present but named and documented with discharge routes
   * - "sorry_undisclosed": FORBIDDEN by Doctrine v7
   * - "failed": build did not exit 0
   */
  lean_build_status: "green" | "sorry_disclosed" | "sorry_undisclosed" | "failed";

  /**
   * Number of sorry occurrences in the Lean file.
   * MUST be 0 if lean_build_status === "green".
   * MUST match the actual grep count of sorry in the file.
   */
  lean_sorry_count: number;

  // ── Staged advisory flag ─────────────────────────────────────────────────

  /**
   * True if this claim is pre-production and should be treated with caution.
   * MUST be true when MOCK_JUDGES=1 or no real API keys are present.
   */
  staged_advisory: boolean;

  /** Explanation of why staged_advisory is true, if applicable. */
  staged_notes?: string;
}

// ─── DSSE Envelope ───────────────────────────────────────────────────────────

/**
 * DSSE (Dead Simple Signing Envelope) outer wrapper.
 *
 * Per the DSSE spec (github.com/secure-systems-lab/dsse) and RAE-1 §2.1.
 *
 * PAE (Pre-Authentication Encoding):
 *   PAE(type, payload) = LE64(2) || LE64(len(type)) || type
 *                      || LE64(len(payload)) || payload
 *
 * The sig field is base64url(HMAC-SHA-256(key, PAE(payloadType, payload))).
 *
 * Lean ref: SZL.AGI.PACBayes.capability_improvement_rate_bound
 *           file: Lutar/PACBayes/CapabilityImprovementRate.lean
 *           commit: c4d1379568
 */
export interface DSSEEnvelope {
  /** MUST equal RAE1_PAYLOAD_TYPE = "application/vnd.szl.rae1+json". */
  payloadType: typeof RAE1_PAYLOAD_TYPE;

  /** Base64url-encoded JSON of RAE1Payload. */
  payload: string;

  /**
   * Array of signatures. Each entry has:
   * - keyid: HMAC key ID in format "hmac-sha256:<sha256-of-key-material>"
   * - sig:   base64url(HMAC-SHA-256(key, PAE(payloadType, payload)))
   */
  signatures: Array<{
    keyid: string;
    sig: string;
  }>;
}

// ─── Chain Summary ────────────────────────────────────────────────────────────

/**
 * Published after every complete benchmark run.
 * Committed to runtime/bench-2025/latest.json and tagged with Zenodo DOI.
 *
 * See RAE_1_PROTOCOL.md §4.3
 */
export interface ChainSummary {
  run_id: string;
  run_timestamp: string;
  benchmark_name: string;
  n_problems: number;
  n_solved: number;
  score_01: number;
  chain_root: string;
  chain_head: string;
  receipts_jsonl_sha256: string;
  lean_repo: string;
  lean_commit_sha: string;
  lean_theorem: string;
  lean_build_status: RAE1Payload["lean_build_status"];
  lean_sorry_count: number;
  staged_advisory: boolean;
  zenodo_doi?: string;
}