Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

fix(agora): keep verification independent and stop sculpting the fetcher's URL

nirholas416ee94ae74b
diff --git a/tests/agora-work-proof.test.js b/tests/agora-work-proof.test.js
index bebb61155..cd963826c 100644
--- a/tests/agora-work-proof.test.js
+++ b/tests/agora-work-proof.test.js
@@ -21,9 +21,11 @@ import {
proofBytesFromHex,
buildWorkResult,
} from '../workers/agora-citizens/work/_skills.js';
+import { jobPrompt } from '../workers/agora-citizens/work/_skills.js';
import { runVerifier } from '../workers/agora-citizens/work/verifier.js';
import { ACTIVE_PROFESSIONS, hasRunner, runProfession } from '../workers/agora-citizens/work/index.js';
import { buildRoster, primaryProfession, professionForAgent } from '../workers/agora-citizens/roster.js';
+import { isSelfDealing } from '../workers/agora-citizens/engine.js';
const sha = (s) => createHash('sha256').update(s).digest('hex');
const dataUrl = (bytes, mime = 'application/octet-stream') =>
@@ -119,6 +121,31 @@ describe('runVerifier — re-derives a producer proof (the trust loop)', () => {
});
});
+describe('jobPrompt: a creative brief, never an address', () => {
+ it('takes the real brief fields', () => {
+ expect(jobPrompt({ prompt: 'a weathered brass key' })).toBe('a weathered brass key');
+ expect(jobPrompt({ description: 'a low-poly desert fox' })).toBe('a low-poly desert fox');
+ expect(jobPrompt({})).toBe('');
+ });
+
+ it('ignores the Fetcher resource URL the engine attaches to every job', () => {
+ // The engine passes `resource` (the x402 target) on EVERY job and
+ // work/fetcher.js reads it directly. When jobPrompt also accepted it, a
+ // Sculptor never reached its own default brief and sculpted the URL string.
+ expect(jobPrompt({ resource: 'https://api.example.com/v0/inboxes/:inbox_id' })).toBe('');
+ });
+
+ it('ignores a bare URL in any brief field', () => {
+ expect(jobPrompt({ description: 'https://api.example.com/v0/threads/:thread_id' })).toBe('');
+ expect(jobPrompt({ title: 'ipfs://bafyfoo' })).toBe('');
+ });
+
+ it('keeps prose that merely contains a URL', () => {
+ const brief = 'a fox statue modelled on https://example.com/ref.png';
+ expect(jobPrompt({ prompt: brief })).toBe(brief);
+ });
+});
+
describe('active roster — ships only professions with a reachable runner', () => {
// The set that actually ships. Cartographer (bit 3) is deferred — its
// /api/diorama compose route exceeds the serverless function budget — so it is
@@ -192,3 +219,31 @@ describe('active roster — ships only professions with a reachable runner', ()
}
});
});
+
+describe('isSelfDealing: a vouch is only worth what its independence is worth', () => {
+ const me = 'citizen-a';
+ const peer = 'citizen-b';
+
+ it('bars claiming a bounty you posted', () => {
+ expect(isSelfDealing({ creator: { id: me } }, me)).toBe(true);
+ });
+
+ it('bars verifying a deliverable you produced', () => {
+ // Observed live on devnet 2026-08-06: the poster-side query correctly
+ // excludes the patron's own deliverables, but the bounty is then open to
+ // the whole board, so a peer's bounty targeting Aria's GLB was claimed by
+ // Aria, which vouched for its own work. Re-deriving your own hash from
+ // your own bytes always passes, so that attestation carried no signal.
+ expect(isSelfDealing({ creator: { id: peer }, target: { citizenId: me } }, me)).toBe(true);
+ });
+
+ it('allows a genuine third-party verification', () => {
+ expect(isSelfDealing({ creator: { id: peer }, target: { citizenId: peer } }, me)).toBe(false);
+ });
+
+ it('allows an ordinary peer bounty and tolerates missing fields', () => {
+ expect(isSelfDealing({ creator: { id: peer } }, me)).toBe(false);
+ expect(isSelfDealing({}, me)).toBe(false);
+ expect(isSelfDealing({ creator: { id: me } }, null)).toBe(false);
+ });
+});
diff --git a/workers/agora-citizens/README.md b/workers/agora-citizens/README.md
index aa5f42de5..43545b6bc 100644
--- a/workers/agora-citizens/README.md
+++ b/workers/agora-citizens/README.md
@@ -232,7 +232,8 @@ so the board regularly lights up with a live race or a filling guild:
- **Guild (`Collaborative`).** An open-entry pool (`minReputation 0`). Up to
`maxWorkers` citizens each claim, contribute a real sub-result, and complete; the
program **splits the reward**. Each share is **measured from the escrow** the
- completion drew down (bracketed `readEscrowLamports` — a real on-chain figure,
+ completion drew down as reward (bracketed `readEscrowState`, net of the escrow's rent
+ reserve on the completion that closes it, so it is a real on-chain figure and
never a guess) and projected as `earned`. The reconcile sweep projects `settled`
when the chain shows the guild finished, or `expired_task` (→ reward returns) if
it misses its worker target before the deadline.
diff --git a/workers/agora-citizens/engine.js b/workers/agora-citizens/engine.js
index b88ba0d5d..1cb439acb 100644
--- a/workers/agora-citizens/engine.js
+++ b/workers/agora-citizens/engine.js
@@ -35,7 +35,8 @@ import {
generateTaskId,
deriveTaskPda,
getTask,
- readEscrowLamports,
+ readEscrowState,
+ measuredShareAtomic,
withRetry,
TASK_STATE,
} from './agenc.js';
@@ -223,7 +224,15 @@ export async function bootFleet(cfg, store) {
lastSupplyAt: 0,
};
- ctx.dispatcher = await setupDispatcher(ctx);
+ // The dispatcher is the devnet work supply, not the fleet. If it can't be
+ // funded or registered, citizens still boot and work whatever the board
+ // already carries: one component's failure never grounds the city.
+ try {
+ ctx.dispatcher = await setupDispatcher(ctx);
+ } catch (err) {
+ log.error('dispatcher setup failed, running on externally-supplied work only', { err: err?.message });
+ ctx.dispatcher = null;
+ }
const seedAgents = await store.listSeedAgents(cfg.maxCitizens);
const specs = buildRoster(seedAgents, cfg);
@@ -369,6 +378,41 @@ async function pickClaimableTask(ctx, citizen) {
return null;
}
+/**
+ * Would this citizen be working both sides of the bounty? Two ways, both barred:
+ *
+ * 1. It posted the bounty. Claiming your own posting pays your escrow back to
+ * yourself and fakes demand.
+ * 2. It produced the deliverable the bounty asks someone to VERIFY. The
+ * poster-side query already excludes the patron's own deliverables, but the
+ * bounty is then open to the whole board, so the citizen that made the
+ * artifact could claim the job of checking it. A self-vouch attests nothing:
+ * re-deriving your own hash from your own bytes always passes, and it is
+ * precisely the attestation an attacker would want to mint. Independence is
+ * the entire product of the trust loop.
+ */
+export function isSelfDealing(task, citizenId) {
+ if (!citizenId) return false;
+ if (task?.creator?.id && task.creator.id === citizenId) return true;
+ if (task?.target?.citizenId && task.target.citizenId === citizenId) return true;
+ return false;
+}
+
+/**
+ * Can a citizen still engage this task on-chain? An Exclusive task is claimable only
+ * while it is Open. A multi-worker task (Arena / Guild) leaves Open the moment its
+ * FIRST worker claims, but it is still filling: the race wants every racer and the
+ * guild wants every contributor, and the free-slot check below is what actually bounds
+ * it. Gating these on Open alone let one claim lock everyone else out and strand the
+ * remaining slots until the deadline expired. Reconcile already treats a mid-fill
+ * multi-worker task as live; this is the same rule on the engage side.
+ */
+export function isJoinableState(state, taskType) {
+ if (state === TASK_STATE.Open) return true;
+ if (!isMultiWorkerType(taskType)) return false;
+ return state === TASK_STATE.InProgress || state === TASK_STATE.PendingValidation;
+}
+
/**
* SEEK the board's AgenC lane for a real bounty a patron (or human, in Task 08)
* posted. Honors the career ladder: a citizen only takes a job it's qualified for
@@ -381,7 +425,7 @@ async function pickBoardBounty(ctx, citizen) {
for (const t of tasks) {
if (t.source !== 'agenc' || !t.taskPda) continue;
if (citizen.claimed.has(t.taskPda)) continue;
- if (t.creator?.id && t.creator.id === citizen.id) continue; // never claim your own posting
+ if (isSelfDealing(t, citizen.id)) continue;
// Career-ladder gate from the projection (surfaced by /api/agora/board).
const eligible = citizenCanClaim(citizen, {
@@ -406,7 +450,7 @@ async function pickBoardBounty(ctx, citizen) {
} catch {
continue;
}
- if (!onchain || onchain.state !== TASK_STATE.Open) continue;
+ if (!onchain || !isJoinableState(onchain.state, normalizeTaskType(t.taskType))) continue;
if (onchain.currentWorkers >= onchain.maxWorkers) continue;
if (Number(onchain.deadline) <= Date.now() / 1000) continue;
@@ -588,7 +632,7 @@ async function settleArena(ctx, citizen, { job, work, profession, name }) {
async function settleGuild(ctx, citizen, { job, work, profession, name }) {
const cfg = ctx.cfg;
const repBefore = citizen.reputation;
- const escrowBefore = await readEscrowLamports(citizen.client, job.taskPda);
+ const escrowBefore = await readEscrowState(citizen.client, job.taskPda);
let completion;
try {
completion = await completeTask(
@@ -606,11 +650,9 @@ async function settleGuild(ctx, citizen, { job, work, profession, name }) {
await reconcile(ctx, citizen);
const repAfter = citizen.reputation > repBefore ? citizen.reputation : repBefore + 1;
citizen.reputation = repAfter;
- const escrowAfter = await readEscrowLamports(citizen.client, job.taskPda);
- let shareAtomic = null;
- if (escrowBefore != null && escrowAfter != null && escrowBefore > escrowAfter) {
- shareAtomic = Number(escrowBefore - escrowAfter); // what my completion drew from escrow
- }
+ const escrowAfter = await readEscrowState(citizen.client, job.taskPda);
+ const drawn = measuredShareAtomic(escrowBefore, escrowAfter); // what my completion drew as reward
+ const shareAtomic = drawn != null ? Number(drawn) : null;
const share = shareAtomic != null ? rewardShape(cfg, shareAtomic) : null;
await ctx.store.appendActivity({
citizenId: citizen.id,
@@ -628,8 +670,8 @@ async function settleGuild(ctx, citizen, { job, work, profession, name }) {
guild: true,
outcome: 'contributed',
shareAtomic: shareAtomic != null ? String(shareAtomic) : null,
- escrowBefore: escrowBefore != null ? String(escrowBefore) : null,
- escrowAfter: escrowAfter != null ? String(escrowAfter) : null,
+ escrowBefore: escrowBefore != null ? String(escrowBefore.lamports) : null,
+ escrowAfter: escrowAfter != null ? String(escrowAfter.lamports) : null,
},
});
if (share) {
diff --git a/workers/agora-citizens/work/_skills.js b/workers/agora-citizens/work/_skills.js
index 733ba7c24..9a1d63990 100644
--- a/workers/agora-citizens/work/_skills.js
+++ b/workers/agora-citizens/work/_skills.js
@@ -100,8 +100,18 @@ export function buildWorkResult({ profession, citizen, deliverableUrl, deliverab
// Best creative brief from a job. On-chain tasks carry only a 64-byte
// description; the dispatcher/board attaches the real prompt as `job.prompt`.
+//
+// `job.resource` is deliberately NOT a source. It is the Fetcher's x402 target
+// URL, which the engine attaches to EVERY job, and work/fetcher.js reads it
+// directly. Accepting it here meant a generative profession never reached its
+// own default brief: a Sculptor handed a board job sculpted a mesh of the
+// literal string "https://api.example.com/v0/inboxes/:inbox_id/…", producing a
+// real GLB of nothing anybody asked for. A bare URL is filtered for the same
+// reason, whichever field carries it: it is an address, never a brief.
export function jobPrompt(job) {
- return String(job?.prompt || job?.title || job?.description || job?.resource || '').trim();
+ const raw = String(job?.prompt || job?.title || job?.description || '').trim();
+ if (/^[a-z][a-z0-9+.-]*:\/\//i.test(raw) && !/\s/.test(raw)) return '';
+ return raw;
}
// ── Deliverable storage (R2) ──────────────────────────────────────────────────