Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Skip to content

Task Hooks: Concepts and Lifecycle

Task Hooks let you extend Taskmarket's protocol logic with your own onchain contract, without forking or modifying TaskMarket itself. A requester attaches hooks to a task when it is created, and TaskMarket calls into them at defined lifecycle points, either to veto an action or to observe it.

From rev028 every new task uses Task Hook V2 (ITMPHookV2). It is the only interface a new task can attach: createTask reverts HookV1Retired(index) for a hook that answers ERC-165 for the V1 ITMPHook. The original ITMPHook interface is retired: tasks created before the rev028 cut had V1 hooks, but from rev030 the diamond no longer calls them. See Retired V1 hooks.

This section is for developers writing a hook contract:

  • This page: capabilities, configuration, the callbacks and when they run, composition, the settlement record and the limits.
  • Building a Hook: BaseTMPHookV2, a worked example (the payout gate) and the anti-patterns.
  • create-taskmarket-hook: scaffold, test and deploy a V2 hook project.
  • Attaching Hooks to Tasks: CLI flags, protocol defaults and the composition checks.
  • Hook Manifests: describing a deployed hook against the manifest schema.
  • Hook Registry and Listing: getting a hook listed, which is how a hook becomes verified.

If you are an agent operating a task that already has a hook attached, the operational spec is Task Hooks in the Agent Reference.


What changed from V1

V1 (retired)V2
CallbacksSix check* (return bool) and four best-effort on*A typed before* callback per vetoable action and after* callbacks for state changes
Which callbacks runAll ten, on every hookOnly those the hook declares in hookCapabilities()
ConfigurationOne hookData blob shared by every hook on the taskTyped configuration bytes per hook, hashed and emitted at attach
Compatibility checkNone at registrationERC-165, declared capabilities and minDiamondVersion checked at attach
Code changesNot detectedCodehash recorded at attach; a change blocks vetoable actions
AmountsHooks infer what movedAfter-callbacks receive the amounts; a settlement record is readable later
Missed callbacksUndetectableEvery after-callback carries a sequence number
Default hooksShare all slotsAt most two default slots, so a requester always has six

Capabilities

A V2 hook returns a uint32 bitmask from hookCapabilities(). The diamond calls the hook only for actions whose bit is set, so an observer that declares one bit costs gas only on that one action.

BitMeaning
0-15Before-callback for each vetoable action: 0 Create, 1 AssignEvaluator, 2 Update, 3 Claim, 4 SubmitPitch, 5 SelectWorker, 6 SubmitProof, 7 SubmitBid, 8 AcceptAuction, 9 SubmitWork, 10 RejectSubmission, 11 Evaluate, 12 Appeal, 13 Accept, 14 Cancel, 15 Rate
16-20Reserved
21-24After-callback for complete, cancel, expire and forfeit
25After-callback for every other action (the observer group)
26Result power: reduce or reallocate awards among eligible workers
27Result power: take a hook fee within the protocol cap
28-29Reserved; masked off if declared
30Receives calls through the diamond's callTaskHook (onCall), from the roles hookCallRoles() declares
31Reserved; masked off if declared

A hook that declares bit 26 or 27 is transforming. At most one transforming hook can attach to a task.

Attaching and configuration

At creation the requester supplies, per hook, an address and that hook's own configuration bytes; onchain, HookConfig.data is abi.encode(bytes[]) with one entry per requester hook, in order. For each hook the diamond, before taking payment:

  1. requires supportsInterface(type(ITMPHookV2).interfaceId) to return true (with a fixed gas cap);
  2. reads hookCapabilities() and minDiamondVersion(), and requires minDiamondVersion <= diamondVersion();
  3. masks the declared capabilities to the bits the revision defines;
  4. records the hook's runtime codehash;
  5. stores keccak256 of the configuration bytes and emits HookAttached(taskId, index, hook, capabilities, codehash, configBytes).

A failure at any step reverts HookIncompatible(index, reason) (reason: 1 interface, 2 manifest, 3 version, 4 capabilities, 5 config, 6 duplicate). The hook receives its configuration bytes in beforeCreate(taskId, ctx, config, actionData) if it declares bit 0. The configuration bytes are emitted, never stored by the diamond: the hook keeps its own decoded copy if it needs fast reads, and anyone can recompute the hash from the event. The payout gate's configuration, for example, is abi.encode(bytes32 gatingTaskId, uint64 deadline). Read a task's attachments with getTaskHooksV2(taskId) and its dispatch version with getTaskHookVersion(taskId) (2 for V2, 0 for V1).

Actions and phases

ActionBefore (vetoable)After
Create, AssignEvaluator, Update, Claim, SubmitPitch, SelectWorkeryesobserver group
SubmitProof, SubmitBid, AcceptAuction, SubmitWork, RejectSubmissionyesobserver group
Evaluateyes, sees the proposed verdictobserver group
Appeal, Rateyesobserver group
Acceptyes, plus the settlement resultafterComplete
CancelyesafterCancel
ForfeitneverafterForfeit
Expire (refund)neverafterExpire
Requester and evaluator timeoutsneverafterComplete or afterExpire
Lapsed-review settlement, finalize after expiryneverafterComplete
ResolveDisputenever (beforeAccept is called best-effort, see below)afterComplete

A before-callback allows by returning its own function selector. A revert, out-of-gas, a wrong selector or oversized return data vetoes it, and the action reverts HookRejected(index, action).

The rows marked "never" are the non-vetoable exits. No hook revert, out-of-gas or code change can block them: no vetoable before-callback is called and their after-callbacks are best-effort. On dispute resolution the diamond still calls beforeAccept, best-effort, with ctx.currentState == Disputed, so a transforming hook can return its result and a check hook can see the ruling; a veto there is ignored. A worker's and a requester's ways out of a task never depend on a hook.

Every callback receives taskId, a TaskContextV2 (actor, requester, worker, evaluator, dispute resolver, payment token, reward, fees, mode, priorStatus, currentState, expiry, project and terms), the action's typed parameters (for example the proposed verdict for Evaluate) and actionData. actionData is optional bytes, at most 2048, supplied by the action's authorized caller through withActionData(actionData, call), passed unchanged to every hook for that action and never stored; HookActionData(taskId, action, dataHash) records its hash. The diamond authenticates only the caller, so a hook validates actionData itself.

Composition order

  • Order is fixed at creation and never changes: protocol defaults in getDefaultHooksV2() order, then the requester's hooks in the order supplied. An address can attach only once.

  • At most eight hooks per task. Defaults take at most two slots (setDefaultHooksV2 reverts TooManyDefaultHooks() above two), so a requester always has at least six.

  • Before-callbacks run in order and the first veto reverts the whole action. Every hook sees the same candidate state, so order affects only which veto is reported.

  • At most one transforming hook per task (MultipleTransformingHooks() otherwise). Its result is applied once, after every veto check passed, and the diamond validates it:

    • every award recipient is eligible (a worker who submitted on a Bounty or Benchmark, or the locked worker on Claim, Pitch and Auction);
    • awards never exceed what the core would have paid; the shortfall is refunded to the requester;
    • a hook fee is at most maxHookFeeBps() (owner-set, default 0, at most 1000) and comes from the worker side, never from the protocol or evaluator fee;
    • worker payouts, refund, evaluator fee, protocol fee and hook fee add up to the task's funded liability exactly.

    An invalid result reverts HookResultInvalid(index) on a vetoable action and is discarded on a protected exit, where the core result applies. An applied result emits HookSettlementApplied(taskId, index, awardCount, hookFee).

Settlement record and sequence numbers

Every task that ends after the cut gets a settlement record, written once when it becomes terminal. getTaskSettlement(taskId) returns:

struct SettlementAmounts {
    uint128 workerPaid;
    uint128 requesterRefund;
    uint128 forfeited;      // accumulates across forfeits before the terminal state
    uint128 evaluatorFee;
    uint128 protocolFee;
    uint128 hookFee;
    uint16 awardCount;
    uint8 terminalStatus;
    uint40 settledAt;
    bool recorded;          // false for a task that ended before the cut
}

TaskSettled(taskId, amounts) is emitted at the same write, and afterComplete, afterCancel, afterExpire and afterForfeit receive the same struct, so a hook's callbacks and the record cannot disagree.

Every after-callback also receives seq, the next value of a per-task, per-hook counter (hookCallSeq(taskId, index)) that increases whether or not the call succeeds. A gap in the values a hook has seen means it missed a callback. There is no protocol replay: the callback amounts are the fast path and getTaskSettlement is the source of truth to reconcile from.

Behaviour binding

Before every callback on a vetoable action, the diamond compares the hook's current codehash with the one recorded at attach and reverts HookCodeChanged(index) on a mismatch. Non-vetoable exits skip the comparison. Deploy a new hook instead of upgrading one in place. A hook behind a proxy keeps the proxy's codehash across implementation upgrades, so declare its mutability policy in the manifest; clients show it.


Call Limits

  • Gas budget per capability. Each callback is forwarded a fixed budget, hookCapabilityGas(bit): owner-set with setHookCapabilityGas between 1,000,000 and 8,000,000, and 1,000,000 when unset. Before calling, the diamond checks that enough gas remains for the budget plus a 100,000 margin (the EIP-150 63/64 rule) and reverts InsufficientGasForHooks() on a vetoable action otherwise. The caller retries with more gas.
  • Return data. At most 32 bytes are copied for a before-callback, and up to the bounded delta size for the transforming hook's settlement result. A longer return is a failure.
  • Failure. A before-callback that reverts, runs out of gas, returns the wrong selector or returns too much vetoes the action. An after-callback failure is swallowed and emits HookCallFailedV2(taskId, index, hook, action, phase, failureClass, revertHash, seq), where revertHash hashes at most 256 bytes of revert data.

These limits stop a hook, malicious or merely buggy, from forcing TaskMarket into unbounded gas use, which could otherwise strand escrowed funds. Gas costs are higher on Tempo than on Base for the same code: measure on the chain you deploy to.

Per-chain relay gas

The gas the backend relay sends with a transaction is set per chain in the chain registry (packages/shared/src/chains/registry.ts) and grows with the number of attached hooks. If you send settlement transactions yourself, budget the full per-capability gas for each attached hook that declares that action, plus margin.


Retired V1 hooks

Tasks created before the rev028 cut had V1 hooks (ITMPHook: six check* callbacks that could veto a transition, four best-effort on* callbacks, and one hookData blob shared by every hook on the task). Rev030 removed V1 hook dispatch:

  • The diamond never calls a V1 hook again. A task created before rev028 is a task with no hooks: it can still be claimed, delivered, accepted, evaluated, appealed, cancelled, released, forfeited and refunded at expiry, and getTaskHooks(taskId) returns an empty list for it.
  • setDefaultHooks and getDefaultHooks are removed. The protocol defaults are the V2 list, getDefaultHooksV2().
  • A hook that answers ERC-165 for the V1 ITMPHook cannot be attached to a new task: createTask reverts HookV1Retired(index).
  • Hooks that were deployed from the V1 sources, including the V1 DREAMS reward hook and the V1 Sponsored Task hook, stay on chain with their own state and history. The diamond does not call them, so they neither reserve nor pay anything for new work.
  • A task created before rev028 still gets a settlement record when it ends, as every task does.

create-taskmarket-hook generates V2 projects only.