Source code / Node.js
Proof tests
The assertions behind the Constellation evidence dossier.
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import test from "node:test";
import { prove, verify, SAMPLE } from "../public/constellation-proof.ts";
test("published version-one vector remains verifiable", async () => {
const vector = JSON.parse(readFileSync(new URL("../public/proof-vector.json", import.meta.url), "utf8"));
assert.equal(await verify(vector, false), true);
});
test("independent verification binds both commitments and graph", async () => {
const proof = await prove(SAMPLE, false);
const transferred = JSON.parse(JSON.stringify(proof));
assert.deepEqual(Object.keys(transferred).sort(), ["extra", "transcript", "version"]);
assert.equal(await verify(transferred, false), true);
assert.equal(await verify(transferred, true), false);
const edited = await prove(SAMPLE, true);
assert.equal(await verify(edited, true), true);
assert.equal(await verify(edited, false), false);
const retagged = { ...proof, extra: true, transcript: proof.transcript + edited.transcript.slice(proof.transcript.length) };
assert.equal(await verify(retagged, true), false);
});
test("sealing one witness twice produces independent commitments", async () => {
const first = await prove(SAMPLE, false);
const second = await prove(SAMPLE, false);
// Six compressed points occupy 192 bytes or 256 base64url characters.
assert.notEqual(first.transcript.slice(0, 256), second.transcript.slice(0, 256));
const transplanted = { ...first, transcript: second.transcript.slice(0, 256) + first.transcript.slice(256) };
assert.equal(await verify(transplanted, false), false);
});
test("reject invalid witnesses, malformed proofs and modified responses", async () => {
await assert.rejects(prove([0, 0, 1, 0, 2, 1], false));
await assert.rejects(prove([3, 2, 1, 0, 2, 1], false));
await assert.rejects(prove(Array(6), false));
assert.equal(await verify(null, false), false);
const proof = await prove(SAMPLE, false);
assert.equal(await verify({ ...proof, version: 2 }, false), false);
assert.equal(await verify({ ...proof, transcript: "" }, false), false);
const payload = Buffer.from(proof.transcript, "base64url");
payload[224] ^= 1; // Low bit of the first Schnorr response.
assert.equal(await verify({ ...proof, transcript: payload.toString("base64url") }, false), false);
payload.fill(255, 192, 224); // First scalar exceeds group order.
assert.equal(await verify({ ...proof, transcript: payload.toString("base64url") }, false), false);
});