Skip to content

calibration: attestation-evidence envelope — schema, pure structural validator, and report-data binding helper #8541

Description

@JSONbored

Problem

The backtest system persists every CI run's result with metadata.corpusChecksum plus head/base SHAs (via persistThresholdBacktestRuns in src/services/threshold-backtest-run.ts), which makes verdicts third-party reproducible for public corpora. The attested-evaluation roadmap (parent epic) needs a typed evidence seam before any TEE infrastructure exists: a schema describing "this run executed inside an attested environment" plus a pure validator, so the runner work later attaches evidence to runs without inventing an ad-hoc shape. At origin/main no attestation-related code exists anywhere in the repo. This issue is that seam — pure code only, zero infrastructure, zero behavior change.

Requirements

⚠️ Scope is exactly three exports in one new file plus its tests and one barrel line. This issue is NOT satisfied by: wiring anything into ORB (src/**), performing cryptographic verification of attestation reports, adding dependencies, touching any existing calibration module's behavior, or any change outside the three files named below.

  • New file packages/loopover-engine/src/calibration/attestation-envelope.ts, exporting exactly:
    • type AttestationEnvelope with fields: schemaVersion: 1 (literal); teeTechnology: "sev-snp" | "tdx"; runtimeClass: string (non-empty, ≤ 128 chars); measurement: string (lowercase hex, 32–128 hex chars); reportData: string (lowercase hex, exactly 64 chars — a sha256); attestationReport: string (base64, non-empty, ≤ 65536 chars); verification: a discriminated union — { status: "unverified" } | { status: "verified"; verifierId: string; verifiedAt: string } | { status: "failed"; verifierId: string; verifiedAt: string; reason: string } (verifierId/reason non-empty; verifiedAt must parse as an ISO-8601 datetime).
    • function buildAttestationReportData(binding: { corpusChecksum: string; headSha: string; baseSha: string }): string — lowercase-hex sha256 of `${corpusChecksum}:${headSha}:${baseSha}` via node:crypto (mirror backtest-split.ts's existing sha256 usage; no new dependency).
    • function validateAttestationEnvelope(value: unknown): { valid: true; envelope: AttestationEnvelope } | { valid: false; errors: string[] } — structural validation of every field/constraint above; on failure, errors names each failing field path; the function never throws for any input (including null, primitives, arrays, and objects with extra keys — extra keys are rejected with an error naming the key).
  • One line in packages/loopover-engine/src/index.ts: export * from "./calibration/attestation-envelope.js"; (matching the existing calibration export lines).
  • No cryptographic verification of the attestation report — validation is structural only. Cryptographic verification is later maintainer work in the parent epic; implementing any of it here does not satisfy this issue and adds unreviewable scope.
  • Tests: every validation rule exercised on both arms (accept at the boundary, reject just past it — e.g. 64-char vs 63/65-char reportData, hex vs non-hex, each union variant valid + each variant with a missing/invalid member, valid-then-extra-key), buildAttestationReportData pinned against a precomputed vector, and the never-throws guarantee covered for non-object inputs. 100% of new lines and branches covered — both arms of every conditional.
  • Coverage must appear in Codecov's patch report: follow the package's existing test convention for calibration modules, and if the package-native runner's coverage is not what Codecov measures, add the root-vitest mirror exactly as test(calibration): make signal-tracking's real coverage visible to Codecov #8438 did for signal-tracking.ts.

Deliverables

  • attestation-envelope.ts with the three exports, exact constraints above
  • Barrel export line in packages/loopover-engine/src/index.ts
  • Tests covering every constraint's both arms + the pinned report-data vector, Codecov-visible

Links & Resources

Boundaries

Pure module + tests + one barrel line only. No src/** changes, no crypto verification, no new dependencies, no changes to existing calibration modules.

Metadata

Metadata

Assignees

No one assigned

    Labels

    gittensor:featureGittensor-scored feature linked to a feature issue — scores a 0.25x multiplier.help wantedExtra attention is needed

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions