brainchain-verify 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/dist/cli.js +3 -3
- package/dist/deployments.js +1 -1
- package/dist/verify.d.ts +2 -0
- package/dist/verify.js +38 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ brainchain-verify <mainnet|testnet|chainId> --task <taskId> [--set <TaskBoard>]
|
|
|
22
22
|
| `mainnet`, `testnet` or a chain id | `mainnet` is chain 274663 at `https://rpc.usebrainchain.com`; `testnet` is chain 274630 at `https://rpc.testnet.usebrainchain.com`. |
|
|
23
23
|
| `<decisionId>` | The decision's number in its `DecisionLog`, from 1. |
|
|
24
24
|
| `--task <id>` | Check every decision about one task, oldest first. |
|
|
25
|
-
| `--set <TaskBoard>` | A retired contract set, by its TaskBoard address
|
|
25
|
+
| `--set <TaskBoard>` | A retired contract set, by its TaskBoard address, by the key a decision page uses (`?set=v3-1`) or by release (`3.1.0`). Without it, the active set. Each set numbers its tasks and decisions from 1. |
|
|
26
26
|
| `--rpc <url>` | Another RPC for the same chain. |
|
|
27
27
|
| `--json` | One JSON object on stdout. |
|
|
28
28
|
|
|
@@ -79,6 +79,7 @@ Some checks skip by design:
|
|
|
79
79
|
|
|
80
80
|
- A record for work Jev did not accept is served without the work, so `record-hash` and `input-hash` cannot match it. The answer, confidence and threshold are still checked.
|
|
81
81
|
- A decision the board never applied, because a later decision or a closed window settled the task, skips `threshold`.
|
|
82
|
+
- A grade of work delivered outside BrainChain has no task on the board, so it skips `threshold`. Its subject, levels and confidence are still checked.
|
|
82
83
|
- A grade recorded before the chain gated on the paid levels skips `confidence-recomputed`: its confidence is Jev's score confidence, which the probabilities alone do not give.
|
|
83
84
|
|
|
84
85
|
## What it cannot check
|
package/dist/cli.js
CHANGED
|
@@ -12,8 +12,8 @@ fetches the published record, recomputes its hashes and confidence, and applies
|
|
|
12
12
|
the task's thresholds as the contracts do. Needs no keys.
|
|
13
13
|
|
|
14
14
|
--task <id> check every decision about one task
|
|
15
|
-
--set <board> a retired contract set, by TaskBoard address
|
|
16
|
-
the site (v3-1); without it, the active set
|
|
15
|
+
--set <board> a retired contract set, by TaskBoard address, by its key on
|
|
16
|
+
the site (v3-1) or by release (3.1.0); without it, the active set
|
|
17
17
|
--rpc <url> another RPC for the same chain
|
|
18
18
|
--json one JSON object on stdout
|
|
19
19
|
|
|
@@ -64,7 +64,7 @@ if (!foundNetwork)
|
|
|
64
64
|
const network = foundNetwork;
|
|
65
65
|
const foundSet = setArg === undefined
|
|
66
66
|
? network.sets[0]
|
|
67
|
-
: network.sets.find((s) => (isAddress(setArg) ? s.board.toLowerCase() === setArg.toLowerCase() : s.key === setArg));
|
|
67
|
+
: network.sets.find((s) => (isAddress(setArg) ? s.board.toLowerCase() === setArg.toLowerCase() : s.key === setArg || s.release === setArg));
|
|
68
68
|
if (!foundSet) {
|
|
69
69
|
const sets = network.sets.map((s, i) => `${s.key} (TaskBoard ${s.board}${i === 0 ? ", active" : ""})`);
|
|
70
70
|
usage(`No contract set ${setArg} on ${network.name}. Sets: ${sets.join(", ")}`);
|
package/dist/deployments.js
CHANGED
package/dist/verify.d.ts
CHANGED
package/dist/verify.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BaseError, decodeFunctionData, encodeAbiParameters, keccak256, pad, toBytes, } from "viem";
|
|
1
|
+
import { BaseError, decodeFunctionData, encodeAbiParameters, keccak256, pad, toBytes, toHex, } from "viem";
|
|
2
2
|
import { decisionExecutorAbi, decisionLogAbi, modelRegistryAbi, taskBoardAbi } from "./abi.js";
|
|
3
3
|
import { canonicalStringify } from "./canonical.js";
|
|
4
4
|
const Kind = { Hire: 1, Grade: 2, Ruling: 3, Change: 4 };
|
|
@@ -42,6 +42,20 @@ function decodeText(bytes) {
|
|
|
42
42
|
return undefined;
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
|
+
/** Base and Base Sepolia, where ACP evaluations come from. */
|
|
46
|
+
const ACP_CHAINS = [8453n, 84532n];
|
|
47
|
+
/** Whether a grade's subject is the one the service derives for work delivered elsewhere: a paid grade by its id, or an ACP evaluation by its job. */
|
|
48
|
+
function outsideGrade(recorded, subject) {
|
|
49
|
+
if (!/^\d+$/.test(recorded))
|
|
50
|
+
return false;
|
|
51
|
+
const id = BigInt(recorded);
|
|
52
|
+
if (id >> 256n !== 0n)
|
|
53
|
+
return false;
|
|
54
|
+
const paid = keccak256(encodeAbiParameters([{ type: "string" }, { type: "bytes32" }], ["x402-grade", toHex(id, { size: 32 })]));
|
|
55
|
+
if (paid === subject)
|
|
56
|
+
return true;
|
|
57
|
+
return ACP_CHAINS.some((chain) => keccak256(encodeAbiParameters([{ type: "string" }, { type: "uint256" }, { type: "uint256" }], ["acp-evaluation", chain, id])) === subject);
|
|
58
|
+
}
|
|
45
59
|
/** TaskBoard.subjectOf(id): the task on this board on this chain. */
|
|
46
60
|
function taskSubject(chainId, board, task) {
|
|
47
61
|
return keccak256(encodeAbiParameters([{ type: "uint256" }, { type: "address" }, { type: "uint256" }], [BigInt(chainId), board, task]));
|
|
@@ -231,12 +245,18 @@ export async function verifyDecision(ctx, id) {
|
|
|
231
245
|
c.check("input-hash", input === decision.inputHash, `request hash matches inputHash ${short(input)}`, `request hash ${short(input)} differs from inputHash ${short(decision.inputHash)}`);
|
|
232
246
|
}
|
|
233
247
|
c.check("kind", record.kind === kind, `kind: ${record.kind}`, `the record is a ${record.kind}; the chain recorded a ${kind}`);
|
|
234
|
-
const
|
|
248
|
+
const outside = decision.kind === Kind.Grade && outsideGrade(record.subject, decision.subject);
|
|
249
|
+
const task = !outside && decision.kind !== Kind.Change && /^\d+$/.test(record.subject) ? BigInt(record.subject) : undefined;
|
|
235
250
|
if (task !== undefined)
|
|
236
251
|
report.task = Number(task);
|
|
252
|
+
if (outside)
|
|
253
|
+
report.outside = true;
|
|
237
254
|
if (decision.kind === Kind.Change) {
|
|
238
255
|
c.check("subject", record.subject.toLowerCase() === decision.subject, `subject: ${short(decision.subject)}, the exact call this change names`, "the record's subject differs from the one on chain");
|
|
239
256
|
}
|
|
257
|
+
else if (outside) {
|
|
258
|
+
c.add("subject", "ok", "subject: a grade of work delivered outside BrainChain, so no task on this board");
|
|
259
|
+
}
|
|
240
260
|
else {
|
|
241
261
|
c.check("subject", task !== undefined && taskSubject(network.chainId, set.board, task) === decision.subject, `subject: task ${record.subject} on board ${short(set.board)}, chain ${network.chainId}`, `the record names task ${record.subject}, which is not the subject recorded on chain`);
|
|
242
262
|
}
|
|
@@ -278,6 +298,10 @@ export async function verifyDecision(ctx, id) {
|
|
|
278
298
|
await checkBrief(ctx, c, task, decision, record, state);
|
|
279
299
|
await checkTaskThreshold(ctx, c, id, task, decision, record);
|
|
280
300
|
}
|
|
301
|
+
if (outside) {
|
|
302
|
+
checkOutsideGrade(c, record);
|
|
303
|
+
c.add("threshold", "skip", "threshold: no task on this chain, so no board applied this grade; the caller received the verdict");
|
|
304
|
+
}
|
|
281
305
|
if (decision.kind === Kind.Change)
|
|
282
306
|
await checkChange(ctx, c, id, decision, record, state);
|
|
283
307
|
return report;
|
|
@@ -311,7 +335,18 @@ async function checkBrief(ctx, c, task, decision, record, state) {
|
|
|
311
335
|
c.add("confidence-recomputed", "skip", "grade confidence: this grade predates the rule that gates on the paid levels, so its confidence is Jev's score confidence, which the probabilities alone do not give");
|
|
312
336
|
return;
|
|
313
337
|
}
|
|
314
|
-
|
|
338
|
+
checkGradeConfidence(c, record, ascending.map((_, i) => String(i)).slice(ascending.length - 1 - brief.passIndex));
|
|
339
|
+
}
|
|
340
|
+
// No brief on chain to compare with: the levels and the pass level are in the record, which inputHash commits to.
|
|
341
|
+
function checkOutsideGrade(c, record) {
|
|
342
|
+
const levels = record.request.questions.decision.criteria;
|
|
343
|
+
if (!Array.isArray(levels) || record.passFrom === undefined) {
|
|
344
|
+
c.add("confidence-recomputed", "skip", "grade confidence: the record does not name its pass level");
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
checkGradeConfidence(c, record, levels.map((_, i) => String(i)).slice(record.passFrom));
|
|
348
|
+
}
|
|
349
|
+
function checkGradeConfidence(c, record, paidKeys) {
|
|
315
350
|
const parts = paidKeys.map((key) => record.probabilities[key] ?? 0);
|
|
316
351
|
const jev = share(parts);
|
|
317
352
|
const how = `paid levels ${paidKeys.join(", ")} hold ${parts.join(" + ")} = ${jev.toFixed(4)}`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "brainchain-verify",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Check a BrainChain decision against the chain: the published record, its hashes, its confidence and the thresholds the contracts applied.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "BrainChain",
|