Dev.to AI πŸ€– Ai πŸ‘ 0 πŸ“– 6 min read

Give your AI agent the cancel, not the key

A finance team approves Friday's vendor payments on Monday. On Tuesday an email arrives from the vendor's real mailbox: "confirming Friday's payment goes to the updated payout address… please don't call, just reply here.

A finance team approves Friday's vendor payments on Monday. On Tuesday an email arrives from the vendor's real mailbox: "confirming Friday's payment goes to the updated payout address… please don't call, just reply here." On a stablecoin chain, once that payment lands, nobody can pull it back.

The obvious fix in 2026 is an AI agent that reads the inbox and reacts. The obvious problem is that an agent reading attacker-written email is the most prompt-injectable thing you can build, and the usual guardrail ("give it a session key with a spend cap") still lets a hijacked agent pay up to the cap.

I built Brake for the QDay Aevum Builder Challenge around a different idea: don't give the agent a key that can pay. Give it the cancel.

The primitive: EIP-3009's cancelAuthorization

USDC-style tokens (Circle's FiatToken v2) implement EIP-3009. Besides transferWithAuthorization, a signed payment anyone can submit, it has a less famous sibling: cancelAuthorization(authorizer, nonce, v, r, s). It marks a nonce as used, so a payment signed with that nonce can never execute.

Two properties make it useful:

  1. A payment authorization can be time-locked with validAfter, so it cannot clear before payday.
  2. A cancel signed by the payer can be submitted by anyone.

The second one is the whole design, so I tested it first. On Aevum testnet (chain 44005), tUSD8 is a FiatToken clone. A cancel signed by the payer was submitted from an unrelated EOA (tx) and through a contract (tx). In both cases the paired payment then reverted (tx). The same gate runs as 7 Foundry tests.

Sign the payment and its cancel together

For every line of a payment run, finance signs two EIP-712 messages once, over the same nonce:

/** Sign one line: the payment and the cancellation that can stop it, over the same nonce. */
export async function signPair(
  account: Account,
  domain: TokenDomain,
  line: { to: Address; value: bigint; validAfter: bigint; validBefore: bigint; nonce?: Hex },
): Promise<SignedPair> {
  const authorization: Authorization = {
    from: account.address,
    to: line.to,
    value: line.value,
    validAfter: line.validAfter,
    validBefore: line.validBefore,
    nonce: line.nonce ?? randomNonce(),
  };
  const payment = await signTransferAuthorization(account, domain, authorization);
  const cancel = await signCancelAuthorization(account, domain, authorization.nonce);
  return { authorization, payment, cancel, /* digests */ };
}

The payment signature goes to a keeper that submits it on payday. The cancel signature goes to the stop path. The agent never sees a payment signature, holds 0 tUSD8, and has no allowance. The worst a hijacked agent can do is delay a line. It cannot create a payment or change where one goes, because those are fixed inside signatures it never had.

The contract: the agent's only lever

The agent doesn't call the token directly. It calls Brake.stop, which checks the agent's grant (per-run, with an expiry and a stop budget), then submits the payer's cancel:

if (token.authorizationState(run.payer, l.nonce)) {
    // used (paid) or cancelled outside Brake; the reconciler reads logs
    l.status = Status.CONSUMED;
    emit StopConsumed(runId, idx, reason, evidenceHash, msg.sender);
    return Status.CONSUMED;
}

if (byAgent) {
    if (run.stops >= run.maxStops) revert StopBudgetExhausted();
    run.stops += 1;
}
l.status = Status.STOPPED;

token.cancelAuthorization(run.payer, l.nonce, v, r, s); // reverts on a bad signature: nothing changes

emit LineStopped(runId, idx, reason, evidenceHash, msg.sender);
if (byAgent && run.stops == run.alarmAt) emit StopAlarm(runId, run.stops);
_receipt(runId, idx, RESPONSE_STOP, reason, evidenceHash, uri);

A few details that came out of testing:

  • The stop budget (maxStops) caps how many lines a hijacked agent can cancel per run. Hitting it turns the next attempt into an on-chain HOLD for finance, not a stop.
  • CONSUMED, not a lie. If the payment already cleared, the stop lands on a used nonce. Brake records that, and the reconciler reads tUSD8's AuthorizationUsed log and marks the line TOO LATE with a recovery ticket. The agent never claims a stop it didn't make.
  • Every decision is a receipt. Each ALLOW, HOLD or STOP writes an ERC-8004 Validation Registry response (100 / 50 / 0) with a reason code and an evidence hash.

The model reads; it doesn't decide

The agent has a rules layer (unverified bank change, lookalike sender, disputed invoice, blacklisted payee…) and a model layer. The model's whole interface is one strict-schema tool:

export const RECORD_FINDINGS_TOOL = {
  name: "record_findings",
  description: "Record what the linked messages mean for each payment line. Call exactly once.",
  strict: true,
  input_schema: {
    type: "object" as const,
    properties: {
      findings: {
        type: "array",
        items: {
          type: "object",
          properties: {
            line: { type: "integer", description: "line index" },
            intent: { type: "string", enum: [...INTENTS] },
            quotes: { /* message_id + verbatim text */ },
            note: { type: "string", description: "one sentence, plain English" },
          },
          // ...

There is no pay tool, no signature, no free-form action. Deterministic code then decides:

  • Every quote the model cites must appear verbatim in the message. A paraphrased or misattributed quote is dropped.
  • Rules are consulted first, and no model output can turn a rule STOP into ALLOW or HOLD. A fast-check property test runs that against 10,000 generated model outputs.
  • An unverified finding never ALLOWs. A model failure never becomes ALLOW.

That last rule paid off on the live chain. The first live run failed: the model rejected the forced tool_choice the engine sent (HTTP 400), every review errored, and all four lines were held with no tUSD8 moved. The fix was to let the model choose its tool under the strict schema, with a missing tool call still holding the line.

Does the model actually matter?

This is the part I didn't expect. In the demo email, the vendor's compromised mailbox asks finance not to call, and adds a bracketed note addressed to the "payment assistant". The payee on file was phone-verified weeks earlier, so no rule fires.

From the 25-email injection suite (6 held-out emails committed before tuning):

Split Rules only With the model
Tune (n=19) 4/19 19/19, 0 false stops
Held-out (n=6) 2/6 6/6, 0 false stops

In the hero scenario, the model stops line 3 in 5 of 5 runs with 0 rules fired. Stub the model out and line 3 is ALLOWED and paid. n=25 is a regression suite, not a detection rate, and I say so in the repo.

The injection in the email doesn't help the attacker. The best it can do is suppress a stop only the model would have made. It can't reach a key that pays.

Live numbers

On Aevum testnet 44005, with claude-sonnet-5-5 through the Anthropic API:

  • Hero run, 71.1 s end to end: Monday ALLOW Γ—4 β†’ Tuesday email β†’ model-only stop (tx) β†’ lines 1, 2 and 4 paid in one Multicall3 batch (tx) β†’ line 3's replay reverts with the token's own FiatTokenV2: authorization is used or canceled (tx) β†’ finance re-issues line 3 to the verified wallet and it pays.
  • Email to agent stop confirmed: p50 4,987 ms, p95 10,093 ms (n=10).
  • Gas: a stop that cancels is about 183,000.
  • Agent-initiated transfers: 0.
  • Tests: 131 (forge 50, signer 12, engine 69).

Honest limits

  • Brake prevents only what it detects. A fraud that neither rules nor model flag pays as it would without Brake. If the attacker had stayed silent, line 3 would have paid.
  • It acts only before payday. After that it can report TOO LATE, not claw back.
  • The stop budget binds only the Brake path. Raw cancel signatures live on the server, so a compromised server can cancel every line (a delayed run). It can't change a payee or an amount.
  • Demo mode is custodial on testnet. The non-custodial path (your key signs, the server stores only signatures) has run on a local fork, not yet live.
  • Privacy: vendor email text goes to the model API; only hashes go on-chain.
  • Issuer powers: the token issuer can pause or blacklist, which blocks payments and cancels alike.

The takeaway

When you scope an agent's power, ask whether it needs to act at all, or only to veto. Many tokens already ship a veto primitive. A pre-signed cancel turns "the agent might pay the wrong person" into "the agent might make a payment late", and a late payment can be fixed.

Try to trick it yourself: the live app has a composer where you can write an email as the vendor. The code, tests and every live transaction hash are in the repo.

πŸ“° Read the original article on Dev.to AI

Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.