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:
Aere Network committed 2026-10-03 13:26:03 +03:00
1 parent 2c000478dc
commit c9f2932e04
145 files changed
+17395 -104

No files matched your search

+5 -2
View File
@@ -22,11 +22,14 @@ state and every event with its block time and sender, and `judeca` is a pure fun
the deadline, dispute strictly inside the window, finalize only after it (unless the requester accepts early), resolution only by the
arbiter or after `ARBITRATION_TIMEOUT`, the terminal payout matching the state, the result bytes hashing to the commitment, the replay of
the public spec agreeing with whoever won, and the notarized envelope naming this job's spec and result before the window closed.
Every refusal names its rule (`reguli`). A timeline the judge cannot read is refused by name, not thrown, and so is one that lacks an
event the job state implies: a timeline with its submission event withheld used to skip the window rule and come out VALID (found by
the conformance suite on 2026-10-03, `conformance/`).
```
AERE_TESTNET_KEY_FILE=<key> AERE_ETHERS_DIR=<dir with node_modules/ethers> node proba-piata-28001.mjs # the flow on 28001 (five scenarios)
node proba-judecata.mjs # the judge on the recorded timelines: 5 honest VALID, 10 forged INVALID, the receipt
node proba-judecata.mjs --control-negativ # 7 plantings on a copy of piata.mjs; each forged fixture must then be accepted
node proba-judecata.mjs # the judge on the recorded timelines: 5 honest VALID, 15 forged or malformed INVALID, the receipt
node proba-judecata.mjs --control-negativ # 10 plantings on a copy of piata.mjs; each forged fixture must then be accepted
node extrage-artefact.mjs # regenerate AereComputeMarketV3.json from the contracts build (refuses a changed source)
```
+39 -23
View File
@@ -21,6 +21,8 @@ import { ruleaza, rezultatHash, rezultatOcteti, specHash as specHashOf, keccak,
const AICI = path.dirname(fileURLToPath(import.meta.url));
export const ARTEFACT = path.join(AICI, 'AereComputeMarketV3.json');
export const STATUS = ['None', 'Open', 'Claimed', 'Submitted', 'Disputed', 'Paid', 'Refunded', 'Slashed'];
/** The rules the judge names. A refusal can only name one of these (the helper throws otherwise), so the list is the whole list. */
export const REGULI = ['forma', 'intreg', 'postare', 'termen', 'fereastra', 'arbitru', 'plata', 'rezultat', 'replay', 'dovada'];
export const MODE = ['REPLAY', 'ZK_VERIFIED', 'OPTIMISTIC'];
const H32 = /^0x[0-9a-f]{64}$/i;
const sha256 = (b) => '0x' + crypto.createHash('sha256').update(b).digest('hex');
@@ -83,51 +85,65 @@ export async function cronologie({ ethers, provider, market, artifact, jobId, fr
const ok = (m, cond, text) => { if (!cond) m.push(text); return !!cond; };
const low = (x) => String(x || '').toLowerCase();
export function judeca(d) {
const motive = [], randuri = []; const j = d.job, ev = d.events || []; const un = (n) => ev.find((e) => e.name === n); const toate = (n) => ev.filter((e) => e.name === n);
// a timeline the judge cannot read is refused by name, never thrown at the caller (2026-10-03: until today a missing field threw)
try { return judecaForma(d); } catch (e) { return { verdict: 'INVALID', motive: ['malformed timeline: ' + String(e.message).slice(0, 120)], reguli: ['forma'], randuri: [] }; }
}
function judecaForma(d) {
const motive = [], randuri = [], reguli = new Set(); const cere = (cond, text, regula) => { if (!REGULI.includes(regula)) throw new Error('piata: undeclared rule ' + regula); if (!cond) { motive.push(text); reguli.add(regula); } return !!cond; };
const j = d.job, ev = d.events || []; const un = (n) => ev.find((e) => e.name === n); const toate = (n) => ev.filter((e) => e.name === n);
const t = (e) => (e ? e.timestamp : null);
if (!j || !ev.length) return { verdict: 'INCOMPLETE', motive: ['no job or no events'], randuri };
if (!j || !ev.length) return { verdict: 'INCOMPLETE', motive: ['no job or no events'], reguli: [], randuri };
const intregi = (...x) => x.every(Number.isInteger);
const okForma = typeof j === 'object' && Array.isArray(ev) && ev.every((e) => e && typeof e === 'object' && typeof e.name === 'string' && e.args && typeof e.args === 'object' && typeof e.from === 'string' && intregi(e.timestamp, e.blockNumber))
&& !!d.constants && typeof d.constants.arbiter === 'string' && intregi(d.constants.arbitrationTimeout, j.deadline, j.submittedAt, j.challengeWindow, j.status) && (d.result == null || typeof d.result === 'string') /*PAZA:forma*/;
if (!cere(okForma, 'malformed timeline: events need name, args, from, integer timestamp and blockNumber; the job and the constants their integer fields', 'forma')) return { verdict: 'INVALID', motive, reguli: [...reguli].sort(), randuri };
for (const e of ev) randuri.push(`${new Date(e.timestamp * 1000).toISOString()} #${e.blockNumber} ${e.name} by ${e.from.slice(0, 10)}.. ${Object.entries(e.args).filter(([k]) => k !== 'result').map(([k, v]) => k + '=' + (H32.test(String(v)) ? String(v).slice(0, 10) + '..' : String(v).length > 20 ? String(v).slice(0, 10) + '..' : v)).join(' ')}`);
const posted = un('JobPosted'), claimed = un('JobClaimed'), submitted = un('ResultSubmitted') || un('ResultReferenced'), disputed = un('JobDisputed'), resolved = un('DisputeResolved'), timedOut = un('DisputeTimedOut'), paid = un('JobPaid'), refunded = un('JobRefunded'), slashed = un('JobSlashed');
// the timeline is WHOLE against the job state: an event the state implies cannot be withheld (2026-10-03: until today a timeline
// without its ResultSubmitted event skipped the challenge-window rule and came out VALID; found by the conformance suite)
const okIntreg = !!posted && (!j.provider || /^0x0{40}$/.test(String(j.provider)) || !!claimed) && (!(j.submittedAt > 0) || !!submitted) && (!(j.disputedAt > 0) || !!disputed) /*PAZA:intreg*/;
cere(okIntreg, 'the timeline lacks an event the job state implies (JobPosted; JobClaimed when a provider is set; the submission when submittedAt is set; JobDisputed when disputedAt is set)', 'intreg');
if (!posted) return { verdict: 'INVALID', motive, reguli: [...reguli].sort(), randuri };
// R0 the posting matches the job (the reward is compared through the payout events: the contract zeroes j.reward on settlement)
ok(motive, posted && low(posted.args.requester) === low(j.requester) && low(posted.args.specHash) === low(j.specHash) && Number(posted.args.deadline) === j.deadline && (j.reward === '0' || posted.args.reward === j.reward), 'the JobPosted event does not match the job (requester, reward, specHash, deadline)');
cere(posted && low(posted.args.requester) === low(j.requester) && low(posted.args.specHash) === low(j.specHash) && Number(posted.args.deadline) === j.deadline && (j.reward === '0' || posted.args.reward === j.reward) /*PAZA:postare*/, 'the JobPosted event does not match the job (requester, reward, specHash, deadline)', 'postare');
// R1 deadlines: a claim and a submission only up to the deadline
if (claimed) ok(motive, t(claimed) <= j.deadline /*PAZA:termen*/, 'the job was claimed after its deadline');
if (submitted) ok(motive, t(submitted) <= j.deadline && t(submitted) === j.submittedAt /*PAZA:termen*/, 'the result was submitted after the deadline, or submittedAt does not match the event');
if (refunded && claimed && !submitted && !disputed) ok(motive, t(refunded) > j.deadline /*PAZA:termen*/, 'the escrow was reclaimed as expired before the deadline');
if (claimed) cere(t(claimed) <= j.deadline /*PAZA:termen*/, 'the job was claimed after its deadline', 'termen');
if (submitted) cere(t(submitted) <= j.deadline && t(submitted) === j.submittedAt /*PAZA:termen*/, 'the result was submitted after the deadline, or submittedAt does not match the event', 'termen');
if (refunded && claimed && !submitted && !disputed) cere(t(refunded) > j.deadline /*PAZA:termen*/, 'the escrow was reclaimed as expired before the deadline', 'termen');
// R2 the challenge window: a dispute strictly inside it, a finalize (by anyone but the requester) only after it
if (disputed) ok(motive, submitted && t(disputed) < j.submittedAt + j.challengeWindow /*PAZA:fereastra*/, 'the dispute was raised after the challenge window closed');
if (paid && !resolved && submitted) ok(motive, low(paid.from) === low(j.requester) || t(paid) >= j.submittedAt + j.challengeWindow /*PAZA:fereastra*/, 'the provider was paid inside the challenge window by someone other than the requester (acceptResult is the requester\'s)');
if (disputed) cere(submitted && t(disputed) < j.submittedAt + j.challengeWindow /*PAZA:fereastra*/, 'the dispute was raised after the challenge window closed', 'fereastra');
if (paid && !resolved && submitted) cere(low(paid.from) === low(j.requester) || t(paid) >= j.submittedAt + j.challengeWindow /*PAZA:fereastra*/, 'the provider was paid inside the challenge window by someone other than the requester (acceptResult is the requester\'s)', 'fereastra');
// R3 who resolved: the arbiter, or the permissionless timeout after ARBITRATION_TIMEOUT
if (resolved) ok(motive, low(resolved.from) === low(d.constants.arbiter) /*PAZA:arbitru*/, 'the dispute was resolved by an address that is not the ARBITER');
if (timedOut) ok(motive, disputed && t(timedOut) >= j.disputedAt + d.constants.arbitrationTimeout /*PAZA:arbitru*/, 'the dispute was timed out before ARBITRATION_TIMEOUT');
if (resolved || timedOut) ok(motive, !!disputed, 'a resolution without a dispute');
if (resolved) cere(low(resolved.from) === low(d.constants.arbiter) /*PAZA:arbitru*/, 'the dispute was resolved by an address that is not the ARBITER', 'arbitru');
if (timedOut) cere(disputed && t(timedOut) >= j.disputedAt + d.constants.arbitrationTimeout /*PAZA:arbitru*/, 'the dispute was timed out before ARBITRATION_TIMEOUT', 'arbitru');
if (resolved || timedOut) cere(!!disputed /*PAZA:arbitru*/, 'a resolution without a dispute', 'arbitru');
// R4 the terminal payout matches the state
const st = STATUS[j.status]; let terminal = null;
if (st === 'Paid') { const okP = paid && low(paid.args.provider) === low(j.provider) && paid.args.reward === posted.args.reward && (!claimed || paid.args.bondReturned === claimed.args.providerBond) && (!resolved || resolved.args.providerWon === true) /*PAZA:plata*/; ok(motive, okP, 'status Paid without a matching JobPaid (provider, reward, bond returned, providerWon)'); terminal = paid && { status: st, payee: paid.args.provider, amount: paid.args.reward, txHash: paid.txHash, blockHash: paid.blockHash }; }
else if (st === 'Slashed') { const okS = slashed && disputed && resolved && resolved.args.providerWon === false && low(slashed.args.challenger) === low(disputed.args.challenger) && (!claimed || slashed.args.slashedProviderBond === claimed.args.providerBond) /*PAZA:plata*/; ok(motive, okS, 'status Slashed without a matching JobSlashed (challenger, provider bond) and DisputeResolved(false)'); terminal = slashed && { status: st, payee: slashed.args.challenger, amount: slashed.args.slashedProviderBond, refundedTo: j.requester, txHash: slashed.txHash, blockHash: slashed.blockHash }; }
else if (st === 'Refunded') { const okR = refunded && low(refunded.args.requester) === low(j.requester) && refunded.args.reward === posted.args.reward /*PAZA:plata*/; ok(motive, okR, 'status Refunded without a matching JobRefunded (requester, reward)'); terminal = refunded && { status: st, payee: refunded.args.requester, amount: refunded.args.reward, txHash: refunded.txHash, blockHash: refunded.blockHash }; }
ok(motive, j.status !== 5 || j.reward === '0', 'a paid job still holds a reward');
if (st === 'Paid') { const okP = paid && low(paid.args.provider) === low(j.provider) && paid.args.reward === posted.args.reward && (!claimed || paid.args.bondReturned === claimed.args.providerBond) && (!resolved || resolved.args.providerWon === true) /*PAZA:plata*/; cere(okP, 'status Paid without a matching JobPaid (provider, reward, bond returned, providerWon)', 'plata'); terminal = paid && { status: st, payee: paid.args.provider, amount: paid.args.reward, txHash: paid.txHash, blockHash: paid.blockHash }; }
else if (st === 'Slashed') { const okS = slashed && disputed && resolved && resolved.args.providerWon === false && low(slashed.args.challenger) === low(disputed.args.challenger) && (!claimed || slashed.args.slashedProviderBond === claimed.args.providerBond) /*PAZA:plata*/; cere(okS, 'status Slashed without a matching JobSlashed (challenger, provider bond) and DisputeResolved(false)', 'plata'); terminal = slashed && { status: st, payee: slashed.args.challenger, amount: slashed.args.slashedProviderBond, refundedTo: j.requester, txHash: slashed.txHash, blockHash: slashed.blockHash }; }
else if (st === 'Refunded') { const okR = refunded && low(refunded.args.requester) === low(j.requester) && refunded.args.reward === posted.args.reward /*PAZA:plata*/; cere(okR, 'status Refunded without a matching JobRefunded (requester, reward)', 'plata'); terminal = refunded && { status: st, payee: refunded.args.requester, amount: refunded.args.reward, txHash: refunded.txHash, blockHash: refunded.blockHash }; }
cere((j.status !== 5 || j.reward === '0') /*PAZA:plata*/, 'a paid job still holds a reward', 'plata');
// R5 the result bytes hash to the on-chain commitment
if (d.result && submitted) ok(motive, keccak(Buffer.from(d.result.slice(2), 'hex')) === low(j.resultHash) && low(submitted.args.resultHash) === low(j.resultHash) /*PAZA:rezultat*/, 'the submitted bytes do not hash to the job\'s resultHash');
if (d.result && submitted) cere(keccak(Buffer.from(d.result.slice(2), 'hex')) === low(j.resultHash) && low(submitted.args.resultHash) === low(j.resultHash) /*PAZA:rezultat*/, 'the submitted bytes do not hash to the job\'s resultHash', 'rezultat');
// R6 REPLAY: the public spec recomputed; the arbiter's decision must agree with the recomputation
let replay = null;
if (d.spec && d.result && submitted) {
ok(motive, specHashOf(d.spec) === low(j.specHash), 'the public spec does not hash to the job\'s specHash');
cere(specHashOf(d.spec) === low(j.specHash) /*PAZA:replay*/, 'the public spec does not hash to the job\'s specHash', 'replay');
try { const r = ruleaza(d.spec); const corect = rezultatHash(r) === low(j.resultHash); replay = { recomputedHash: rezultatHash(r), providerRight: corect };
if (disputed) { replay.challengerRecomputedRight = low(disputed.args.recomputedResultHash) === rezultatHash(r); }
if (resolved) ok(motive, resolved.args.providerWon === corect /*PAZA:replay*/, `the arbiter sided with the ${resolved.args.providerWon ? 'provider' : 'challenger'} but the replay says the provider is ${corect ? 'right' : 'wrong'}`);
if (st === 'Paid' && !resolved) ok(motive, corect /*PAZA:replay*/, 'the provider was paid for a result the replay does not reproduce (no one disputed in time)');
} catch (e) { motive.push('the replay could not run: ' + e.message); }
if (resolved) cere(resolved.args.providerWon === corect /*PAZA:replay*/, `the arbiter sided with the ${resolved.args.providerWon ? 'provider' : 'challenger'} but the replay says the provider is ${corect ? 'right' : 'wrong'}`, 'replay');
if (st === 'Paid' && !resolved) cere(corect /*PAZA:replay*/, 'the provider was paid for a result the replay does not reproduce (no one disputed in time)', 'replay');
} catch (e) { cere(false, 'the replay could not run: ' + e.message, 'replay'); }
}
// R7 the provider's envelope names this result and existed before the window closed
if (d.envelope) {
const e = d.envelope, stmt = e.statement || {};
const okE = e.kind === 'aere-proof-of-execution-attestation' && low(stmt.outputHash) === low(j.resultHash) && low(stmt.inputHash) === low(j.specHash) && sha256(Buffer.from(JSON.stringify(stmt), 'utf8')) === low(e.statementHash) /*PAZA:dovada*/;
ok(motive, okE, 'the execution envelope does not name this job\'s specHash/resultHash, or its statementHash is not its statement\'s');
if (e.notarization && submitted) ok(motive, Number(e.notarization.firstSeen) <= j.submittedAt + j.challengeWindow /*PAZA:dovada*/, 'the envelope was notarized only after the challenge window closed');
cere(okE, 'the execution envelope does not name this job\'s specHash/resultHash, or its statementHash is not its statement\'s', 'dovada');
if (e.notarization && submitted) cere(Number(e.notarization.firstSeen) <= j.submittedAt + j.challengeWindow /*PAZA:dovada*/, 'the envelope was notarized only after the challenge window closed', 'dovada');
}
const terminalStatus = ['Paid', 'Refunded', 'Slashed'].includes(st);
return { verdict: motive.length ? 'INVALID' : terminalStatus ? 'VALID' : 'INCOMPLETE', motive, randuri, status: st, terminal, replay };
return { verdict: motive.length ? 'INVALID' : terminalStatus ? 'VALID' : 'INCOMPLETE', motive, reguli: [...reguli].sort(), randuri, status: st, terminal, replay };
}
/** The AIP-23 settlement receipt of a terminal job: the payout transaction, the parties, the amount, the instruction (market, job, status). */
export function chitanta(d, { createdAt = new Date().toISOString() } = {}) {
+6 -1
View File
@@ -34,6 +34,11 @@ export function fixturi(P) {
F.push({ nume: 'N8 S1 the envelope names another result (outputHash changed, statementHash kept)', asteptat: 'INVALID', paza: 'dovada', r: () => { const d = date('S1'); d.envelope.statement.outputHash = '0x' + 'cc'.repeat(32); return v(P.judeca(d)); } });
F.push({ nume: 'N9 S1 the envelope notarized only after the window closed', asteptat: 'INVALID', paza: 'dovada', r: () => { const d = date('S1'); d.envelope.notarization.firstSeen = d.job.submittedAt + d.job.challengeWindow + 1; return v(P.judeca(d)); } });
F.push({ nume: 'N10 S4 reclaimed as expired BEFORE the deadline', asteptat: 'INVALID', paza: 'termen', r: () => { const d = date('S4'); ev(d, 'JobRefunded').timestamp = d.job.deadline - 1; return v(P.judeca(d)); } });
F.push({ nume: 'N11 S2 the JobPosted event names another requester than the job', asteptat: 'INVALID', paza: 'postare', r: () => { const d = date('S2'); ev(d, 'JobPosted').args.requester = d.job.provider; return v(P.judeca(d)); } });
F.push({ nume: 'N12 S5 an event whose time is not a whole number of seconds: refused by name (form)', asteptat: 'INVALID', paza: 'forma', r: () => { const d = date('S5'); ev(d, 'JobPosted').timestamp += 0.5; return v(P.judeca(d)); } });
F.push({ nume: 'N14 S1 finalized inside the window by a third party, with the ResultSubmitted event withheld (the window rule would be skipped): refused as not whole', asteptat: 'INVALID', paza: 'intreg', r: () => { const d = date('S1'); ev(d, 'JobPaid').timestamp = d.job.submittedAt + 1; d.events = d.events.filter((e) => e.name !== 'ResultSubmitted'); const r = P.judeca(d); return { verdict: r.verdict, detail: r.reguli.join() + ': ' + r.motive.join('; ') }; } });
F.push({ nume: 'N15 S4 the JobClaimed event withheld (the deadline rule of an expiry would be skipped): refused as not whole', asteptat: 'INVALID', paza: 'intreg', r: () => { const d = date('S4'); d.events = d.events.filter((e) => e.name !== 'JobClaimed'); return v(P.judeca(d)); } });
F.push({ nume: 'N13 malformed timelines (no constants, an event without args, events not a list) are refused by name, never thrown', asteptat: 'INVALID', r: () => { const rez = [(d) => { delete d.constants; }, (d) => { delete d.events[0].args; }, (d) => { d.events = 'x'; }].map((f) => { const d = date('S2'); f(d); const r = P.judeca(d); return r.verdict + ':' + r.reguli.join(); }); return { verdict: rez.every((x) => x === 'INVALID:forma') ? 'INVALID' : 'VALID', detail: rez.join(' ') }; } });
F.push({ nume: 'R1 the settlement receipt of S1 is an AIP-23 settlement envelope naming the payout tx and the provider', asteptat: 'VALID', r: () => { const d = date('S1'); const c = P.chitanta(d); const t = ev(d, 'JobPaid'); return { verdict: c.kind === 'aere-proof-of-settlement-attestation' && c.statement.txHash === t.txHash && c.statement.to.toLowerCase() === d.job.provider.toLowerCase() && c.statement.chainId === 28001 ? 'VALID' : 'INVALID', detail: c.statementHash.slice(0, 18) + '..' }; } });
return F;
}
@@ -49,7 +54,7 @@ if (!control) {
console.log(`\nmarket judge (evidence ${dovezi[dovezi.length - 1]}): ${verzi} VERDE, ${rosii} ROSU, ${stricate} STRICAT`);
process.exitCode = rosii || stricate ? 1 : 0;
} else {
const SURSA = fs.readFileSync(MODUL, 'utf8'); const marcaje = ['termen', 'fereastra', 'arbitru', 'plata', 'rezultat', 'replay', 'dovada']; let bune = 0;
const SURSA = fs.readFileSync(MODUL, 'utf8'); const marcaje = ['forma', 'intreg', 'postare', 'termen', 'fereastra', 'arbitru', 'plata', 'rezultat', 'replay', 'dovada']; let bune = 0;
for (const m of marcaje) {
const copie = path.join(AICI, `_plantat-piata-${process.pid}-${m}.mjs`); const n = SURSA.split(`/*PAZA:${m}*/`).length - 1; const tinte = fixturi(P).filter((f) => f.paza === m);
let stare, detaliu;