arl-protocol-sdk 0.0.0-stage → 0.2.0
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 +79 -2
- package/package.json +32 -4
- package/protocol/src/canonical.d.ts +7 -0
- package/protocol/src/canonical.js +35 -0
- package/protocol/src/deployments.d.ts +17 -0
- package/protocol/src/deployments.js +24 -0
- package/protocol/src/evidence.d.ts +72 -0
- package/protocol/src/evidence.js +107 -0
- package/protocol/src/index.d.ts +14 -0
- package/protocol/src/index.js +9 -0
- package/protocol/src/policies.d.ts +5 -0
- package/protocol/src/policies.js +56 -0
- package/protocol/src/policy.d.ts +65 -0
- package/protocol/src/policy.js +202 -0
- package/protocol/src/prepare.d.ts +176 -0
- package/protocol/src/prepare.js +104 -0
- package/protocol/src/proof.d.ts +70 -0
- package/protocol/src/proof.js +239 -0
- package/protocol/src/reputation.d.ts +47 -0
- package/protocol/src/reputation.js +74 -0
- package/protocol/src/task.d.ts +121 -0
- package/protocol/src/task.js +322 -0
- package/sdk/src/abi.d.ts +358 -0
- package/sdk/src/abi.js +465 -0
- package/sdk/src/acquireArl.d.ts +34 -0
- package/sdk/src/acquireArl.js +126 -0
- package/sdk/src/escrowProvider.d.ts +73 -0
- package/sdk/src/escrowProvider.js +169 -0
- package/sdk/src/index.d.ts +9 -0
- package/sdk/src/index.js +10 -0
- package/sdk/src/jobs.d.ts +278 -0
- package/sdk/src/jobs.js +220 -0
- package/sdk/src/openTask.d.ts +23 -0
- package/sdk/src/openTask.js +116 -0
- package/sdk/src/payVerified.d.ts +45 -0
- package/sdk/src/payVerified.js +147 -0
- package/sdk/src/streaming.d.ts +80 -0
- package/sdk/src/streaming.js +229 -0
- package/sdk/src/verified.d.ts +229 -0
- package/sdk/src/verified.js +220 -0
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
// arl-proof/1: the proof envelope a provider publishes for one job (spec/arl-proof/v0.1.0).
|
|
2
|
+
// It binds the delivered result and its evidence to the task (task hash) and to the on-chain job
|
|
3
|
+
// (chain, escrow, job id). Only a hash goes on chain: `ARLJobs.submit(jobId, deliverable)`.
|
|
4
|
+
// A proof is a claim, never a verification: validators check it under the task's policy.
|
|
5
|
+
import { canonicalHash } from "./canonical.js";
|
|
6
|
+
import { EVIDENCE_KINDS, taskHash } from "./task.js";
|
|
7
|
+
export const PROOF_VERSION = "arl-proof/1";
|
|
8
|
+
export const REEXEC_RESULT_VERSION = "arl-reexec-result/1";
|
|
9
|
+
export class ProofError extends Error {
|
|
10
|
+
name = "ProofError";
|
|
11
|
+
}
|
|
12
|
+
const HASH = /^0x[0-9a-f]{64}$/;
|
|
13
|
+
const SHA256 = /^[0-9a-f]{64}$/;
|
|
14
|
+
const ADDRESS = /^0x[0-9a-fA-F]{40}$/;
|
|
15
|
+
const DIGITS = /^(0|[1-9][0-9]*)$/;
|
|
16
|
+
const MEDIA_TYPE = /^[a-z0-9][a-z0-9!#$&^_.+-]{0,62}\/[a-z0-9][a-z0-9!#$&^_.+-]{0,62}$/;
|
|
17
|
+
const PATH = /^[A-Za-z0-9._-]+(\/[A-Za-z0-9._-]+)*$/;
|
|
18
|
+
const MAX_EVIDENCE = 32;
|
|
19
|
+
function isRecord(v) {
|
|
20
|
+
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
21
|
+
}
|
|
22
|
+
function onlyKeys(v, allowed, what) {
|
|
23
|
+
for (const k of Object.keys(v)) {
|
|
24
|
+
if (!allowed.includes(k))
|
|
25
|
+
throw new ProofError(`${what}: unknown field ${k}`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function str(v, max, what) {
|
|
29
|
+
if (typeof v !== "string" || v.trim().length === 0 || v.length > max) {
|
|
30
|
+
throw new ProofError(`${what} must be a non-empty string of at most ${max} characters`);
|
|
31
|
+
}
|
|
32
|
+
return v;
|
|
33
|
+
}
|
|
34
|
+
function uri(v, what) {
|
|
35
|
+
const s = str(v, 2048, what);
|
|
36
|
+
let parsed;
|
|
37
|
+
try {
|
|
38
|
+
parsed = new URL(s);
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
throw new ProofError(`${what} is not a URL`);
|
|
42
|
+
}
|
|
43
|
+
if (parsed.protocol !== "https:" && parsed.protocol !== "ipfs:") {
|
|
44
|
+
throw new ProofError(`${what} must be https or ipfs`);
|
|
45
|
+
}
|
|
46
|
+
return s;
|
|
47
|
+
}
|
|
48
|
+
function sha256(v, what) {
|
|
49
|
+
if (typeof v !== "string" || !SHA256.test(v)) {
|
|
50
|
+
throw new ProofError(`${what} must be 64 lowercase hex`);
|
|
51
|
+
}
|
|
52
|
+
return v;
|
|
53
|
+
}
|
|
54
|
+
function mediaType(v, what) {
|
|
55
|
+
if (typeof v !== "string" || !MEDIA_TYPE.test(v)) {
|
|
56
|
+
throw new ProofError(`${what} must be a lowercase media type`);
|
|
57
|
+
}
|
|
58
|
+
return v;
|
|
59
|
+
}
|
|
60
|
+
function contentRef(v, what) {
|
|
61
|
+
if (!isRecord(v))
|
|
62
|
+
throw new ProofError(`${what} must be an object`);
|
|
63
|
+
onlyKeys(v, ["uri", "sha256", "media_type", "bytes"], what);
|
|
64
|
+
if (typeof v.bytes !== "number" || !Number.isSafeInteger(v.bytes) || v.bytes < 0) {
|
|
65
|
+
throw new ProofError(`${what}.bytes must be a non-negative integer`);
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
uri: uri(v.uri, `${what}.uri`),
|
|
69
|
+
sha256: sha256(v.sha256, `${what}.sha256`),
|
|
70
|
+
media_type: mediaType(v.media_type, `${what}.media_type`),
|
|
71
|
+
bytes: v.bytes,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
function modelRef(v, what) {
|
|
75
|
+
if (!isRecord(v))
|
|
76
|
+
throw new ProofError(`${what} must be an object`);
|
|
77
|
+
onlyKeys(v, ["name", "weights_sha256", "runtime"], what);
|
|
78
|
+
return {
|
|
79
|
+
name: str(v.name, 200, `${what}.name`),
|
|
80
|
+
weights_sha256: sha256(v.weights_sha256, `${what}.weights_sha256`),
|
|
81
|
+
runtime: str(v.runtime, 200, `${what}.runtime`),
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
function evidenceItem(v, i) {
|
|
85
|
+
const what = `evidence[${i}]`;
|
|
86
|
+
if (!isRecord(v))
|
|
87
|
+
throw new ProofError(`${what} must be an object`);
|
|
88
|
+
onlyKeys(v, ["kind", "uri", "sha256", "media_type", "model"], what);
|
|
89
|
+
if (typeof v.kind !== "string" || !EVIDENCE_KINDS.includes(v.kind)) {
|
|
90
|
+
throw new ProofError(`${what}.kind must be one of ${EVIDENCE_KINDS.join(", ")}`);
|
|
91
|
+
}
|
|
92
|
+
const kind = v.kind;
|
|
93
|
+
const item = {
|
|
94
|
+
kind,
|
|
95
|
+
uri: uri(v.uri, `${what}.uri`),
|
|
96
|
+
sha256: sha256(v.sha256, `${what}.sha256`),
|
|
97
|
+
media_type: mediaType(v.media_type, `${what}.media_type`),
|
|
98
|
+
};
|
|
99
|
+
if (v.model !== undefined)
|
|
100
|
+
item.model = modelRef(v.model, `${what}.model`);
|
|
101
|
+
if (kind === "model-verdict" && item.model === undefined) {
|
|
102
|
+
throw new ProofError(`${what}: model-verdict evidence must name the model and its weights hash`);
|
|
103
|
+
}
|
|
104
|
+
if (kind !== "model-verdict" && item.model !== undefined) {
|
|
105
|
+
throw new ProofError(`${what}: only model-verdict evidence names a model`);
|
|
106
|
+
}
|
|
107
|
+
return item;
|
|
108
|
+
}
|
|
109
|
+
function reexecResult(v) {
|
|
110
|
+
const what = "result_manifest";
|
|
111
|
+
if (!isRecord(v))
|
|
112
|
+
throw new ProofError(`${what} must be an object`);
|
|
113
|
+
onlyKeys(v, ["version", "spec_hash", "exit_code", "timed_out", "outputs"], what);
|
|
114
|
+
if (v.version !== REEXEC_RESULT_VERSION) {
|
|
115
|
+
throw new ProofError(`${what}.version must be ${REEXEC_RESULT_VERSION}`);
|
|
116
|
+
}
|
|
117
|
+
if (typeof v.spec_hash !== "string" || !HASH.test(v.spec_hash)) {
|
|
118
|
+
throw new ProofError(`${what}.spec_hash must be 0x and 64 lowercase hex`);
|
|
119
|
+
}
|
|
120
|
+
if (v.exit_code !== null &&
|
|
121
|
+
(typeof v.exit_code !== "number" || !Number.isSafeInteger(v.exit_code))) {
|
|
122
|
+
throw new ProofError(`${what}.exit_code must be an integer or null`);
|
|
123
|
+
}
|
|
124
|
+
if (typeof v.timed_out !== "boolean")
|
|
125
|
+
throw new ProofError(`${what}.timed_out must be a boolean`);
|
|
126
|
+
if (!Array.isArray(v.outputs))
|
|
127
|
+
throw new ProofError(`${what}.outputs must be an array`);
|
|
128
|
+
const outputs = v.outputs.map((o, i) => {
|
|
129
|
+
const w = `${what}.outputs[${i}]`;
|
|
130
|
+
if (!isRecord(o))
|
|
131
|
+
throw new ProofError(`${w} must be an object`);
|
|
132
|
+
onlyKeys(o, ["path", "sha256"], w);
|
|
133
|
+
if (typeof o.path !== "string" || !PATH.test(o.path)) {
|
|
134
|
+
throw new ProofError(`${w}.path must be a relative path`);
|
|
135
|
+
}
|
|
136
|
+
if (o.sha256 !== null)
|
|
137
|
+
sha256(o.sha256, `${w}.sha256`);
|
|
138
|
+
return { path: o.path, sha256: o.sha256 };
|
|
139
|
+
});
|
|
140
|
+
return {
|
|
141
|
+
version: REEXEC_RESULT_VERSION,
|
|
142
|
+
spec_hash: v.spec_hash,
|
|
143
|
+
exit_code: v.exit_code,
|
|
144
|
+
timed_out: v.timed_out,
|
|
145
|
+
outputs,
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
/** Validates an untrusted proof document and returns it typed. Unknown fields are refused. */
|
|
149
|
+
export function parseProof(raw) {
|
|
150
|
+
if (!isRecord(raw))
|
|
151
|
+
throw new ProofError("proof must be an object");
|
|
152
|
+
onlyKeys(raw, [
|
|
153
|
+
"version",
|
|
154
|
+
"task_hash",
|
|
155
|
+
"chain_id",
|
|
156
|
+
"jobs",
|
|
157
|
+
"job_id",
|
|
158
|
+
"deliverable",
|
|
159
|
+
"result_manifest",
|
|
160
|
+
"evidence",
|
|
161
|
+
], "proof");
|
|
162
|
+
if (raw.version !== PROOF_VERSION)
|
|
163
|
+
throw new ProofError(`version must be ${PROOF_VERSION}`);
|
|
164
|
+
if (typeof raw.task_hash !== "string" || !HASH.test(raw.task_hash)) {
|
|
165
|
+
throw new ProofError("task_hash must be 0x and 64 lowercase hex");
|
|
166
|
+
}
|
|
167
|
+
if (typeof raw.chain_id !== "number" || !Number.isSafeInteger(raw.chain_id) || raw.chain_id < 1) {
|
|
168
|
+
throw new ProofError("chain_id must be a positive integer");
|
|
169
|
+
}
|
|
170
|
+
if (typeof raw.jobs !== "string" || !ADDRESS.test(raw.jobs)) {
|
|
171
|
+
throw new ProofError("jobs must be an address");
|
|
172
|
+
}
|
|
173
|
+
if (typeof raw.job_id !== "string" || !DIGITS.test(raw.job_id) || raw.job_id === "0") {
|
|
174
|
+
throw new ProofError("job_id must be a positive decimal string");
|
|
175
|
+
}
|
|
176
|
+
if (!Array.isArray(raw.evidence) || raw.evidence.length > MAX_EVIDENCE) {
|
|
177
|
+
throw new ProofError(`evidence must be an array of at most ${MAX_EVIDENCE} items`);
|
|
178
|
+
}
|
|
179
|
+
const proof = {
|
|
180
|
+
version: PROOF_VERSION,
|
|
181
|
+
task_hash: raw.task_hash,
|
|
182
|
+
chain_id: raw.chain_id,
|
|
183
|
+
jobs: raw.jobs,
|
|
184
|
+
job_id: raw.job_id,
|
|
185
|
+
deliverable: contentRef(raw.deliverable, "deliverable"),
|
|
186
|
+
evidence: raw.evidence.map(evidenceItem),
|
|
187
|
+
};
|
|
188
|
+
if (raw.result_manifest !== undefined)
|
|
189
|
+
proof.result_manifest = reexecResult(raw.result_manifest);
|
|
190
|
+
return proof;
|
|
191
|
+
}
|
|
192
|
+
/** keccak256 of the canonical proof. */
|
|
193
|
+
export function proofHash(proof) {
|
|
194
|
+
return canonicalHash(proof);
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* The bytes32 the provider passes to `ARLJobs.submit`: for a reexec task the hash of the
|
|
198
|
+
* arl-reexec-result/1 manifest (what `arl-verifier` recomputes, unchanged), otherwise the proof
|
|
199
|
+
* hash.
|
|
200
|
+
*/
|
|
201
|
+
export function submittedDeliverable(proof) {
|
|
202
|
+
return proof.result_manifest !== undefined
|
|
203
|
+
? canonicalHash(proof.result_manifest)
|
|
204
|
+
: proofHash(proof);
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Structural checks of a proof against its task (no network, no chain): the hashes bind, the
|
|
208
|
+
* required evidence is present, the deliverable fits. Passing this is the precondition for
|
|
209
|
+
* verification, not verification itself.
|
|
210
|
+
*/
|
|
211
|
+
export function checkProofAgainstTask(task, proof) {
|
|
212
|
+
if (proof.task_hash !== taskHash(task))
|
|
213
|
+
throw new ProofError("task_hash does not match the task");
|
|
214
|
+
if (proof.deliverable.media_type !== task.deliverable.media_type) {
|
|
215
|
+
throw new ProofError("deliverable media type differs from the task");
|
|
216
|
+
}
|
|
217
|
+
if (task.deliverable.max_bytes !== undefined &&
|
|
218
|
+
proof.deliverable.bytes > task.deliverable.max_bytes) {
|
|
219
|
+
throw new ProofError("deliverable is larger than the task allows");
|
|
220
|
+
}
|
|
221
|
+
const kinds = new Set(proof.evidence.map((e) => e.kind));
|
|
222
|
+
if (proof.result_manifest !== undefined)
|
|
223
|
+
kinds.add("result-manifest");
|
|
224
|
+
for (const k of task.evidence) {
|
|
225
|
+
if (!kinds.has(k))
|
|
226
|
+
throw new ProofError(`required evidence missing: ${k}`);
|
|
227
|
+
}
|
|
228
|
+
if (task.workload.class === "reexec") {
|
|
229
|
+
if (proof.result_manifest === undefined) {
|
|
230
|
+
throw new ProofError("a reexec task needs the arl-reexec-result/1 manifest");
|
|
231
|
+
}
|
|
232
|
+
if (proof.result_manifest.spec_hash !== task.workload.spec_hash) {
|
|
233
|
+
throw new ProofError("result_manifest.spec_hash differs from the task's workload spec");
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
else if (proof.result_manifest !== undefined) {
|
|
237
|
+
throw new ProofError("only a reexec task carries a result manifest");
|
|
238
|
+
}
|
|
239
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export declare const REPUTATION_VERSION = "arl-reputation/1";
|
|
2
|
+
export type OutcomeKind = "completed" | "rejected" | "expired" | "failed";
|
|
3
|
+
export interface Outcome {
|
|
4
|
+
/** "<escrow address>:<job id>", unique per job. */
|
|
5
|
+
job: string;
|
|
6
|
+
client: string;
|
|
7
|
+
token: "ARL" | "USDC";
|
|
8
|
+
/** Budget in base units, decimal string. */
|
|
9
|
+
budget: string;
|
|
10
|
+
outcome: OutcomeKind;
|
|
11
|
+
/** Unix seconds when the outcome was final on chain. */
|
|
12
|
+
final_at: number;
|
|
13
|
+
/** Whether a dispute was raised (and ruled) on this job. */
|
|
14
|
+
disputed: boolean;
|
|
15
|
+
}
|
|
16
|
+
export interface ScoreParams {
|
|
17
|
+
/** Half-life of an outcome's weight, in seconds. */
|
|
18
|
+
half_life_seconds: number;
|
|
19
|
+
/** Highest share of total weight a single client may contribute (anti wash-trading). */
|
|
20
|
+
max_client_share: number;
|
|
21
|
+
/** Outcomes needed before a score is published. */
|
|
22
|
+
min_outcomes: number;
|
|
23
|
+
/** Distinct clients needed before a score is published. */
|
|
24
|
+
min_clients: number;
|
|
25
|
+
}
|
|
26
|
+
export declare const DEFAULT_PARAMS: ScoreParams;
|
|
27
|
+
export interface Score {
|
|
28
|
+
version: typeof REPUTATION_VERSION;
|
|
29
|
+
/** 0–10000 basis points (100.00 %), or null when there is not enough history. */
|
|
30
|
+
score_bps: number | null;
|
|
31
|
+
outcomes: number;
|
|
32
|
+
clients: number;
|
|
33
|
+
completed: number;
|
|
34
|
+
rejected: number;
|
|
35
|
+
expired: number;
|
|
36
|
+
disputed: number;
|
|
37
|
+
}
|
|
38
|
+
export declare class ReputationError extends Error {
|
|
39
|
+
name: string;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Computes the score. Completed counts 100, rejected and expired (a funded job the provider did
|
|
43
|
+
* not deliver) count 0; failed jobs (the committee did not decide) are not the provider's doing
|
|
44
|
+
* and are excluded. Each outcome is weighted by budget size and recency; a client's total weight
|
|
45
|
+
* is capped at `max_client_share` of the total, so one counterparty cannot buy a reputation.
|
|
46
|
+
*/
|
|
47
|
+
export declare function reputationScore(outcomes: Outcome[], now: number, params?: ScoreParams): Score;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// arl-reputation/1: an agent's score computed only from verified outcomes (spec/arl-reputation/
|
|
2
|
+
// v0.1.0). Inputs come from the chain: the evaluator's ERC-8004 feedback (tag "arl-verified",
|
|
3
|
+
// value 100 approved / 0 rejected) joined with the ARLJobs job (client, budget, token) and expiry
|
|
4
|
+
// refunds of funded jobs. Self-reported feedback is never an input: readers query the
|
|
5
|
+
// ReputationRegistry with the deployed evaluators as the only allowed clients.
|
|
6
|
+
export const REPUTATION_VERSION = "arl-reputation/1";
|
|
7
|
+
export const DEFAULT_PARAMS = {
|
|
8
|
+
half_life_seconds: 180 * 24 * 3600,
|
|
9
|
+
max_client_share: 0.25,
|
|
10
|
+
min_outcomes: 3,
|
|
11
|
+
min_clients: 2,
|
|
12
|
+
};
|
|
13
|
+
const DECIMALS = { ARL: 18, USDC: 6 };
|
|
14
|
+
export class ReputationError extends Error {
|
|
15
|
+
name = "ReputationError";
|
|
16
|
+
}
|
|
17
|
+
/** Whole token units, dampened: 1 + log10(1 + units). Budgets in different tokens are not priced. */
|
|
18
|
+
function sizeWeight(token, budget) {
|
|
19
|
+
if (!/^(0|[1-9][0-9]*)$/.test(budget))
|
|
20
|
+
throw new ReputationError("budget must be a decimal string");
|
|
21
|
+
const units = Number(BigInt(budget) / 10n ** BigInt(DECIMALS[token]));
|
|
22
|
+
return 1 + Math.log10(1 + units);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Computes the score. Completed counts 100, rejected and expired (a funded job the provider did
|
|
26
|
+
* not deliver) count 0; failed jobs (the committee did not decide) are not the provider's doing
|
|
27
|
+
* and are excluded. Each outcome is weighted by budget size and recency; a client's total weight
|
|
28
|
+
* is capped at `max_client_share` of the total, so one counterparty cannot buy a reputation.
|
|
29
|
+
*/
|
|
30
|
+
export function reputationScore(outcomes, now, params = DEFAULT_PARAMS) {
|
|
31
|
+
const seen = new Set();
|
|
32
|
+
const counted = outcomes.filter((o) => {
|
|
33
|
+
if (seen.has(o.job))
|
|
34
|
+
throw new ReputationError(`duplicate outcome for ${o.job}`);
|
|
35
|
+
seen.add(o.job);
|
|
36
|
+
if (o.final_at > now)
|
|
37
|
+
throw new ReputationError(`outcome in the future: ${o.job}`);
|
|
38
|
+
return o.outcome !== "failed";
|
|
39
|
+
});
|
|
40
|
+
const byClient = new Map();
|
|
41
|
+
for (const o of counted) {
|
|
42
|
+
const age = now - o.final_at;
|
|
43
|
+
const w = sizeWeight(o.token, o.budget) * Math.pow(0.5, age / params.half_life_seconds);
|
|
44
|
+
const value = o.outcome === "completed" ? 1 : 0;
|
|
45
|
+
const key = o.client.toLowerCase();
|
|
46
|
+
const c = byClient.get(key) ?? { w: 0, wv: 0 };
|
|
47
|
+
c.w += w;
|
|
48
|
+
c.wv += w * value;
|
|
49
|
+
byClient.set(key, c);
|
|
50
|
+
}
|
|
51
|
+
const total = [...byClient.values()].reduce((s, c) => s + c.w, 0);
|
|
52
|
+
const share = params.max_client_share;
|
|
53
|
+
let w = 0;
|
|
54
|
+
let wv = 0;
|
|
55
|
+
for (const c of byClient.values()) {
|
|
56
|
+
// Scale a dominant client down so its weight is at most `share` of the result, measured
|
|
57
|
+
// against everyone else's weight, keeping its own success ratio.
|
|
58
|
+
const cap = (share / (1 - share)) * (total - c.w);
|
|
59
|
+
const f = byClient.size > 1 && c.w > cap ? cap / c.w : 1;
|
|
60
|
+
w += c.w * f;
|
|
61
|
+
wv += c.wv * f;
|
|
62
|
+
}
|
|
63
|
+
const enough = counted.length >= params.min_outcomes && byClient.size >= params.min_clients;
|
|
64
|
+
return {
|
|
65
|
+
version: REPUTATION_VERSION,
|
|
66
|
+
score_bps: enough && w > 0 ? Math.round((wv / w) * 10_000) : null,
|
|
67
|
+
outcomes: counted.length,
|
|
68
|
+
clients: byClient.size,
|
|
69
|
+
completed: counted.filter((o) => o.outcome === "completed").length,
|
|
70
|
+
rejected: counted.filter((o) => o.outcome === "rejected").length,
|
|
71
|
+
expired: counted.filter((o) => o.outcome === "expired").length,
|
|
72
|
+
disputed: counted.filter((o) => o.disputed).length,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import type { Address, Hex } from "viem";
|
|
2
|
+
export declare const TASK_VERSION = "arl-task/1";
|
|
3
|
+
export declare const WORKLOAD_CLASSES: readonly ["reexec", "attested", "model-assisted", "review"];
|
|
4
|
+
export type WorkloadClass = (typeof WORKLOAD_CLASSES)[number];
|
|
5
|
+
export declare const TIERS: readonly ["fallback", "reexecution", "attested"];
|
|
6
|
+
export type Tier = (typeof TIERS)[number];
|
|
7
|
+
export declare const EVIDENCE_KINDS: readonly ["result-manifest", "logs", "artifact", "attestation", "model-verdict"];
|
|
8
|
+
export type EvidenceKind = (typeof EVIDENCE_KINDS)[number];
|
|
9
|
+
export declare const TOKENS: readonly ["ARL", "USDC"];
|
|
10
|
+
export type Token = (typeof TOKENS)[number];
|
|
11
|
+
/** Bounds of the deployed contracts and of this spec. */
|
|
12
|
+
export declare const BOUNDS: {
|
|
13
|
+
/** ARLJobs.MIN_DURATION and MAX_DURATION, in hours (5 minutes rounds up to 1 hour). */
|
|
14
|
+
readonly deadlineHours: readonly [1, 8760];
|
|
15
|
+
/** ARLVerifiedEvaluator.MIN_VOTE_WINDOW / MAX_VOTE_WINDOW. */
|
|
16
|
+
readonly voteWindowSeconds: readonly [600, 604800];
|
|
17
|
+
/** minChallengeWindow on Base Mainnet (86400) / MAX_CHALLENGE_WINDOW. */
|
|
18
|
+
readonly challengeWindowSeconds: readonly [86400, 2592000];
|
|
19
|
+
/** ARLVerifiedEvaluator.MAX_COMMITTEE. */
|
|
20
|
+
readonly committeeSize: readonly [1, 7];
|
|
21
|
+
readonly title: 120;
|
|
22
|
+
readonly description: 4000;
|
|
23
|
+
readonly acceptance: readonly [1, 20];
|
|
24
|
+
readonly rule: 500;
|
|
25
|
+
/** ARLJobs.MAX_DESCRIPTION, in UTF-8 bytes (the on-chain job description). */
|
|
26
|
+
readonly onchainDescription: 1024;
|
|
27
|
+
};
|
|
28
|
+
export interface Workload {
|
|
29
|
+
class: WorkloadClass;
|
|
30
|
+
/** Where the workload spec lives (required for reexec: an arl-reexec/1 document). */
|
|
31
|
+
spec_uri?: string;
|
|
32
|
+
/** keccak256 of the canonical workload spec (required for reexec). */
|
|
33
|
+
spec_hash?: Hex;
|
|
34
|
+
}
|
|
35
|
+
export interface AcceptanceRule {
|
|
36
|
+
id: string;
|
|
37
|
+
rule: string;
|
|
38
|
+
}
|
|
39
|
+
export interface Payment {
|
|
40
|
+
token: Token;
|
|
41
|
+
/** Budget in the token's base units, as a decimal string (no float, no sign). */
|
|
42
|
+
budget: string;
|
|
43
|
+
deadline_hours: number;
|
|
44
|
+
}
|
|
45
|
+
export interface Verification {
|
|
46
|
+
/** The verification policy this task follows (arl-policy/1 id, Phase 2C). */
|
|
47
|
+
policy: string;
|
|
48
|
+
tier: Tier;
|
|
49
|
+
committee_size: number;
|
|
50
|
+
threshold: number;
|
|
51
|
+
vote_window_seconds: number;
|
|
52
|
+
challenge_window_seconds: number;
|
|
53
|
+
/** Bond floor in ARL base units, decimal string; the contract takes max(floor, budget / 10). */
|
|
54
|
+
bond_floor: string;
|
|
55
|
+
}
|
|
56
|
+
export interface Task {
|
|
57
|
+
version: typeof TASK_VERSION;
|
|
58
|
+
title: string;
|
|
59
|
+
description: string;
|
|
60
|
+
workload: Workload;
|
|
61
|
+
acceptance: AcceptanceRule[];
|
|
62
|
+
deliverable: {
|
|
63
|
+
media_type: string;
|
|
64
|
+
max_bytes?: number;
|
|
65
|
+
};
|
|
66
|
+
payment: Payment;
|
|
67
|
+
verification: Verification;
|
|
68
|
+
evidence: EvidenceKind[];
|
|
69
|
+
}
|
|
70
|
+
export declare class TaskError extends Error {
|
|
71
|
+
name: string;
|
|
72
|
+
}
|
|
73
|
+
/** Validates an untrusted task document and returns it typed. Unknown fields are refused. */
|
|
74
|
+
export declare function parseTask(raw: unknown): Task;
|
|
75
|
+
/** keccak256 of the canonical task: the task hash. */
|
|
76
|
+
export declare function taskHash(task: Task): Hex;
|
|
77
|
+
/**
|
|
78
|
+
* The value committed as `specHash` in `ARLVerifiedEvaluator.configure`: the workload spec hash
|
|
79
|
+
* for a reexec task (validators re-run that spec, unchanged from arl-reexec/1), otherwise the task
|
|
80
|
+
* hash.
|
|
81
|
+
*/
|
|
82
|
+
export declare function committedSpecHash(task: Task): Hex;
|
|
83
|
+
/**
|
|
84
|
+
* The on-chain job description: `arl-task:<task hash>` followed by the task's URI, so anyone can
|
|
85
|
+
* fetch the task and check it against its hash. Must fit ARLJobs.MAX_DESCRIPTION.
|
|
86
|
+
*/
|
|
87
|
+
export declare function jobDescription(task: Task, taskUri: string): string;
|
|
88
|
+
/** Arguments for ARLJobs.createJob and the Config of ARLVerifiedEvaluator.configure. */
|
|
89
|
+
export interface OnchainTerms {
|
|
90
|
+
createJob: {
|
|
91
|
+
provider: Address;
|
|
92
|
+
evaluator: Address;
|
|
93
|
+
expiredAt: bigint;
|
|
94
|
+
description: string;
|
|
95
|
+
hook: Address;
|
|
96
|
+
};
|
|
97
|
+
configure: {
|
|
98
|
+
tier: number;
|
|
99
|
+
threshold: number;
|
|
100
|
+
voteWindow: bigint;
|
|
101
|
+
challengeWindow: bigint;
|
|
102
|
+
bond: bigint;
|
|
103
|
+
providerAgentId: bigint;
|
|
104
|
+
specHash: Hex;
|
|
105
|
+
committee: Address[];
|
|
106
|
+
};
|
|
107
|
+
budget: bigint;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Maps a parsed task to the contract calls (pure: no chain access). `now` is the chain time in
|
|
111
|
+
* seconds. The committee is proposed by the client; it must not contain the client or provider.
|
|
112
|
+
*/
|
|
113
|
+
export declare function onchainTerms(task: Task, opts: {
|
|
114
|
+
client: Address;
|
|
115
|
+
provider: Address;
|
|
116
|
+
evaluator: Address;
|
|
117
|
+
committee: Address[];
|
|
118
|
+
taskUri: string;
|
|
119
|
+
now: bigint;
|
|
120
|
+
providerAgentId?: bigint;
|
|
121
|
+
}): OnchainTerms;
|