From ff7d2ce7e6403cd9c56a43d0ba825fa66155209e Mon Sep 17 00:00:00 2001 From: vAPI Development <336934719+vapi-development@users.noreply.github.com> Date: Wed, 2 Dec 2026 16:58:48 +0100 Subject: [PATCH 1/2] fix(tasks): hash the declared share, skills and location terms like vAPI vAPI freezes every declared order term into the on-chain terms hash, including `share`, `skills` and `location` (orderTermsSchema). The client's terms model did not know those fields, so it hashed other terms than vAPI and predicted another clone address. On Base mainnet the funding of a new pool was refused with "The funding target differs from the prediction for accepted creation terms." Nothing was signed. The client now carries those three declared fields, so its terms hash and clone prediction match vAPI for pools, tasks and bounties. A regression test pins the terms hash of a real mainnet pool posted on 2026-12-02, which makes the pinned pool factory predict vAPI's funding address. Co-Authored-By: Claude Opus 5.5 Signed-off-by: vAPI Development <336934719+vapi-development@users.noreply.github.com> --- .../core/src/tasks/terms-hash-parity.test.ts | 85 +++++++++++++++++++ packages/core/src/tasks/v2.ts | 8 ++ 2 files changed, 93 insertions(+) create mode 100644 packages/core/src/tasks/terms-hash-parity.test.ts diff --git a/packages/core/src/tasks/terms-hash-parity.test.ts b/packages/core/src/tasks/terms-hash-parity.test.ts new file mode 100644 index 0000000..3ae3ca7 --- /dev/null +++ b/packages/core/src/tasks/terms-hash-parity.test.ts @@ -0,0 +1,85 @@ +import { describe, expect, it } from "vitest"; + +import { acceptedV2TermsHash } from "./v2-plan-guard.js"; +import { TRUSTED_TASKS_V2_DEPLOYMENTS } from "./v2-trust.js"; +import type { GetOrderResponse } from "./types.js"; + +const BASE = TRUSTED_TASKS_V2_DEPLOYMENTS[8453]!; + +/** + * A pool posted on Base mainnet on 2026-12-02 (order 0eb0adc1…). vAPI froze its terms with the + * declared `share` field, and the pinned pool factory predicts vAPI's funding address + * 0x96d5Bd72E199feE7F9e198694bf08642C9aEe021 only for this terms hash. + */ +const mainnetPool = { + workOrder: { + id: "0eb0adc1-5cf8-4b66-aa8d-21e6f0a90488", + title: "Pilot test: submit a test username", + description: + "Pilot test pool (vAPI team). Claim with your vAPI ID and submit a test username as text. Reward 0.01 USDC per claim, one claim per wallet.", + clientAddress: "0x39733bd6670b1d0ea1ec081f8b2137663bc2d510", + terms: { + shape: "pool", + proofSpec: { items: [{ preset: "text" }], anyOf: false }, + checkin: "none", + pool: { + rewardPerClaimBaseUnits: "10000", + budgetBaseUnits: "20000", + gate: "open", + verifier: "poster", + openCheck: "vapi-id", + }, + liveness: { nextDueAt: null, stalledAt: null, cadence: "none", canCancelRemainderAt: null }, + share: { public: false }, + }, + market: { + budget: { network: "eip155:8453", asset: "USDC", amountBaseUnits: "20000" }, + deadlineAt: "2026-12-02T17:45:54.632Z", + }, + }, +} as unknown as GetOrderResponse; + +function withTerms(view: GetOrderResponse, terms: Record): GetOrderResponse { + return { ...view, workOrder: { ...view.workOrder, terms } } as unknown as GetOrderResponse; +} + +const task = { + workOrder: { + ...mainnetPool.workOrder, + terms: { + shape: "task", + checkin: "none", + milestones: [ + { + index: 1, + amountBaseUnits: "1000000", + acceptance: "Deliver the page", + deadlineAt: "2026-12-09T12:00:00.000Z", + }, + ], + }, + market: { + budget: { network: "eip155:8453", asset: "USDC", amountBaseUnits: "1000000" }, + deadlineAt: "2026-12-09T12:00:00.000Z", + }, + }, +} as unknown as GetOrderResponse; + +describe("terms hash parity with vAPI's declared order terms", () => { + it("hashes a mainnet pool exactly as vAPI froze it, including share", () => { + expect(acceptedV2TermsHash(mainnetPool, BASE, 0n)).toBe( + "0x37e5666efa834f366bef6bc7910c3a073a590fb938832f88cf76b5b4a9a54f2c", + ); + }); + + it.each([ + ["share", { share: { public: true } }], + ["skills", { skills: ["design"] }], + ["location", { location: { lat: 52.37, lng: 4.9 } }], + ])("binds the declared %s field into a task's terms hash", (_field, extra) => { + const terms = task.workOrder.terms as Record; + expect(acceptedV2TermsHash(withTerms(task, { ...terms, ...extra }), BASE, 604800n)).not.toBe( + acceptedV2TermsHash(task, BASE, 604800n), + ); + }); +}); diff --git a/packages/core/src/tasks/v2.ts b/packages/core/src/tasks/v2.ts index 2f46280..3df1d3a 100644 --- a/packages/core/src/tasks/v2.ts +++ b/packages/core/src/tasks/v2.ts @@ -89,6 +89,14 @@ export const poolTermsSchema = z.strictObject({ }); export const taskTermsFields = { shape: taskShapeSchema.optional(), + // Declared fields vAPI freezes into the on-chain terms hash (vapi-app shared/order-terms.ts + // orderTermsSchema). Every declared field must stay here, or the client hashes other terms + // than vAPI and refuses the funding target vAPI predicts. + share: z.strictObject({ public: z.boolean() }).optional(), + skills: z.array(z.string()).max(10).optional(), + location: z + .strictObject({ lat: z.number().min(-90).max(90), lng: z.number().min(-180).max(180) }) + .optional(), milestones: declaredMilestonesSchema.optional(), proofSpec: proofSpecSchema.optional(), checkin: checkinCadenceSchema.optional(), From 9c1a1f945aae51e558879328e1221bb29f5ea2fc Mon Sep 17 00:00:00 2001 From: vAPI Development <336934719+vapi-development@users.noreply.github.com> Date: Wed, 2 Dec 2026 17:09:49 +0100 Subject: [PATCH 2/2] fix(tasks): hash declared terms without offering them as post input `share`, `skills` and `location` are set on vAPI, not by this client's post. They now live in `declaredTermsFields`, which only the terms hash reads; `taskTermsFields`, the post input of the SDK, CLI and MCP, is unchanged, so MCP `tasks.post` does not accept fields it would drop. Co-Authored-By: Claude Opus 5.5 Signed-off-by: vAPI Development <336934719+vapi-development@users.noreply.github.com> --- .../core/src/tasks/terms-hash-parity.test.ts | 8 +++++++ packages/core/src/tasks/v2-plan-guard.ts | 8 +++---- packages/core/src/tasks/v2.ts | 22 ++++++++++++------- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/packages/core/src/tasks/terms-hash-parity.test.ts b/packages/core/src/tasks/terms-hash-parity.test.ts index 3ae3ca7..c6cf1ca 100644 --- a/packages/core/src/tasks/terms-hash-parity.test.ts +++ b/packages/core/src/tasks/terms-hash-parity.test.ts @@ -2,6 +2,7 @@ import { describe, expect, it } from "vitest"; import { acceptedV2TermsHash } from "./v2-plan-guard.js"; import { TRUSTED_TASKS_V2_DEPLOYMENTS } from "./v2-trust.js"; +import { declaredTermsFields, taskTermsFields } from "./v2.js"; import type { GetOrderResponse } from "./types.js"; const BASE = TRUSTED_TASKS_V2_DEPLOYMENTS[8453]!; @@ -82,4 +83,11 @@ describe("terms hash parity with vAPI's declared order terms", () => { acceptedV2TermsHash(task, BASE, 604800n), ); }); + + it("hashes vAPI's declared fields without offering them as post input", () => { + for (const field of ["share", "skills", "location"]) { + expect(Object.keys(declaredTermsFields)).toContain(field); + expect(Object.keys(taskTermsFields)).not.toContain(field); + } + }); }); diff --git a/packages/core/src/tasks/v2-plan-guard.ts b/packages/core/src/tasks/v2-plan-guard.ts index b49f52b..4cc0b98 100644 --- a/packages/core/src/tasks/v2-plan-guard.ts +++ b/packages/core/src/tasks/v2-plan-guard.ts @@ -18,7 +18,7 @@ import { canonicalJson } from "./canonical-json.js"; import { getTrustedTasksDurations } from "./trusted-deployments.js"; import { DEFAULT_ACCEPTANCE_WINDOW_SECONDS } from "./scope-terms.js"; import { freezeScopeTerms } from "./scope-terms.js"; -import { taskTermsFields } from "./v2.js"; +import { declaredTermsFields } from "./v2.js"; import { TaskOperationError } from "./operation-support.js"; import { escrowFactoryV2Abi, @@ -217,7 +217,7 @@ export function acceptedV2TermsHash( reviewWindow: bigint, ) { const order = view.workOrder; - const terms = z.object(taskTermsFields).parse(order.terms); + const terms = z.object(declaredTermsFields).parse(order.terms); const market = z .object({ budget: z.object({ network: z.string(), amountBaseUnits: z.string() }) }) .parse(order.market); @@ -282,7 +282,7 @@ export function acceptedV2TermsHash( /** The worker bond the accepted order declares (EscrowV2 accepts it only on a one-milestone task). */ function acceptedWorkerBondBp(view: GetOrderResponse) { - const terms = z.object(taskTermsFields).parse(view.workOrder.terms); + const terms = z.object(declaredTermsFields).parse(view.workOrder.terms); return terms.bounty ? 0 : (terms.workerBondBp ?? 0); } @@ -300,7 +300,7 @@ function acceptedCreationArgs( onchainVerifier?: Address, ): readonly unknown[] { const order = view.workOrder; - const terms = z.object(taskTermsFields).parse(order.terms); + const terms = z.object(declaredTermsFields).parse(order.terms); const poster = address.parse(order.clientAddress); const total = acceptedV2Total(view); const salt = keccak256(toHex(order.id)); diff --git a/packages/core/src/tasks/v2.ts b/packages/core/src/tasks/v2.ts index 3df1d3a..0d895d0 100644 --- a/packages/core/src/tasks/v2.ts +++ b/packages/core/src/tasks/v2.ts @@ -89,14 +89,6 @@ export const poolTermsSchema = z.strictObject({ }); export const taskTermsFields = { shape: taskShapeSchema.optional(), - // Declared fields vAPI freezes into the on-chain terms hash (vapi-app shared/order-terms.ts - // orderTermsSchema). Every declared field must stay here, or the client hashes other terms - // than vAPI and refuses the funding target vAPI predicts. - share: z.strictObject({ public: z.boolean() }).optional(), - skills: z.array(z.string()).max(10).optional(), - location: z - .strictObject({ lat: z.number().min(-90).max(90), lng: z.number().min(-180).max(180) }) - .optional(), milestones: declaredMilestonesSchema.optional(), proofSpec: proofSpecSchema.optional(), checkin: checkinCadenceSchema.optional(), @@ -106,6 +98,20 @@ export const taskTermsFields = { bounty: bountyTermsSchema.optional(), pool: poolTermsSchema.optional(), }; +/** + * Every declared term vAPI freezes into an order's on-chain terms hash (vapi-app + * shared/order-terms.ts orderTermsSchema). Hashing reads a hosted order with these fields; a + * missing one makes the client hash other terms than vAPI and refuse vAPI's escrow. `share`, + * `skills` and `location` are set on vAPI, not by this client's post input. + */ +export const declaredTermsFields = { + ...taskTermsFields, + share: z.strictObject({ public: z.boolean() }).optional(), + skills: z.array(z.string()).max(10).optional(), + location: z + .strictObject({ lat: z.number().min(-90).max(90), lng: z.number().min(-180).max(180) }) + .optional(), +}; export const taskTermsSchema = z.looseObject({ ...taskTermsFields, shape: taskShapeSchema,