conformance: a conformance suite for the AIP-23 proof kinds (one verdict form over the published verifiers, 35 rules derived from code, 122 vectors, a runner for any implementation, a second verifier in Python); four defects it found in the published verifiers are fixed here: the market judge accepted a timeline with its submission event withheld, and three verifiers threw on malformed input instead of refusing by name
This commit is contained in:
1 parent
2c000478dc
commit
c9f2932e04
145 files changed
+17395
-104
No files matched your search
@@ -50,7 +50,7 @@ unit, in one function both sides use). A dataset appends; it never rewrites.
|
||||
## Probes
|
||||
|
||||
```
|
||||
AERE_VERIFY_PROOF=<verify-proof.mjs from aere-node> node proba-verifiable-data.mjs # 22 rows: honest answers VALID, nine forged ones INVALID
|
||||
AERE_VERIFY_PROOF=<verify-proof.mjs from aere-node> node proba-verifiable-data.mjs # 23 rows: honest answers VALID, ten forged or malformed ones INVALID
|
||||
# for their named reason, sampling on a local server
|
||||
AERE_VERIFY_PROOF=... node proba-verifiable-data.mjs --control-negativ # 5 plantings on a copy of baza.mjs; each must make its
|
||||
# forged fixture pass, which proves the check is load-bearing
|
||||
|
||||
+51
-39
@@ -23,6 +23,8 @@ import { leafHash, merkleTree, verifyInclusion, verifyConsistency } from '../ver
|
||||
import { buildProof } from '../proof-kinds/proof-kinds.mjs';
|
||||
|
||||
export const FORMAT = 'aere-verifiable-dataset-1';
|
||||
/** The rules the verifying side names. A refusal can only name one of these (the helper throws otherwise), so the list is the whole list. */
|
||||
export const REGULI = ['forma', 'angajament', 'camp', 'includere', 'index', 'interval', 'ordine', 'completitudine', 'consistenta', 'esantion'];
|
||||
export const KIND_RASPUNS = 'aere-verifiable-query-answer';
|
||||
export const KIND_INREGISTRARE = 'aere-verifiable-record';
|
||||
export const KIND_CONSISTENTA = 'aere-verifiable-consistency';
|
||||
@@ -173,73 +175,83 @@ export function auditeaza(db) {
|
||||
}
|
||||
|
||||
// ----- verification, without the data (what a reader runs on a commitment and an answer) -----
|
||||
const ok = (motive, cond, m) => { if (!cond) motive.push(m); return cond; };
|
||||
// every refusal NAMES its rule (forma, angajament, camp, includere, index, interval, ordine, completitudine, consistenta, esantion): the
|
||||
// rule ids travel on the motive list and come back as `reguli` in each verdict
|
||||
const ok = (motive, cond, m, regula) => { if (!REGULI.includes(regula)) throw new Error('baza: undeclared rule ' + regula); if (!cond) { motive.push(m); (motive.reguli || (motive.reguli = new Set())).add(regula); } return cond; };
|
||||
const reguliDin = (motive) => [...(motive.reguli || [])].sort();
|
||||
// the verifying side never throws on a malformed answer (2026-10-03: a row without its queried field, a null row, a neighbour without a
|
||||
// value used to throw; found by the conformance vectors): what the format cannot carry is a refusal by name, not a crash of the reader
|
||||
const sigur = (fn, ...a) => { try { return fn(...a); } catch { return null; } };
|
||||
const cmp = (a, b) => { try { return comparaValori(a, b); } catch { return NaN; } };
|
||||
const valoare = (r, f) => (r && r.disclosed && r.disclosed[f] != null ? r.disclosed[f].value : undefined);
|
||||
function verificaRand(r, commitment, field, motive, eticheta) {
|
||||
if (!r || typeof r !== 'object' || !r.c || typeof r.c !== 'object' || !r.disclosed) return ok(motive, false, eticheta + ': malformed row');
|
||||
const okForma = !!(r && typeof r === 'object' && r.c && typeof r.c === 'object' && r.disclosed) /*PAZA:forma*/;
|
||||
if (!ok(motive, okForma, eticheta + ': malformed row', 'forma')) return false;
|
||||
for (const [k, d] of Object.entries(r.disclosed)) {
|
||||
if (!d || typeof d.salt !== 'string') return ok(motive, false, eticheta + ': disclosed field ' + k + ' without a salt');
|
||||
const okCamp = r.c[k] === angajamentCamp(k, d.value, d.salt) /*PAZA:camp*/;
|
||||
if (!ok(motive, okCamp, eticheta + ': the disclosed value of "' + k + '" does not match its commitment')) return false;
|
||||
if (!ok(motive, !!(d && typeof d.salt === 'string') /*PAZA:camp*/, eticheta + ': disclosed field ' + k + ' without a salt', 'camp')) return false;
|
||||
const okCamp = r.c[k] === sigur(angajamentCamp, k, d.value, d.salt) /*PAZA:camp*/;
|
||||
if (!ok(motive, okCamp, eticheta + ': the disclosed value of "' + k + '" does not match its commitment', 'camp')) return false;
|
||||
}
|
||||
const leaf = frunzaInregistrare(r.id, r.c);
|
||||
if (!ok(motive, r.logProof && verifyInclusion({ ...r.logProof, leafHash: leaf, treeSize: commitment.size, rootHash: commitment.logRoot }) && r.logProof.index === r.i, eticheta + ': the record is not in the log of version ' + commitment.version)) return false;
|
||||
const leaf = sigur(frunzaInregistrare, r.id, r.c);
|
||||
if (!ok(motive, r.logProof && verifyInclusion({ ...r.logProof, leafHash: leaf, treeSize: commitment.size, rootHash: commitment.logRoot }) && r.logProof.index === r.i /*PAZA:includere*/, eticheta + ': the record is not in the log of version ' + commitment.version, 'includere')) return false;
|
||||
if (field !== null) {
|
||||
if (!ok(motive, r.disclosed[field] !== undefined, eticheta + ': the queried field "' + field + '" is not disclosed')) return false;
|
||||
if (!ok(motive, r.disclosed[field] !== undefined /*PAZA:index*/, eticheta + ': the queried field "' + field + '" is not disclosed', 'index')) return false;
|
||||
const ix = commitment.indexes[field];
|
||||
const okIndex = r.indexProof && verifyInclusion({ ...r.indexProof, leafHash: frunzaIndex(field, r.disclosed[field].value, r.i, leaf), treeSize: ix.size, rootHash: ix.root }) && r.indexProof.index === r.pos;
|
||||
if (!ok(motive, okIndex, eticheta + ': the row is not at position ' + r.pos + ' of the index "' + field + '"')) return false;
|
||||
const okIndex = r.indexProof && verifyInclusion({ ...r.indexProof, leafHash: sigur(frunzaIndex, field, valoare(r, field), r.i, leaf), treeSize: ix.size, rootHash: ix.root }) && r.indexProof.index === r.pos /*PAZA:index*/;
|
||||
if (!ok(motive, okIndex, eticheta + ': the row is not at position ' + r.pos + ' of the index "' + field + '"', 'index')) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/** A query answer against a commitment: every row proves itself, the rows are the whole contiguous run, the neighbours are outside. */
|
||||
export function verificaRaspuns(answer, commitment) {
|
||||
const motive = [];
|
||||
if (!answer || answer.kind !== KIND_RASPUNS || !commitment) return { verdict: 'INVALID', motive: ['not a ' + KIND_RASPUNS], rows: 0 };
|
||||
ok(motive, answer.commitmentHash === hashAngajament(commitment) && answer.version === commitment.version && answer.name === commitment.name, 'the answer names another commitment');
|
||||
if (!answer || answer.kind !== KIND_RASPUNS || !commitment) return { verdict: 'INVALID', motive: ['not a ' + KIND_RASPUNS], reguli: ['forma'], rows: 0 };
|
||||
ok(motive, answer.commitmentHash === hashAngajament(commitment) && answer.version === commitment.version && answer.name === commitment.name /*PAZA:angajament*/, 'the answer names another commitment', 'angajament');
|
||||
const f = answer.field; const ix = commitment.indexes && commitment.indexes[f];
|
||||
if (!ok(motive, !!ix, 'the field "' + f + '" is not indexed in the commitment')) return { verdict: 'INVALID', motive, rows: 0 };
|
||||
ok(motive, answer.indexSize === ix.size, 'the answer\'s index size differs from the commitment\'s');
|
||||
if (!ok(motive, !!ix, 'the field "' + f + '" is not indexed in the commitment', 'angajament')) return { verdict: 'INVALID', motive, reguli: reguliDin(motive), rows: 0 };
|
||||
ok(motive, answer.indexSize === ix.size /*PAZA:angajament*/, 'the answer\'s index size differs from the commitment\'s', 'angajament');
|
||||
const from = answer.from, to = answer.to; const rows = Array.isArray(answer.rows) ? answer.rows : [];
|
||||
if (from !== null && to !== null) ok(motive, comparaValori(from, to) <= 0, 'from is above to');
|
||||
const inRange = (v) => (from === null || comparaValori(v, from) >= 0) && (to === null || comparaValori(v, to) <= 0);
|
||||
let start = rows.length ? rows[0].pos : (answer.before ? answer.before.pos + 1 : 0);
|
||||
if (from !== null && to !== null) ok(motive, cmp(from, to) <= 0 /*PAZA:interval*/, 'from is above to', 'interval');
|
||||
const inRange = (v) => (from === null || cmp(v, from) >= 0) && (to === null || cmp(v, to) <= 0);
|
||||
let start = rows.length ? (rows[0] && typeof rows[0] === 'object' ? rows[0].pos : null) : (answer.before ? answer.before.pos + 1 : 0);
|
||||
const dovedit = []; // a row that did not prove itself is already refused by name; it is not compared with its neighbour
|
||||
for (const [k, r] of rows.entries()) {
|
||||
if (!verificaRand(r, commitment, f, motive, 'row ' + k)) continue;
|
||||
ok(motive, r.pos === start + k, 'row ' + k + ' breaks the contiguous run of the index');
|
||||
ok(motive, inRange(r.disclosed[f].value), 'row ' + k + ' is outside the queried range');
|
||||
if (k) { const okOrdine = comparaValori(rows[k - 1].disclosed[f].value, r.disclosed[f].value) < 0 || (comparaValori(rows[k - 1].disclosed[f].value, r.disclosed[f].value) === 0 && rows[k - 1].i < r.i) /*PAZA:ordine*/; ok(motive, okOrdine, 'rows ' + (k - 1) + ' and ' + k + ' are not in index order'); }
|
||||
dovedit[k] = verificaRand(r, commitment, f, motive, 'row ' + k); if (!dovedit[k]) continue;
|
||||
ok(motive, r.pos === start + k /*PAZA:completitudine*/, 'row ' + k + ' breaks the contiguous run of the index', 'completitudine');
|
||||
ok(motive, inRange(valoare(r, f)) /*PAZA:interval*/, 'row ' + k + ' is outside the queried range', 'interval');
|
||||
if (k && dovedit[k - 1]) { const okOrdine = cmp(valoare(rows[k - 1], f), valoare(r, f)) < 0 || (cmp(valoare(rows[k - 1], f), valoare(r, f)) === 0 && rows[k - 1].i < r.i) /*PAZA:ordine*/; ok(motive, okOrdine, 'rows ' + (k - 1) + ' and ' + k + ' are not in index order', 'ordine'); }
|
||||
}
|
||||
const end = start + rows.length;
|
||||
const vecin = (n, pos, cond, m) => {
|
||||
if (!n) return ok(motive, cond, m);
|
||||
const okVecin = n.pos === pos && n.indexProof && verifyInclusion({ ...n.indexProof, leafHash: frunzaIndex(f, n.value, n.i, n.recordLeaf), treeSize: ix.size, rootHash: ix.root }) && n.indexProof.index === pos;
|
||||
return ok(motive, okVecin, 'the neighbour at position ' + pos + ' does not prove itself in the index');
|
||||
if (!n) return ok(motive, cond /*PAZA:completitudine*/, m, 'completitudine');
|
||||
const okVecin = n.pos === pos && n.indexProof && verifyInclusion({ ...n.indexProof, leafHash: sigur(frunzaIndex, f, n.value, n.i, n.recordLeaf), treeSize: ix.size, rootHash: ix.root }) && n.indexProof.index === pos /*PAZA:completitudine*/;
|
||||
return ok(motive, okVecin, 'the neighbour at position ' + pos + ' does not prove itself in the index', 'completitudine');
|
||||
};
|
||||
// completeness: the row before the run is below the range (or the run starts at 0), the row after is above it (or the run ends the index)
|
||||
const okInainte = vecin(answer.before, start - 1, start === 0, 'the run does not start at 0 and no neighbour before it is shown') && (!answer.before || (from !== null && comparaValori(answer.before.value, from) < 0)) /*PAZA:completitudine*/;
|
||||
ok(motive, okInainte, 'a row before the run could still be in the range (the answer may be incomplete)');
|
||||
const okDupa = vecin(answer.after, end, end === ix.size, 'the run does not end the index and no neighbour after it is shown') && (!answer.after || (to !== null && comparaValori(answer.after.value, to) > 0)) /*PAZA:completitudine*/;
|
||||
ok(motive, okDupa, 'a row after the run could still be in the range (the answer may be incomplete)');
|
||||
return { verdict: motive.length ? 'INVALID' : 'VALID', motive, rows: rows.length };
|
||||
const okInainte = vecin(answer.before, start - 1, start === 0, 'the run does not start at 0 and no neighbour before it is shown') && (!answer.before || (from !== null && cmp(answer.before.value, from) < 0)) /*PAZA:completitudine*/;
|
||||
ok(motive, okInainte, 'a row before the run could still be in the range (the answer may be incomplete)', 'completitudine');
|
||||
const okDupa = vecin(answer.after, end, end === ix.size, 'the run does not end the index and no neighbour after it is shown') && (!answer.after || (to !== null && cmp(answer.after.value, to) > 0)) /*PAZA:completitudine*/;
|
||||
ok(motive, okDupa, 'a row after the run could still be in the range (the answer may be incomplete)', 'completitudine');
|
||||
return { verdict: motive.length ? 'INVALID' : 'VALID', motive, reguli: reguliDin(motive), rows: rows.length };
|
||||
}
|
||||
/** One record (from `dovadaInregistrare` or the serving endpoint) against a commitment. */
|
||||
export function verificaInregistrare(rec, commitment) {
|
||||
const motive = [];
|
||||
if (!rec || rec.kind !== KIND_INREGISTRARE) return { ok: false, motive: ['not a ' + KIND_INREGISTRARE] };
|
||||
ok(motive, rec.commitmentHash === hashAngajament(commitment) && rec.version === commitment.version, 'the record names another commitment');
|
||||
if (!rec || rec.kind !== KIND_INREGISTRARE || !commitment) return { ok: false, motive: ['not a ' + KIND_INREGISTRARE + ' with its commitment'], reguli: ['forma'] };
|
||||
ok(motive, rec.commitmentHash === hashAngajament(commitment) && rec.version === commitment.version /*PAZA:angajament*/, 'the record names another commitment', 'angajament');
|
||||
verificaRand(rec, commitment, null, motive, 'record ' + rec.i);
|
||||
return { ok: motive.length === 0, motive };
|
||||
return { ok: motive.length === 0, motive, reguli: reguliDin(motive) };
|
||||
}
|
||||
/** A consistency proof between two commitments: the older log is a prefix of the newer (nothing rewritten, nothing removed). */
|
||||
export function verificaConsistentaVersiuni(d, older, newer) {
|
||||
const motive = [];
|
||||
if (!d || d.kind !== KIND_CONSISTENTA || !d.proof) return { ok: false, motive: ['not a ' + KIND_CONSISTENTA] };
|
||||
ok(motive, d.from.commitmentHash === hashAngajament(older) && d.to.commitmentHash === hashAngajament(newer), 'the proof names other commitments');
|
||||
if (!d || d.kind !== KIND_CONSISTENTA || !d.proof || !d.from || !d.to || !older || !newer) return { ok: false, motive: ['not a ' + KIND_CONSISTENTA + ' with its two commitments'], reguli: ['forma'] };
|
||||
ok(motive, d.from.commitmentHash === hashAngajament(older) && d.to.commitmentHash === hashAngajament(newer) /*PAZA:angajament*/, 'the proof names other commitments', 'angajament');
|
||||
const okRadacini = d.proof.firstRoot === older.logRoot && d.proof.secondRoot === newer.logRoot && d.proof.firstSize === older.size && d.proof.secondSize === newer.size /*PAZA:consistenta*/;
|
||||
ok(motive, okRadacini, 'the proof\'s roots or sizes are not the commitments\'');
|
||||
ok(motive, verifyConsistency(d.proof), 'the older log is not a prefix of the newer (rewritten history)');
|
||||
ok(motive, newer.previous === hashAngajament(older) || newer.version !== older.version + 1, 'the newer version does not name the older as previous');
|
||||
return { ok: motive.length === 0, motive };
|
||||
ok(motive, okRadacini, 'the proof\'s roots or sizes are not the commitments\'', 'consistenta');
|
||||
ok(motive, verifyConsistency(d.proof) /*PAZA:consistenta*/, 'the older log is not a prefix of the newer (rewritten history)', 'consistenta');
|
||||
ok(motive, (newer.previous === hashAngajament(older) || newer.version !== older.version + 1) /*PAZA:consistenta*/, 'the newer version does not name the older as previous', 'consistenta');
|
||||
return { ok: motive.length === 0, motive, reguli: reguliDin(motive) };
|
||||
}
|
||||
/**
|
||||
* Availability sampling: k record positions drawn from a seed (random when none; the seed is printed so the draw can be repeated), each
|
||||
@@ -260,7 +272,7 @@ export async function esantioneaza({ url, commitment, k = 16, seed = null, ia })
|
||||
}
|
||||
const okEsantion = lipsa.length === 0 && verificate === cerute /*PAZA:esantion*/;
|
||||
if (lipsa.length) motive.push('not served: ' + lipsa.join(', '));
|
||||
return { ok: okEsantion, seed: s, cerute, verificate, lipsa, motive };
|
||||
return { ok: okEsantion, reguli: okEsantion ? [] : ['esantion'], seed: s, cerute, verificate, lipsa, motive };
|
||||
}
|
||||
/** The AIP-23 `data` envelope of a commitment: sha256 = SHA-256 of the canonical commitment, name = dataset@version. */
|
||||
export function plicAngajament(commitment, { createdAt = commitment.createdAt } = {}) {
|
||||
|
||||
@@ -81,6 +81,9 @@ export async function fixturi(B, { dir, server }) {
|
||||
const q = { v: 1, kind: B.KIND_RASPUNS, name: 'nesortat', version: 1, commitmentHash: B.hashAngajament(c), field: 'k', from: 'a', to: 'b', indexSize: 2, rows: [rand(0), rand(1)], before: null, after: null };
|
||||
const x = B.verificaRaspuns(q, c); return { verdict: x.verdict, detail: x.motive.join('; ') }; } });
|
||||
F.push({ nume: 'N9 a record whose log proof points at another position', asteptat: 'INVALID', r: () => { const d = B.dovadaInregistrare(db, 2, 5); d.i = 6; d.logProof.index = 6; const x = B.verificaInregistrare(d, c2); return { verdict: x.ok ? 'VALID' : 'INVALID', detail: x.motive.join('; ') }; } });
|
||||
F.push({ nume: 'N10 malformed answers (a row without the queried field, a null row, a neighbour without a value, rows not a list) are refused by name, never thrown', asteptat: 'INVALID', r: () => {
|
||||
const rez = [(q) => { delete q.rows[1].disclosed.varsta; }, (q) => { q.rows[1] = null; }, (q) => { q.rows[0] = null; }, (q) => { delete q.before.value; }, (q) => { q.rows = 'x'; }].map((f) => { const q = B.interogheaza(db, 2, { field: 'varsta', from: 30, to: 40 }); f(q); const x = B.verificaRaspuns(q, c2); return x.verdict + ':' + x.reguli.length; });
|
||||
return { verdict: rez.every((x) => /^INVALID:[1-9]/.test(x)) ? 'INVALID' : 'VALID', detail: rez.join(' ') }; } });
|
||||
// availability sampling against the local server
|
||||
const ia = async (u) => { const r = await fetch(u, { signal: AbortSignal.timeout(10000) }); if (!r.ok) return null; return r.json(); };
|
||||
F.push({ nume: 'A1 availability sampling, 32 records drawn from a seed, all served and verified', asteptat: 'VALID', r: async () => { const x = await B.esantioneaza({ url: server.url, commitment: c2, k: 32, seed: 'proba-a1', ia }); return { verdict: x.ok ? 'VALID' : 'INVALID', detail: `${x.verificate}/${x.cerute}; ${x.motive.join('; ')}` }; } });
|
||||
|
||||
Reference in new issue
Block a user