The worked example — replay-verify, in process
The service serves two domains. The third domain, replay-verify, lives at the record layer directly — which is where your own domain will live first, so this section is the shape of your integration. It is the SimVerify shape: a founding commits a match (game, ruleset, seed); facts append an input stream (tick, actor, action) and nothing else; one recipe derives the final state; a second recipe verifies a claimed score by re-deriving the run. Outcomes are derived, never submitted — append a fact carrying a damage field and the layer refuses it (§6).
First, the domain's own suite (from the tree root):
cd domains/replay-verify
npm test
Expected: all tests pass — 13 tests, 0 failures — including the domain's two-clocks proof (the same record derived under shifted wall clocks, byte-identical) and its verdict-flip proof.
Now drive it yourself. Create domains/replay-verify/drive.mjs with exactly this content:
// drive.mjs — the integration guide's §3 driver: the worked example,
// end to end. Run from this directory: node drive.mjs
import { replayVerify, buildCanonicalRecord, buildTamperedRecord } from './src/replay-verify.mjs';
const honest = buildCanonicalRecord();
const fin = replayVerify.collapse(honest, 'final-state@1');
console.log(`SCORE (read from the derivation, never hardcoded): ${fin.artifact.score}`);
console.log(`STATE HASH: ${fin.artifact.stateHash}`);
console.log(`MANIFEST: ${JSON.stringify(fin.manifest)}`);
const ver = replayVerify.collapse(honest, 'verify-score@1', { params: { claimedScore: fin.artifact.score } });
console.log(`VERDICT ON THE HONEST CLAIM: ${ver.artifact.verdict}`);
const rep = replayVerify.replay(honest, 'final-state@1', fin.manifest);
console.log(`REPLAY OF THE FINAL-STATE MANIFEST: ${rep.verdict}`);
const tampered = buildTamperedRecord();
const tver = replayVerify.collapse(tampered, 'verify-score@1', { params: { claimedScore: fin.artifact.score } });
console.log(`TAMPERED RUN'S DERIVED SCORE: ${tver.artifact.derivedScore}`);
console.log(`VERDICT ON THE HONEST CLAIM AGAINST THE TAMPERED RECORD: ${tver.artifact.verdict}`);
const trep = replayVerify.replay(tampered, 'final-state@1', fin.manifest);
console.log(`REPLAY OF THE HONEST MANIFEST AGAINST THE TAMPERED RECORD: ${trep.verdict}`);
Run it: node drive.mjs. Expected output, verbatim:
SCORE (read from the derivation, never hardcoded): 16
STATE HASH: sha256:b46ee3e49195fd3daca1ab73e175c04d7a61b8de991a72370ccd5c911c1cdf90
MANIFEST: {"recordHash":"sha256:47fd4fcf4aa2d5c79c8d4fe3be4ef5a639d02c63fa97ea5502f42ce05912d7cf","position":8,"recipe":"final-state@1","engine":"quantum-engine-core/0.1.0","outputHash":"sha256:d8e314666c0de8d838e0b10744d2e5ece1a128064ff104a668cc97d9655c98ea"}
VERDICT ON THE HONEST CLAIM: VERIFIED
REPLAY OF THE FINAL-STATE MANIFEST: MATCH
TAMPERED RUN'S DERIVED SCORE: 10
VERDICT ON THE HONEST CLAIM AGAINST THE TAMPERED RECORD: REFUTED
REPLAY OF THE HONEST MANIFEST AGAINST THE TAMPERED RECORD: MISMATCH
Read what just happened, because your domain must do the same:
- The canonical match is eight input facts folded through
duel-rules@1: energy-priced actions against a shared target. The honest score is 16 — read from the derivation by the driver, never hardcoded into the claim. The claim is then verified by collapsingverify-score@1withclaimedScoreas a collapse parameter: the parameter is part of the collapse's identity, bound into its content key. - The tampered record is the same match with one input altered (tick 3, vex
strikebecomesrest). Its run derives 10. The honest claim against it: REFUTED. And the honest run's manifest replayed against the tampered record: MISMATCH — so the MATCH above is not vacuous. - Records are append-only, so "tampering" here means founding a second record whose stream differs. In-process the twin reuses the same subject and moment (records are values; nothing deduplicates them). Over HTTP the same founding returns the same record instead — §5 shows the twin technique there.
Two design facts from this domain belong in your notebook before §4; both were findings when this domain was built against the contract:
- A domain whose draws fork from a committed data seed builds its own stream factory. The record layer's
ctx.rngForforks from the record's founding seed — a hash of subject + moment. Replay-verify's whole point is that the sim seed is a fact of the match, so it importscreateStreamFactoryfrom the core and forks from the founding fact'sseedfield:replay-verify|tick|<tick>|<actor>. Two records that commit the same founding and the same inputs derive the same run, whoever founded them. Fork fromctx.rngForinstead only if you intend the run to differ by founder — for verification shapes, you almost never do. - A ruleset pin lives in the founding fields, not in the recipe registry. The layer pins recipes (
final-state@1). A domain with several rulesets carries the ruleset as committed data that one recipe reads — and refuses, loudly, any pin it does not implement. Ruleset evolution is therefore a domain convention, not a layer mechanism: a new ruleset is a new pin in your founding schema's vocabulary, and old records still name the old pin.
← The surface in five calls — the chronicle record · Your own domain — the convoy template →