From 526db477b40d1169c7688a7d13140560ca3d0033 Mon Sep 17 00:00:00 2001 From: vAPI Development <336934719+vapi-development@users.noreply.github.com> Date: Wed, 2 Dec 2026 14:56:43 +0100 Subject: [PATCH 1/3] fix(tasks): fund a new task, bounty or pool through vAPI's ERC-3009 intent Where vAPI serves ERC-3009 funding (Base mainnet), the first funding of a new order is one ReceiveWithAuthorization to the clone's predicted address; the clone is created after the signature is confirmed. The plan guard refused every such intent ("The V2 target is not registered by the locally pinned factory"), so the CLI and local MCP could not fund any new task, bounty or pool there. The guard now treats the intent like the approval of a fresh clone: it derives the creation arguments from the accepted terms and the pinned factory's live fee, and signs only when the pinned factory predicts the intent's address for them. The authorization can only be redeemed by that address, which exists only as the clone of exactly those arguments. The signing-block deadline check of a task now reads MIN_WORK_TIME from the factory implementation while the clone does not exist, and covers the accepted milestones instead of an empty list. Co-Authored-By: Claude Opus 5.5 Signed-off-by: vAPI Development <336934719+vapi-development@users.noreply.github.com> --- packages/core/src/tasks/v2-execution.test.ts | 166 +++++++++++++++++++ packages/core/src/tasks/v2-plan-guard.ts | 33 +++- 2 files changed, 193 insertions(+), 6 deletions(-) diff --git a/packages/core/src/tasks/v2-execution.test.ts b/packages/core/src/tasks/v2-execution.test.ts index 984e0c1..90b468d 100644 --- a/packages/core/src/tasks/v2-execution.test.ts +++ b/packages/core/src/tasks/v2-execution.test.ts @@ -23,6 +23,7 @@ import { escrowV2Abi, bountyEscrowV2Abi, bountyPoolV1Abi, + bountyPoolFactoryV1Abi, reviewerRegistryV2Abi, } from "./v2-abi.js"; import { acceptedV2TermsHash } from "./v2-plan-guard.js"; @@ -2459,6 +2460,171 @@ function authorizedFunding( return intent; } +describe("a new clone funded by one authorization (hosted ERC-3009 funding)", () => { + // vAPI prepares the first funding of a new order as one ReceiveWithAuthorization to the + // clone's predicted address; the clone is created only after the signature is confirmed. + function newClone(f: Awaited>) { + let registered = false; + const original = f.rpc.readContract.getMockImplementation()!; + f.rpc.readContract.mockImplementation(async (call) => { + if (call.functionName === "isEscrow") return registered; + if (!registered && call.address?.toLowerCase() === state.escrow.toLowerCase()) + throw new Error("Cannot read the escrow before creation"); + return original(call); + }); + f.rpc.waitForTransactionReceipt.mockImplementation(async () => { + registered = true; + return { status: "success" }; + }); + return { registered: () => registered }; + } + it("predicts the clone from accepted terms, signs once, then creates and funds it", async () => { + const f = await fixture("v2-fund"); + const intent = authorizedFunding(f); + const clone = newClone(f); + f.client.confirmV2Signature.mockImplementation( + async (_id: string, _op: string, signature: `0x${string}`) => { + f.prepared.operation.plan.to = FACTORY.toLowerCase() as Hex; + f.prepared.operation.plan.data = encodeFunctionData({ + abi: escrowFactoryV2Abi, + functionName: "createAndFundWithAuthorization", + args: [ + ...creationArgs(), + account.address, + BigInt(intent.typedData.message.validAfter), + BigInt(intent.typedData.message.validBefore), + intent.typedData.message.nonce as `0x${string}`, + signature, + ], + }); + return f.prepared; + }, + ); + expect(await f.execute({ ...f.input, write: { action: "fund" } })).toMatchObject({ + ok: true, + operation: { step: "v2-fund", state: "confirmed" }, + }); + expect(f.typedSign).toHaveBeenCalledTimes(1); + expect(f.sign).toHaveBeenCalledTimes(1); + expect(f.sign.mock.calls[0]![0]).toMatchObject({ to: FACTORY.toLowerCase() }); + expect(clone.registered()).toBe(true); + }); + it("funds a new open vAPI ID pool: one authorization, then create and fund", async () => { + const f = await fixture("v2-fund"); + Object.assign(f.view.workOrder, { + terms: { + shape: "pool", + pool: { + rewardPerClaimBaseUnits: "20000000", + budgetBaseUnits: "100000000", + gate: "open", + verifier: "poster", + openCheck: "vapi-id", + }, + }, + market: { ...f.view.workOrder.market, deadlineAt: DEADLINE }, + v2State: undefined, + }); + const intent = authorizedFunding(f); + let registered = false; + const original = f.rpc.readContract.getMockImplementation()!; + f.rpc.readContract.mockImplementation(async (call) => { + if (call.functionName === "isPool") return registered; + if (!registered && call.address?.toLowerCase() === state.escrow.toLowerCase()) + throw new Error("Cannot read the pool before creation"); + if (call.functionName === "rewardPerClaim") return 20000000n; + if (call.functionName === "deadline") return BigInt(Date.parse(DEADLINE) / 1000); + if (call.functionName === "gate") return 1; + if (call.functionName === "verifier") return account.address; + if (call.functionName === "budget") return 100000000n; + return original(call); + }); + f.rpc.waitForTransactionReceipt.mockImplementation(async () => { + registered = true; + return { status: "success" }; + }); + const create = encodeFunctionData({ + abi: bountyPoolFactoryV1Abi, + functionName: "createPool", + args: [ + account.address, + 20000000n, + 100000000n, + BigInt(Date.parse(DEADLINE) / 1000), + acceptedV2TermsHash(f.view as unknown as import("./types.js").GetOrderResponse, PIN, 0n), + 1, + account.address, + keccak256(toHex(V2_WRITE_ORDER)), + ], + }); + let current = f.prepared; + const step = (name: "v2-create-pool" | "v2-fund", to: string, data: Hex) => + (current = { + ...current, + operation: { + ...current.operation, + step: name, + plan: { ...current.operation.plan, step: name, to: to.toLowerCase() as Hex, data }, + }, + }); + f.client.confirmV2Signature.mockImplementation( + async (_id: string, _op: string, signature: `0x${string}`) => { + step("v2-create-pool", POOL_FACTORY, create); + // vAPI returns the create step now and the authorized funding as the following step. + fundData = encodeFunctionData({ + abi: bountyPoolV1Abi, + functionName: "fundWithAuthorization", + args: [ + account.address, + BigInt(intent.typedData.message.validAfter), + BigInt(intent.typedData.message.validBefore), + intent.typedData.message.nonce as `0x${string}`, + signature, + ], + }); + return current; + }, + ); + let fundData: Hex = "0x"; + f.client.operationV2.mockImplementation(async (_id, mode, body) => { + if (mode === "recover") return { ...current, recovered: false, scanComplete: true }; + if (mode === "reconcile" && current.operation.step === "v2-create-pool") + return step("v2-fund", state.escrow, fundData); + return { + ...current, + operation: { + ...current.operation, + state: mode === "transaction" ? "submitted" : "confirmed", + transactionHash: (body as { transactionHash?: string }).transactionHash, + }, + }; + }); + expect(await f.execute({ ...f.input, write: { action: "fund" } })).toMatchObject({ + ok: true, + operation: { step: "v2-fund", state: "confirmed" }, + }); + expect(f.typedSign).toHaveBeenCalledTimes(1); + const [creation, funding] = f.sign.mock.calls.map(([tx]) => tx); + expect(f.sign).toHaveBeenCalledTimes(2); + expect(creation).toMatchObject({ to: POOL_FACTORY.toLowerCase() }); + expect(funding).toMatchObject({ to: state.escrow }); + }); + it("refuses to sign when the pinned factory predicts another clone for the accepted terms", async () => { + const f = await fixture("v2-fund"); + authorizedFunding(f); + newClone(f); + const original = f.rpc.readContract.getMockImplementation()!; + f.rpc.readContract.mockImplementation(async (call) => + call.functionName === "predictEscrow" ? WORKER : original(call), + ); + await expect(f.execute({ ...f.input, write: { action: "fund" } })).rejects.toThrow( + /prediction/u, + ); + expect(f.typedSign).not.toHaveBeenCalled(); + expect(f.sign).not.toHaveBeenCalled(); + }); +}); + describe("Base mainnet: today's production readiness (configured: false)", () => { it("parses the exact production body as unavailable on chain 8453", async () => { const f = onBase(await fixture("v2-fund"), READINESS_UNAVAILABLE); diff --git a/packages/core/src/tasks/v2-plan-guard.ts b/packages/core/src/tasks/v2-plan-guard.ts index ad64862..b49f52b 100644 --- a/packages/core/src/tasks/v2-plan-guard.ts +++ b/packages/core/src/tasks/v2-plan-guard.ts @@ -167,6 +167,11 @@ export type VerifiedV2Target = { /** Verified escrow terms: the registered clone's terms(), or accepted creation terms. */ terms?: V2EscrowTerms; milestones: Array<{ amount: bigint; deadline: bigint; status: number }>; + /** + * The contract whose MIN_WORK_TIME bounds funding deadlines: the factory implementation while + * the clone is not created yet (its code does not exist), otherwise the clone itself. + */ + deadlineSource?: Address; /** Exact factory prediction inputs (predictEscrow / predictBountyEscrow / predictPool). */ creationArgs?: readonly unknown[]; }; @@ -563,9 +568,16 @@ export async function verifyV2Target( verifyAcceptedCreation(options, view, pin, creationArgs, pool, chainId, fresh); candidate = await predict(creationArgs); } + // A first funding names a clone that does not exist yet: the approval of a fresh clone, or + // vAPI's ERC-3009 intent (one ReceiveWithAuthorization to the predicted clone, created only + // after the signature is confirmed). Derive the creation arguments from the accepted terms + // and the pinned factory's live fee, and trust only the factory's own prediction for them. + // An authorization can be redeemed only by its `to` contract, and that address exists only + // as the clone of exactly these arguments, so the signature is bound to the accepted order. + const signatureIntent = !plan && intent.success; if ( action.action === "fund" && - plan?.step === "v2-approve-usdc" && + (plan?.step === "v2-approve-usdc" || signatureIntent) && (!candidate || !(await isRegistered(candidate))) ) { fresh = await creationPolicy(rpc, pin, pool); @@ -583,9 +595,9 @@ export async function verifyV2Target( "The V2 target cannot be independently verified from this response. A registered target or verifiable funding creation terms are required.", ); if (!(await isRegistered(candidate))) { - // The hosted signature intent has no frozen creation arguments: never sign - // a redeemable authorization to its unverified predicted address. - if (action.action !== "fund" || !plan || !creationArgs || !fresh) + // Only a first funding may name an unregistered clone, and only with creation arguments + // this client derived or checked itself (above): never sign toward an unverified address. + if (action.action !== "fund" || (!plan && !signatureIntent) || !creationArgs || !fresh) return v2GuardFailure("The V2 target is not registered by the locally pinned factory."); const expectedCreation = acceptedCreationArgs(options, view, pin, chainId, fresh); if (canon(creationArgs) !== canon(expectedCreation)) @@ -593,10 +605,17 @@ export async function verifyV2Target( verifyActor(action, options.account.address, address.parse(order.clientAddress)); const terms = pool ? undefined : escrowTermsSchema.parse(creationArgs[0]); verifyBinding(candidate, terms?.termsHash ?? hash.parse(creationArgs[4])); + let deadlineSource: Address | undefined; + let freshMilestones: VerifiedV2Target["milestones"] = []; if (!pool && !bounty) { const implementation = address.parse( await v2Read(rpc, factory, escrowFactoryV2Abi, "implementation"), ); + deadlineSource = implementation; + freshMilestones = z + .array(milestoneSchema) + .parse(creationArgs[1]) + .map((m) => ({ amount: m.amount, deadline: m.deadline, status: 0 })); if ( !same(await v2Read(rpc, implementation, escrowV2Abi, "FACTORY"), factory) || !same(await v2Read(rpc, implementation, escrowV2Abi, "USDC"), pin.usdc) @@ -627,7 +646,9 @@ export async function verifyV2Target( feeBp: fresh.feeBp, termsHash: terms?.termsHash ?? hash.parse(creationArgs[4]), ...(terms ? { terms } : {}), - milestones: [], + // The accepted milestones, so the signing-block deadline check covers the new clone too. + milestones: freshMilestones, + ...(deadlineSource ? { deadlineSource } : {}), creationArgs, }; } @@ -759,7 +780,7 @@ export async function verifyV2TypedData( if (!target.pool && !target.bounty) await verifyFundingDeadlines( target.rpc, - target.escrow, + target.deadlineSource ?? target.escrow, target.milestones.map((m) => m.deadline), block.timestamp, ); From eb13bfa9d5076f8ba20e18941ce52f0b2c227b7e Mon Sep 17 00:00:00 2001 From: vAPI Development <336934719+vapi-development@users.noreply.github.com> Date: Wed, 2 Dec 2026 15:23:46 +0100 Subject: [PATCH 2/3] fix(tasks): bind a first funding to the order this client posted A first funding creates the clone from vAPI's copy of the order. `post --fund` in the CLI and MCP now passes the order it posted (title, brief, deadline, shape, milestones, bounty or pool terms, worker bond) into the executor, which refuses to sign when vAPI's order differs on any of them. A changed reward, verifier, split or deadline can no longer reach a signature through the approval or the ERC-3009 path. Co-Authored-By: Claude Opus 5.5 Signed-off-by: vAPI Development <336934719+vapi-development@users.noreply.github.com> --- packages/cli/src/task.ts | 1 + packages/core/src/tasks/v2-execution.test.ts | 59 ++++++++++++++- packages/core/src/tasks/v2-execution.ts | 80 ++++++++++++++++++++ packages/mcp/src/tools/tasks.ts | 20 ++--- 4 files changed, 150 insertions(+), 10 deletions(-) diff --git a/packages/cli/src/task.ts b/packages/cli/src/task.ts index db9a7a8..ca64748 100644 --- a/packages/cli/src/task.ts +++ b/packages/cli/src/task.ts @@ -831,6 +831,7 @@ async function taskCommandInner( prepared: v2Prepared.data, preparationKey: outcome.fundingIdempotencyKey, expectedGrossBaseUnits: prepared.escrowAmount, + postedOrder: { ...input, deadlineAt }, policy, caps: await spendCapsForWallet(target.store, target.name), wallet: target.name, diff --git a/packages/core/src/tasks/v2-execution.test.ts b/packages/core/src/tasks/v2-execution.test.ts index 90b468d..714c253 100644 --- a/packages/core/src/tasks/v2-execution.test.ts +++ b/packages/core/src/tasks/v2-execution.test.ts @@ -2599,7 +2599,25 @@ describe("a new clone funded by one authorization (hosted ERC-3009 funding)", () }, }; }); - expect(await f.execute({ ...f.input, write: { action: "fund" } })).toMatchObject({ + expect( + await f.execute({ + ...f.input, + write: { action: "fund" }, + postedOrder: { + title: f.view.workOrder.title, + description: f.view.workOrder.description, + deadlineAt: DEADLINE, + shape: "pool", + pool: { + rewardPerClaimBaseUnits: "20000000", + budgetBaseUnits: "100000000", + gate: "open", + verifier: "poster", + openCheck: "vapi-id", + }, + }, + }), + ).toMatchObject({ ok: true, operation: { step: "v2-fund", state: "confirmed" }, }); @@ -2609,6 +2627,45 @@ describe("a new clone funded by one authorization (hosted ERC-3009 funding)", () expect(creation).toMatchObject({ to: POOL_FACTORY.toLowerCase() }); expect(funding).toMatchObject({ to: state.escrow }); }); + it.each([ + ["reward per claim", { rewardPerClaimBaseUnits: "10000000" }, {}], + ["verifier", { verifier: "vapi" }, {}], + ["deadline", {}, { deadlineAt: "2026-10-29T12:00:00.000Z" }], + ] as const)( + "refuses a first funding when vAPI's order changed the posted %s", + async (_field, poolChange, postChange) => { + const f = await fixture("v2-fund"); + const pool = { + rewardPerClaimBaseUnits: "20000000", + budgetBaseUnits: "100000000", + gate: "open", + verifier: "poster", + openCheck: "vapi-id", + }; + Object.assign(f.view.workOrder, { + terms: { shape: "pool", pool: { ...pool, ...poolChange } }, + market: { ...f.view.workOrder.market, deadlineAt: DEADLINE }, + v2State: undefined, + }); + authorizedFunding(f); + await expect( + f.execute({ + ...f.input, + write: { action: "fund" }, + postedOrder: { + title: f.view.workOrder.title, + description: f.view.workOrder.description, + deadlineAt: DEADLINE, + shape: "pool", + pool, + ...postChange, + }, + }), + ).rejects.toThrow(/differs from what this client posted/u); + expect(f.typedSign).not.toHaveBeenCalled(); + expect(f.sign).not.toHaveBeenCalled(); + }, + ); it("refuses to sign when the pinned factory predicts another clone for the accepted terms", async () => { const f = await fixture("v2-fund"); authorizedFunding(f); diff --git a/packages/core/src/tasks/v2-execution.ts b/packages/core/src/tasks/v2-execution.ts index 425735e..a9d659e 100644 --- a/packages/core/src/tasks/v2-execution.ts +++ b/packages/core/src/tasks/v2-execution.ts @@ -63,6 +63,82 @@ import { taskV2VoteHostedError, } from "./v2-public.js"; +/** + * The order this client posted, for a funding that follows its own post. A first funding + * creates the clone from vAPI's copy of the order, so that copy must still be what was posted. + */ +export type TaskV2PostedOrder = { + title: string; + description: string; + deadlineAt: string; + shape?: string; + milestones?: ReadonlyArray<{ index: number; amountBaseUnits: string; deadlineAt: string }>; + bounty?: { + winners: number; + rewardPerWinnerBaseUnits: string; + deadlineAt: string; + choiceWindowSeconds?: number; + }; + pool?: { + rewardPerClaimBaseUnits: string; + budgetBaseUnits: string; + gate?: string; + verifier?: string; + openCheck?: string; + }; + workerBondBp?: number; +}; + +/** Refuses a funding whose hosted order no longer matches what this client posted. */ +export function assertPostedOrder( + order: { title?: unknown; description?: unknown; terms?: unknown; market?: unknown }, + posted: TaskV2PostedOrder, +) { + const terms = (order.terms ?? {}) as Partial; + const text = (value: unknown) => (typeof value === "string" ? value.trim() : value); + const time = (value: unknown) => (typeof value === "string" ? Date.parse(value) : Number.NaN); + const milestones = (items: TaskV2PostedOrder["milestones"]) => + items?.map((m) => [m.index, m.amountBaseUnits, time(m.deadlineAt)]) ?? null; + const bounty = (b: TaskV2PostedOrder["bounty"]) => + b + ? [b.winners, b.rewardPerWinnerBaseUnits, time(b.deadlineAt), b.choiceWindowSeconds ?? null] + : null; + const pool = (p: TaskV2PostedOrder["pool"]) => + p + ? [ + p.rewardPerClaimBaseUnits, + p.budgetBaseUnits, + p.gate ?? "proven", + p.verifier ?? "poster", + p.openCheck ?? null, + ] + : null; + const market = z.object({ deadlineAt: z.string() }).safeParse(order.market); + const differs = [ + text(order.title) !== text(posted.title) && "title", + text(order.description) !== text(posted.description) && "brief", + (!market.success || time(market.data.deadlineAt) !== time(posted.deadlineAt)) && "deadline", + posted.shape !== undefined && (terms.shape ?? "task") !== posted.shape && "shape", + posted.milestones !== undefined && + canonicalJson(milestones(terms.milestones)) !== + canonicalJson(milestones(posted.milestones)) && + "milestones", + posted.bounty !== undefined && + canonicalJson(bounty(terms.bounty)) !== canonicalJson(bounty(posted.bounty)) && + "bounty terms", + posted.pool !== undefined && + canonicalJson(pool(terms.pool)) !== canonicalJson(pool(posted.pool)) && + "pool terms", + posted.workerBondBp !== undefined && + (terms.workerBondBp ?? 0) !== posted.workerBondBp && + "worker bond", + ].filter((field): field is string => typeof field === "string"); + if (differs.length) + v2GuardFailure( + `vAPI's copy of this order differs from what this client posted (${differs.join(", ")}). Nothing was signed.`, + ); +} + export type TaskV2ExecutionInput = { id: string; write?: TaskV2Action; @@ -70,6 +146,8 @@ export type TaskV2ExecutionInput = { prepared?: TaskV2Prepared; preparationKey?: string; expectedGrossBaseUnits?: bigint; + /** The order this client just posted; a funding signs only for that order. */ + postedOrder?: TaskV2PostedOrder; policy: { maxPerTaskUsd: number; approveAboveUsd: number }; caps: SpendCaps; wallet: WalletName; @@ -299,6 +377,8 @@ export function createTaskV2Executor(options: TasksChainOptions) { } const view = await client.getOrder(input.id); if (view.workOrder.id !== input.id) fail("The money view belongs to another task."); + if (action.action === "fund" && input.postedOrder) + assertPostedOrder(view.workOrder, input.postedOrder); const terms = view.workOrder.terms; const state = stateSchema.safeParse(view.workOrder.v2State); // An operation the API already holds as submitted or confirmed comes back without a diff --git a/packages/mcp/src/tools/tasks.ts b/packages/mcp/src/tools/tasks.ts index 684a2f2..43a0392 100644 --- a/packages/mcp/src/tools/tasks.ts +++ b/packages/mcp/src/tools/tasks.ts @@ -886,16 +886,17 @@ export function createTasksTools(options: TasksToolsOptions) { const postedAt = now(); const prepared = prepareTaskPost(input, postedAt); const ctx = await acting(input.wallet); + const order = { + title: input.title, + description: input.brief, + policyFamily: "general-digital" as const, + ...(input.shape !== undefined || input.milestones || input.proofSpec || input.checkin + ? prepared.terms + : {}), + ...(input.vendor === undefined ? {} : { invitedProviderAddress: input.vendor }), + }; const outcome = await postTask(ctx, { - order: { - title: input.title, - description: input.brief, - policyFamily: "general-digital", - ...(input.shape !== undefined || input.milestones || input.proofSpec || input.checkin - ? prepared.terms - : {}), - ...(input.vendor === undefined ? {} : { invitedProviderAddress: input.vendor }), - }, + order, amount: prepared.amount, deadlineAt: prepared.deadlineAt, ...(input.fund ? { fund: true } : {}), @@ -923,6 +924,7 @@ export function createTasksTools(options: TasksToolsOptions) { prepared: v2Prepared.data, preparationKey: outcome.fundingIdempotencyKey, expectedGrossBaseUnits: prepared.escrowAmount, + postedOrder: { ...order, deadlineAt: prepared.deadlineAt }, policy, caps: await spendCapsForWallet(options.wallets!, ctx.selected.name), wallet: ctx.selected.name, From 8b859fb5abaf442edcc24c16feea447b1a731d9d Mon Sep 17 00:00:00 2001 From: vAPI Development <336934719+vapi-development@users.noreply.github.com> Date: Wed, 2 Dec 2026 15:57:09 +0100 Subject: [PATCH 3/3] revert: take the field-level posted-order check out of this change The check compared a subset of fields and missed others that feed the terms hash, so it gave a false sense of binding. Binding a first funding to the order this client posted moves to its own change, for the approval and the ERC-3009 path together. Co-Authored-By: Claude Opus 5.5 Signed-off-by: vAPI Development <336934719+vapi-development@users.noreply.github.com> --- packages/cli/src/task.ts | 1 - packages/core/src/tasks/v2-execution.test.ts | 59 +-------------- packages/core/src/tasks/v2-execution.ts | 80 -------------------- packages/mcp/src/tools/tasks.ts | 20 +++-- 4 files changed, 10 insertions(+), 150 deletions(-) diff --git a/packages/cli/src/task.ts b/packages/cli/src/task.ts index ca64748..db9a7a8 100644 --- a/packages/cli/src/task.ts +++ b/packages/cli/src/task.ts @@ -831,7 +831,6 @@ async function taskCommandInner( prepared: v2Prepared.data, preparationKey: outcome.fundingIdempotencyKey, expectedGrossBaseUnits: prepared.escrowAmount, - postedOrder: { ...input, deadlineAt }, policy, caps: await spendCapsForWallet(target.store, target.name), wallet: target.name, diff --git a/packages/core/src/tasks/v2-execution.test.ts b/packages/core/src/tasks/v2-execution.test.ts index 714c253..90b468d 100644 --- a/packages/core/src/tasks/v2-execution.test.ts +++ b/packages/core/src/tasks/v2-execution.test.ts @@ -2599,25 +2599,7 @@ describe("a new clone funded by one authorization (hosted ERC-3009 funding)", () }, }; }); - expect( - await f.execute({ - ...f.input, - write: { action: "fund" }, - postedOrder: { - title: f.view.workOrder.title, - description: f.view.workOrder.description, - deadlineAt: DEADLINE, - shape: "pool", - pool: { - rewardPerClaimBaseUnits: "20000000", - budgetBaseUnits: "100000000", - gate: "open", - verifier: "poster", - openCheck: "vapi-id", - }, - }, - }), - ).toMatchObject({ + expect(await f.execute({ ...f.input, write: { action: "fund" } })).toMatchObject({ ok: true, operation: { step: "v2-fund", state: "confirmed" }, }); @@ -2627,45 +2609,6 @@ describe("a new clone funded by one authorization (hosted ERC-3009 funding)", () expect(creation).toMatchObject({ to: POOL_FACTORY.toLowerCase() }); expect(funding).toMatchObject({ to: state.escrow }); }); - it.each([ - ["reward per claim", { rewardPerClaimBaseUnits: "10000000" }, {}], - ["verifier", { verifier: "vapi" }, {}], - ["deadline", {}, { deadlineAt: "2026-10-29T12:00:00.000Z" }], - ] as const)( - "refuses a first funding when vAPI's order changed the posted %s", - async (_field, poolChange, postChange) => { - const f = await fixture("v2-fund"); - const pool = { - rewardPerClaimBaseUnits: "20000000", - budgetBaseUnits: "100000000", - gate: "open", - verifier: "poster", - openCheck: "vapi-id", - }; - Object.assign(f.view.workOrder, { - terms: { shape: "pool", pool: { ...pool, ...poolChange } }, - market: { ...f.view.workOrder.market, deadlineAt: DEADLINE }, - v2State: undefined, - }); - authorizedFunding(f); - await expect( - f.execute({ - ...f.input, - write: { action: "fund" }, - postedOrder: { - title: f.view.workOrder.title, - description: f.view.workOrder.description, - deadlineAt: DEADLINE, - shape: "pool", - pool, - ...postChange, - }, - }), - ).rejects.toThrow(/differs from what this client posted/u); - expect(f.typedSign).not.toHaveBeenCalled(); - expect(f.sign).not.toHaveBeenCalled(); - }, - ); it("refuses to sign when the pinned factory predicts another clone for the accepted terms", async () => { const f = await fixture("v2-fund"); authorizedFunding(f); diff --git a/packages/core/src/tasks/v2-execution.ts b/packages/core/src/tasks/v2-execution.ts index a9d659e..425735e 100644 --- a/packages/core/src/tasks/v2-execution.ts +++ b/packages/core/src/tasks/v2-execution.ts @@ -63,82 +63,6 @@ import { taskV2VoteHostedError, } from "./v2-public.js"; -/** - * The order this client posted, for a funding that follows its own post. A first funding - * creates the clone from vAPI's copy of the order, so that copy must still be what was posted. - */ -export type TaskV2PostedOrder = { - title: string; - description: string; - deadlineAt: string; - shape?: string; - milestones?: ReadonlyArray<{ index: number; amountBaseUnits: string; deadlineAt: string }>; - bounty?: { - winners: number; - rewardPerWinnerBaseUnits: string; - deadlineAt: string; - choiceWindowSeconds?: number; - }; - pool?: { - rewardPerClaimBaseUnits: string; - budgetBaseUnits: string; - gate?: string; - verifier?: string; - openCheck?: string; - }; - workerBondBp?: number; -}; - -/** Refuses a funding whose hosted order no longer matches what this client posted. */ -export function assertPostedOrder( - order: { title?: unknown; description?: unknown; terms?: unknown; market?: unknown }, - posted: TaskV2PostedOrder, -) { - const terms = (order.terms ?? {}) as Partial; - const text = (value: unknown) => (typeof value === "string" ? value.trim() : value); - const time = (value: unknown) => (typeof value === "string" ? Date.parse(value) : Number.NaN); - const milestones = (items: TaskV2PostedOrder["milestones"]) => - items?.map((m) => [m.index, m.amountBaseUnits, time(m.deadlineAt)]) ?? null; - const bounty = (b: TaskV2PostedOrder["bounty"]) => - b - ? [b.winners, b.rewardPerWinnerBaseUnits, time(b.deadlineAt), b.choiceWindowSeconds ?? null] - : null; - const pool = (p: TaskV2PostedOrder["pool"]) => - p - ? [ - p.rewardPerClaimBaseUnits, - p.budgetBaseUnits, - p.gate ?? "proven", - p.verifier ?? "poster", - p.openCheck ?? null, - ] - : null; - const market = z.object({ deadlineAt: z.string() }).safeParse(order.market); - const differs = [ - text(order.title) !== text(posted.title) && "title", - text(order.description) !== text(posted.description) && "brief", - (!market.success || time(market.data.deadlineAt) !== time(posted.deadlineAt)) && "deadline", - posted.shape !== undefined && (terms.shape ?? "task") !== posted.shape && "shape", - posted.milestones !== undefined && - canonicalJson(milestones(terms.milestones)) !== - canonicalJson(milestones(posted.milestones)) && - "milestones", - posted.bounty !== undefined && - canonicalJson(bounty(terms.bounty)) !== canonicalJson(bounty(posted.bounty)) && - "bounty terms", - posted.pool !== undefined && - canonicalJson(pool(terms.pool)) !== canonicalJson(pool(posted.pool)) && - "pool terms", - posted.workerBondBp !== undefined && - (terms.workerBondBp ?? 0) !== posted.workerBondBp && - "worker bond", - ].filter((field): field is string => typeof field === "string"); - if (differs.length) - v2GuardFailure( - `vAPI's copy of this order differs from what this client posted (${differs.join(", ")}). Nothing was signed.`, - ); -} - export type TaskV2ExecutionInput = { id: string; write?: TaskV2Action; @@ -146,8 +70,6 @@ export type TaskV2ExecutionInput = { prepared?: TaskV2Prepared; preparationKey?: string; expectedGrossBaseUnits?: bigint; - /** The order this client just posted; a funding signs only for that order. */ - postedOrder?: TaskV2PostedOrder; policy: { maxPerTaskUsd: number; approveAboveUsd: number }; caps: SpendCaps; wallet: WalletName; @@ -377,8 +299,6 @@ export function createTaskV2Executor(options: TasksChainOptions) { } const view = await client.getOrder(input.id); if (view.workOrder.id !== input.id) fail("The money view belongs to another task."); - if (action.action === "fund" && input.postedOrder) - assertPostedOrder(view.workOrder, input.postedOrder); const terms = view.workOrder.terms; const state = stateSchema.safeParse(view.workOrder.v2State); // An operation the API already holds as submitted or confirmed comes back without a diff --git a/packages/mcp/src/tools/tasks.ts b/packages/mcp/src/tools/tasks.ts index 43a0392..684a2f2 100644 --- a/packages/mcp/src/tools/tasks.ts +++ b/packages/mcp/src/tools/tasks.ts @@ -886,17 +886,16 @@ export function createTasksTools(options: TasksToolsOptions) { const postedAt = now(); const prepared = prepareTaskPost(input, postedAt); const ctx = await acting(input.wallet); - const order = { - title: input.title, - description: input.brief, - policyFamily: "general-digital" as const, - ...(input.shape !== undefined || input.milestones || input.proofSpec || input.checkin - ? prepared.terms - : {}), - ...(input.vendor === undefined ? {} : { invitedProviderAddress: input.vendor }), - }; const outcome = await postTask(ctx, { - order, + order: { + title: input.title, + description: input.brief, + policyFamily: "general-digital", + ...(input.shape !== undefined || input.milestones || input.proofSpec || input.checkin + ? prepared.terms + : {}), + ...(input.vendor === undefined ? {} : { invitedProviderAddress: input.vendor }), + }, amount: prepared.amount, deadlineAt: prepared.deadlineAt, ...(input.fund ? { fund: true } : {}), @@ -924,7 +923,6 @@ export function createTasksTools(options: TasksToolsOptions) { prepared: v2Prepared.data, preparationKey: outcome.fundingIdempotencyKey, expectedGrossBaseUnits: prepared.escrowAmount, - postedOrder: { ...order, deadlineAt: prepared.deadlineAt }, policy, caps: await spendCapsForWallet(options.wallets!, ctx.selected.name), wallet: ctx.selected.name,