conformance: 97 rules of 9 verifiers, 206 vectors; verify-layer and agents refuse a classical key under an ML-DSA-65 name; market-settlement reads the notarization time from the certified read; proof-of-ai README in English

This commit is contained in:
Aere Network committed 2026-10-05 17:17:59 +03:00
1 parent c9f2932e04
commit c9798a0013
111 files changed
+15871 -292

No files matched your search

+40 -19
View File
@@ -5,7 +5,8 @@
// node proba-conformance.mjs [--online] [--acceptate] the suite is derived, whole, single-place, two implementations pass it,
// and malformed artifacts are refused by name (--acceptate lists what a
// verifier still accepts when damaged: the optional and the unread)
// node proba-conformance.mjs --control-negativ [--online] every rule planted out of its verifier, one at a time: the vectors that
// node proba-conformance.mjs --control-negativ [--online] [--doar <rule id prefix>]
// every rule planted out of its verifier, one at a time: the vectors that
// name the rule, and only they, must fail; plus the controls of the
// runner, of the coverage gate and of the rule derivation
// node proba-conformance.mjs --pe-loc a MEASUREMENT, not a gate: each check site planted out alone; how many
@@ -15,7 +16,7 @@
// vectors need the AIP-23 reference verifier (AERE_VERIFY_PROOF=<verify-proof.mjs>, with `npm install` done beside it); --online
// reads testnet 28001 (nothing is sent).
import fs from 'node:fs'; import os from 'node:os'; import path from 'node:path'; import { spawn, spawnSync } from 'node:child_process'; import { fileURLToPath, pathToFileURL } from 'node:url';
import { deriva, hartaPublica, VERIFICATOARE, MODULE, VERIFY_PROOF, FINALITY_SITES, incarca } from './reguli.mjs';
import { deriva, hartaPublica, VERIFICATOARE, MODULE, VERIFY_PROOF, FINALITY_SITES, incarca, marcajul } from './reguli.mjs';
import { incarcaVectorii, ruleazaSuita } from './conformance.mjs';
import { aplica, plicuriKinds } from './genereaza-vectori.mjs';
@@ -46,11 +47,12 @@ const numar = (s, st) => s.rezultate.filter((r) => r.stare === st);
// ---------- planting ----------
const PLANT = "|| String(1) === '1' /*PLANTAT*/";
/** exact-once plantings of the reference verifier (a published program without markers): rule -> [text, planted text] */
/** exact-once plantings of the reference verifier (a published program without markers): rule -> [text, planted text]. The rule is
* taken out whole: its level then passes whatever it is shown. */
const PLANT_VP = {
form: [".test(env.statementHash);", ".test(env.statementHash) || String(1) === '1';"],
integrity: ["const ok = h === env.statementHash.toLowerCase();", "const ok = h === env.statementHash.toLowerCase() || String(1) === '1';"],
signature: ["const ok = crypto.verify(null, Buffer.from(text, 'utf8'), pub, sig);", "const ok = crypto.verify(null, Buffer.from(text, 'utf8'), pub, sig) || String(1) === '1';"],
form: ["const formOk = obj(env) && obj(env.statement)", "const formOk = String(1) === '1' || obj(env) && obj(env.statement)"],
integrity: ["const ok = h === sh.toLowerCase();", "const ok = h === sh.toLowerCase() || String(1) === '1';"],
signature: [" const s = env.signature;\n", " const s = env.signature;\n if (String(1) === '1') return level('signature', 'PASSED', 'planted out');\n"],
finality: ["env.notarization ? 'FAILED' : 'ABSENT'", "(env.notarization && String(1) === '2') ? 'FAILED' : 'ABSENT'"],
};
/** Writes the planted copy of a rule's verifier beside the original; returns { copie, env } or { stricat }. `loc` plants one site only. */
@@ -60,9 +62,14 @@ function planteaza(verifier, sursa, loc = null) {
const src = fs.readFileSync(VERIFY_PROOF, 'utf8'); const [de, cu] = PLANT_VP[sursa] || []; const n = de ? src.split(de).length - 1 : 0;
if (n !== 1) return { stricat: `the planting anchor of ${sursa} appears ${n} times in the reference verifier` };
const copie = path.join(path.dirname(VERIFY_PROOF), `.plantat-conf-${process.pid}-${sursa}.mjs`); fs.writeFileSync(copie, src.replace(de, () => cu));
return { copie, env: { AERE_VERIFY_PROOF: copie } };
return { copie, env: { AERE_VERIFY_PROOF: copie, AERE_CONF_VERIFY_PROOF_DEP: VERIFY_PROOF } };
}
const p = fileURLToPath(MODULE[d.sursa].url); const src = fs.readFileSync(p, 'utf8'); const bucati = src.split(`/*PAZA:${sursa}*/`); const n = bucati.length - 1;
const p = fileURLToPath(MODULE[d.sursa].url); const src = fs.readFileSync(p, 'utf8'); const ap = marcajul(d.sursa);
if (ap) { // the rule is named where the verifier refuses: its one refusal helper, in the copy, drops the refusals of this rule
const text = ap.planteaza(src, sursa); if (text === null || loc !== null) return { stricat: loc !== null ? 'no single sites to plant' : 'the refusal helper is not where the planting expects it' };
const copie = path.join(path.dirname(p), `_plantat-conf-${process.pid}-${sursa}.mjs`); fs.writeFileSync(copie, text); return { copie, env: { [MODULE[d.sursa].env]: copie } };
}
const bucati = src.split(`/*PAZA:${sursa}*/`); const n = bucati.length - 1;
if (n < 1) return { stricat: `no /*PAZA:${sursa}*/ marker in ${path.basename(p)}` };
if (loc !== null && loc >= n) return { stricat: 'site ' + loc + ' of ' + n };
const text = loc === null ? bucati.join(PLANT) : bucati.map((b, i) => (i === bucati.length - 1 ? b : b + (i === loc ? PLANT : `/*PAZA:${sursa}*/`))).join('');
@@ -70,9 +77,9 @@ function planteaza(verifier, sursa, loc = null) {
return { copie, env: { [MODULE[d.sursa].env]: copie } };
}
/** the suite, run as a separate program (several plantings run side by side) */
function suitaAsync(env, { online: on = false, doar = null } = {}) {
function suitaAsync(env, { online: on = false, doar = null, artefacte = null } = {}) {
return new Promise((gata) => {
const args = [path.join(AICI, 'conformance.mjs'), '--impl', REF, '--json']; if (on) args.push('--online'); if (doar) args.push('--only', doar);
const args = [path.join(AICI, 'conformance.mjs'), '--impl', REF, '--json']; if (on) args.push('--online'); if (doar) args.push('--only', doar); if (artefacte) args.push('--artifacts', artefacte.join(','));
const c = spawn(process.execPath, args, { env: { ...process.env, ...env }, stdio: ['ignore', 'pipe', 'pipe'] }); let out = '', err = '';
c.stdout.on('data', (d) => { out += d; }); c.stderr.on('data', (d) => { err += d; });
c.on('close', () => { try { gata({ rezultate: JSON.parse(out).results }); } catch { gata({ eroare: (out + err).trim().split('\n').slice(-1)[0].slice(0, 200) }); } });
@@ -83,20 +90,26 @@ const ramase = () => [...Object.values(MODULE).map((m) => path.dirname(fileURLTo
/**
* Every path of every offline vector that is not INVALID, removed or replaced by null, a string, a number, a list, an object, and given
* to the module verifiers directly. Left out, and said: the policy (a policy that cannot be defined is refused by definePolicy by
* throwing, by design: nothing is judged under it) and the public task of a market job (each replay costs seconds).
* to the module verifiers directly. Left out, and said: the policy of a payment (a policy that cannot be defined is refused by
* definePolicy by throwing, by design: nothing is judged under it), the public task of a market job (each replay costs seconds), and
* the ai-trust bundle (its verifier runs the reference verifier, a program, several times per case).
* @returns {{ cazuri: number, aruncate: string[], acceptate: string[] }} acceptate = the paths (without array positions) whose damage was accepted
*/
async function malformate() {
const R = await incarca('risc'), C = await incarca('chitanta'), P = await incarca('piata'), B = await incarca('baza'); const clona = (x) => JSON.parse(JSON.stringify(x));
const R = await incarca('risc'), C = await incarca('chitanta'), P = await incarca('piata'), B = await incarca('baza'), SC = await incarca('sidecar'), AR = await incarca('arbore'), L = await incarca('ledger'); const clona = (x) => JSON.parse(JSON.stringify(x));
const J = { 'payment-risk': (i) => R.judeca(i.policy, i.inputs).decision === 'ALLOW', 'payment-receipt': (i) => C.verificaChitanta(i.receipt, { policy: i.policy, inputs: i.inputs, tx: i.tx, receipt: i.txReceipt }).verdict === 'VALID', 'market-timeline': (i) => P.judeca(i).verdict === 'VALID',
'dataset-record': (i) => B.verificaInregistrare(i.record, i.commitment).ok, 'dataset-answer': (i) => B.verificaRaspuns(i.answer, i.commitment).verdict === 'VALID', 'dataset-consistency': (i) => B.verificaConsistentaVersiuni(i.proof, i.older, i.newer).ok };
'dataset-record': (i) => B.verificaInregistrare(i.record, i.commitment).ok, 'dataset-answer': (i) => B.verificaRaspuns(i.answer, i.commitment).verdict === 'VALID', 'dataset-consistency': (i) => B.verificaConsistentaVersiuni(i.proof, i.older, i.newer).ok,
// the verifiers enrolled after the first four (2026-10-05), called the way the adapter calls them; ai-trust is not here: each case would run the reference verifier several times
'audit-log': (i) => (i.head !== undefined ? SC.verificaFataDeCap(i.log, i.head, { semnatar: i.signer || null }) : SC.verificaJurnal(i.log)).ok,
'audit-inclusion': (i) => AR.verificaIncludere(i.proof, { cap: i.head || null, semnatar: i.signer || null }).ok,
'audit-consistency': (i) => AR.verificaConsistenta(i.proof, { vechi: i.older, nou: i.newer, semnatar: i.signer || null }).ok,
'agent-ledger': (i) => { const o = { policy: i.policy, policyHash: i.policyHash, anchors: i.anchors || [], notBefore: i.notBefore === undefined ? null : i.notBefore, revocations: i.revocations || [] }; if (i.maxTime !== undefined) o.maxTime = i.maxTime; return L.verifyLedger(i.ledger, o).ok; } };
const cai = (x, p = []) => (x !== null && typeof x === 'object' ? [p, ...Object.keys(x).flatMap((k) => cai(x[k], [...p, Array.isArray(x) ? Number(k) : k]))] : [p]).filter((q) => q.length);
const VAL = [null, 'x', 7, [], {}]; let cazuri = 0; const aruncate = [], acceptate = [];
for (const v of vectori) {
if (!J[v.artifact] || v.expected.verdict === 'INVALID' || v.requires.length) continue;
const inp = clona(v.input); if (v.artifact === 'market-timeline') delete inp.spec;
for (const p of cai(inp)) { if (p[0] === 'policy') continue;
for (const p of cai(inp)) { if (p[0] === 'policy' && v.artifact.startsWith('payment-')) continue;
for (const op of ['remove', 0, 1, 2, 3, 4]) { const c = clona(inp); let o = c; for (const k of p.slice(0, -1)) o = o[k]; const k = p[p.length - 1];
if (op === 'remove') { if (Array.isArray(o)) o.splice(k, 1); else delete o[k]; } else { if (JSON.stringify(o[k]) === JSON.stringify(VAL[op])) continue; o[k] = clona(VAL[op]); }
cazuri++; try { if (J[v.artifact](c)) acceptate.push(v.artifact + ':' + p.filter((x) => typeof x !== 'number').join('.')); } catch (e) { aruncate.push(v.id + ' ' + p.join('.') + ' <- ' + (op === 'remove' ? 'removed' : JSON.stringify(VAL[op])) + ': ' + String(e.message).slice(0, 60)); } } }
@@ -158,10 +171,17 @@ if (!control && !peLoc) {
if (a.includes('--acceptate')) for (const c of cai) console.log(' ' + c); }
} else if (control) {
console.log('CONTROL: every rule planted out of its verifier, one at a time; the vectors that expect the rule, and only they, must fail');
const cazuri = []; for (const [v, d] of Object.entries(VERIFICATOARE)) for (const [src, [id]] of Object.entries(d.reguli)) cazuri.push({ v, src, id, online: id === 'envelope.finality' });
const deRulat = cazuri.filter((c) => !c.online || online); let bune = 0;
// Under a planting the suite runs the vectors of every artifact kind that can load the planted verifier (the kinds whose vectors
// exercise a rule of that verifier); the other kinds never load it: the adapter reaches a planted copy only through that verifier's
// own variable, and a verifier that another one imports is imported from its real file.
const atinse = (verif) => [...new Set(vectori.filter((x) => x.exercises.some((r) => HARTA[r] && HARTA[r].verifier === verif)).map((x) => x.artifact))];
// a rule whose vectors are ALL chain vectors can be controlled only with --online; with --online a rule that has chain vectors is run with them
const toate = []; for (const [v, d] of Object.entries(VERIFICATOARE)) for (const [src, [id]] of Object.entries(d.reguli)) { const ai = vectori.filter((x) => x.expected.failed.includes(id)); toate.push({ v, src, id, numaiOnline: ai.length > 0 && ai.every((x) => x.requires.length), online: online && ai.some((x) => x.requires.length) }); }
const filtru = a.includes('--doar') ? a[a.indexOf('--doar') + 1] : null; const cazuri = toate.filter((c) => !filtru || c.id.startsWith(filtru));
if (filtru) console.log(` (FILTERED: --doar ${filtru}: ${cazuri.length} of ${toate.length} rules; the others are NOT controlled by this run)`);
const deRulat = cazuri.filter((c) => !c.numaiOnline || online); let bune = 0;
try {
const rez = await inParalel(deRulat.map((c) => async () => { const p = planteaza(c.v, c.src); if (p.stricat) return { stricat: p.stricat }; try { return await suitaAsync(p.env, { online: c.online }); } finally { fs.rmSync(p.copie, { force: true }); } }));
const rez = await inParalel(deRulat.map((c) => async () => { const p = planteaza(c.v, c.src); if (p.stricat) return { stricat: p.stricat }; try { return await suitaAsync(p.env, { online: c.online, artefacte: atinse(c.v) }); } finally { fs.rmSync(p.copie, { force: true }); } }));
deRulat.forEach((c, k) => {
const r = rez[k]; const asteptate = cuRegula(c.id, vectori.filter((v) => c.online || !v.requires.length)).sort();
if (r.stricat || r.eroare) return rand('STRICAT', `${c.id}: ${r.stricat || r.eroare}`);
@@ -170,7 +190,8 @@ if (!control && !peLoc) {
rand(ok ? 'VERDE' : stricate.length ? 'STRICAT' : 'ROSU', `${c.id} planted out: ${cazute.length} vector(s) fail` + (ok ? `, exactly the ${asteptate.length} that expect it` : `; expected exactly [${asteptate.join(', ')}], failed [${cazute.join(', ')}]` + (stricate.length ? `, broken [${stricate.join(', ')}]` : '')));
});
} finally { for (const f of ramase()) fs.rmSync(f, { force: true }); }
for (const c of cazuri.filter((x) => x.online && !online)) rand('NEMASURAT', `${c.id}: its vectors need testnet 28001 (--online)`);
for (const c of cazuri.filter((x) => x.numaiOnline && !online)) rand('NEMASURAT', `${c.id}: its vectors need testnet 28001 (--online)`);
if (filtru) rand('NEMASURAT', `${toate.length - cazuri.length} rules left out by --doar`);
console.log('CONTROL of the instruments');
{ // the runner can fail: an implementation that calls everything VALID
const stub = path.join(fs.mkdtempSync(path.join(os.tmpdir(), 'aere-conf-stub-')), 'stub.mjs');