Skip to content

feat(unbind): say whether a USDC approval to the agent's wallet is still live on chain (R4) - #1559

Merged
DealAppSeo merged 3 commits into
mainfrom
claude/r4-unbind-allowance
Nov 16, 2026
Merged

DealAppSeo merged 3 commits into
mainfrom
claude/r4-unbind-allowance

Conversation

@DealAppSeo

@DealAppSeo DealAppSeo commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner

Owner action

You decide (MAJOR: changes what the unbind answer tells an owner about their money). Draft. Do not auto-merge. No flag: the unbind still revokes exactly as before, and its JSON gains one field, onchain_approval.

The question (W5)

In wallet mode (AGENT_SPEND_SOURCE=wallet), the owner gives each agent wallet a USDC approval. Does an unbind leave that approval live on chain?

Yes, by construction [V code]. DELETE /api/v1/human/bind/:agentId calls revokeBinding, which writes revoked_at on the binding and nothing else. An ERC-20 approval changes only when the owner's wallet calls approve, or when the spender uses it up. The engine cannot set it to 0, because that needs the owner's signature.

What already stops misuse: the spend route refuses every spend by an unbound agent (not_bound), and a later owner's spends draw from that owner's wallet, not the old one. But the agent wallet's key is still custodied by the engine, so "nothing can spend it" is a claim about this code, not about the chain.

Today [V on chain, block 59404267, read-only]: every owner → agent-wallet pair on record (7, including the one revoked binding) has allowance 0. The E2E runs so far used stake mode, which has no approval at all. So nothing is exposed now; this is about the first wallet-mode owner.

The fix: the receipt states it plainly

After a successful revoke, the answer reads allowance(owner, agentWallet) from Base Sepolia (bounded at 10 s) and adds:

  • { checked: true, live: true, allowance_usdc, agent_wallet, statement, how_to_end }: "Unbinding does not change your on-chain USDC approval… up to X USDC… stays live until your wallet sets it to 0". How to end it: USDC.approve(<agent wallet>, 0).
  • { checked: true, live: false, allowance_usdc: "0.0" }: nothing live (stake mode).
  • { checked: false, reason }: RPC down, wrong chain, timeout, or an unreadable agent row. It says the approval may still be live, never "0".

Tests

tests/unbind-approval.test.ts, 6 tests: live approval stated with amount and the exact call; 0 in stake mode; failed read, wrong chain, missing owner wallet and timeout are all NOT_CHECKED. Together with the existing agent-spend, agent-spend-from-stake and auth-agent-spend-path suites: 86/86. tsc --noEmit clean. The function is new, so the test fails on origin/main at import. Route wiring is one call after revokeBinding; no route test exists for unbind, because its auth (principalOf) needs a wallet-signed request.

Grok review (fenced lane, v4)

r1 on aec2d617: NO_FINDINGS (spec: who may unbind unchanged; "nothing live" only after a successful read on chain 84532 that returned 0, or a successfully read agent row with no wallet; every failure NOT_CHECKED; a non-zero allowance stated with approve(agentWallet, 0)).

Strix (LOW): confirmed, fixed in 1a4e4b54. On a failed read, the unbind answer echoed the raw ethers error, which embeds the request URL and so any API key in a provider URL. The reason is now classified ("the RPC read failed" / "did not answer in time"), and the raw text goes only to the server log. A test with a keyed URL in the error fails on the previous source; 7/7 pass. Threads replied to and resolved. No Grok round covers 1a4e4b54 yet.

Not done (follow-up if you want "sets it to 0 in the same flow")

USDC on Base Sepolia is FiatToken v2, which supports EIP-2612 permit. The owner could sign permit(owner, agentWallet, 0, deadline) at unbind, and the escrow could submit it gaslessly. That is the same pattern as the gasless deposit (#1558). I kept this PR to the statement because it needs no new signature flow, and stake mode (the default) has nothing to zero.

🤖 Generated with Claude Code

…ill live on chain

Unbinding writes revoked_at and nothing else. In AGENT_SPEND_SOURCE=wallet the owner gave the
agent's wallet a USDC approval, and only the owner's wallet can lower it, so the approval outlives
the unbind. This server already refuses every spend by an unbound agent, but the agent wallet's key
is still custodied here, so the unbind answer now reads the allowance from the chain and states it,
with how to end it (USDC.approve(agentWallet, 0)). Stake mode has no approval and reads 0.

A failed read (RPC down, wrong chain, timeout, unreadable agent row) is NOT_CHECKED and says the
approval may still be live; never "0". The revoke itself is unchanged and happens first.

Measured 2026-11-16 (block 59404267): every owner -> agent wallet pair on record, the one revoked
binding included, reads 0; the E2E runs so far used stake mode.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@DealAppSeo
DealAppSeo marked this pull request as ready for review November 16, 2026 05:04
@strix-security

strix-security Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Strix Security Review

To fix before merging (1)

PR summary: Makes the agent-unbind endpoint report whether the owner's on-chain USDC approval to that agent's wallet is still live: after revoking the binding it reads allowance(owner, agentWallet) from Base Sepolia (10 s bound) and adds an `onchain_approval` field stating the amount and how to zero it, or a "not checked" reason when the read cannot be trusted.

Review summary

Reviewed the unbind receipt change end to end: the new approvalAfterUnbind/approvalForAgentRow helpers and their wiring in DELETE /api/v1/human/bind/:agentId. The ownership gate and signed-path binding still protect the new agent-row read and the chain read; no address, amount or reason in the new field is attacker-steerable, and every failure branch degrades to "not checked / may still be live" rather than to zero. One issue remains: the same raw ethers error text that this PR now classifies on the unbind path is still interpolated into the gate detail of the public, unauthenticated lane allowance report, which can disclose the configured RPC provider URL and any API key in it. Error-text echoes on the authenticated bind/revoke and spend paths, the unchecked affected-row count in revokeBinding, and the per-request ethers provider were each examined and found not to be a security issue for this change.

1 resolved finding
Ruled out (3)
  • Does the unbind receipt return raw Postgres error text to the caller?
    The changed line returns the same object and HTTP status that `main` already returned from `revokeBinding`, and the error text originates in an untouched file, so the PR neither introduces nor widens the disclosure, and only the proven owner can trigger it for their own binding.
  • Can an unchecked affected-row count in `revokeBinding` make the new allowance statement wrong?
    The new field comes from an independent on-chain read with a not-checked answer on every failure path, and the zero-row case needs the same authenticated owner to revoke the same binding twice, ending in the state they are told.
  • Does the per-request ethers provider create a resource-exhaustion risk?
    The retry loop only starts when network detection fails, clears on the first successful answer, and the attacker controls neither the RPC URL nor the endpoint's health, so accumulation is bounded by the outage window.
Review history (3)
  • Review 3 · a381261 · Nov 16 09:19 UTC · Found 1 new Low Vulnerability
  • Review 2 · 1a4e4b5 · Nov 16 05:38 UTC · Fixed 1
  • Review 1 · aec2d61 · Nov 16 05:11 UTC · Found 1 Low Vulnerability

Fixed the findings? re-run the review, or tag @strix-security in a PR comment to run a fresh review.

Review 3 on this PR · a381261 · requested Nov 16 09:14 UTC on a new commit


Reviewed by Strix
Re-run review · Configure security review settings · Try a deeper review with @strix-security /deep

@strix-security strix-security Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strix flagged a new security finding below. See the pinned summary comment for the full PR status.

Comment thread src/services/agent-spend.ts Resolved
Comment thread src/routes/v1/byok.ts Resolved
… on #1559)

ethers puts the request URL in its error message, and a provider URL can carry an API key, so the
unbind answer now says only 'the RPC read failed' or 'did not answer in time'; the raw text goes to
the server log. Test fails on the previous source.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@strix-security strix-security Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the unbind receipt change end to end: the new approvalAfterUnbind reader, its wiring into DELETE /human/bind/:agentId, and the accompanying tests. The previous review's finding that a failed chain read returned the raw ethers error (and with it the configured RPC provider URL and any key inside it) is fixed in this commit — the catch block now reduces the failure to a fixed two-word reason, sends the raw text only to the server log, and a regression test asserts no URL or key can appear in the response. No new security issues were found: the added work all runs after the existing wallet-proof ownership gate, reads only the agent that gate just proved the caller owns, exposes no value that is not already public or already the caller's own, and every failure path fails closed to "not checked, may still be live" rather than to a claim that nothing is approved. One pre-existing raw database error echo sits a few lines above the changed code in the same handler; it was weighed and found to be outside this pull request's changes and reach, leaking only the caller's own input.


Reviewed by Strix
Configure security review settings

DealAppSeo added a commit that referenced this pull request Nov 16, 2026
…sion after the in-lock re-check

- No chain, DB, relay or credit error text reaches a gasless answer; it is logged server-side. ethers
  puts the request URL in its messages and a provider URL can carry an API key (the class Strix
  found on #1559). depositStake's error can carry verifyDeposit's raw RPC text too, so it is logged.
- The admission slot is now taken after the in-lock authorizationState re-check, just before the
  relay, so a concurrent replay refused there uses no slot (Grok r3 on #1558).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@DealAppSeo

Copy link
Copy Markdown
Owner Author

Grok review (fenced lane) round 2 on 1a4e4b54: CHALLENGED, 1 finding, CONFIRMED (low)

Run by Claude Code through the fenced wrapper (grok-review.v4.mjs, reviewer profile, read-only, MCP off). The wrapper accepted the answer: the nonce matched, the checkout was on 1a4e4b54f81b20649b09e8aab02414e4d13a1296, and every cited file was opened. Round 1 was on aec2d617. This round adds the no-echo fix (Strix): a failed approval read answers one of two fixed phrases, and the raw RPC error goes only to the server log.

Evidence:

  • r4.r2.test-output-head.txt: 7/7 pass on head.
  • r4.r2.test-output-old-src.txt: the same tests against the pre-fix approvalAfterUnbind. The no-echo test fails with the RPC URL in the reason.
Grok Finding Adjudication
R3-1 (high) src/routes/v1/byok.ts:623: if the repid_agents read returns no error and no row, a null wallet goes into approvalAfterUnbind, which answers checked: true, live: false, 0.0 ("this agent has no wallet"). No wallet was read and no chain was queried. Confirmed, severity low. The spec allows "no approval" only for a row read successfully with no wallet; a missing row is not that. It is reachable only in a race. human_agent_bindings.agent_id is FOREIGN KEY … REFERENCES repid_agents(id) ON DELETE CASCADE [V], and 0 of the 7 bindings lack an agent row [V], so the row exists when the owner is read. It can be missing only if the agent is deleted between the owner read and the wallet read.

The no-echo change itself: no finding.

Fix: a missing agent row answers checked: false with a fixed reason. The fix will come with a test that fails on this head and a new Grok round, both on the new SHA.

Not merged, and auto-merge is off.

… (Grok r2 on #1559)

The unbind route passed a missing repid_agents row to approvalAfterUnbind as a null wallet, which
answers "this agent has no wallet, so no approval can exist" without reading anything. The binding's
FK cascades from repid_agents, so the row can be missing only if the agent is deleted between the
owner read and the wallet read, but the statement was still false there. approvalForAgentRow now owns
the three cases: read error or no row -> NOT_CHECKED (no chain read); a row with no wallet -> no
approval; a row with a wallet -> read the chain.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@DealAppSeo

Copy link
Copy Markdown
Owner Author

@strix-security please re-review head a381261 (fix for Grok r2 R3-1: a missing agent row on unbind is NOT_CHECKED).

@strix-security strix-security Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strix flagged a new security finding below. See the pinned summary comment for the full PR status.

Comment thread src/services/agent-spend.ts Resolved
Comment thread src/routes/v1/byok.ts Resolved
@DealAppSeo

Copy link
Copy Markdown
Owner Author

Grok review (fenced lane) round 3 on a3812614: NO_FINDINGS

a3812614 fixes round 2's confirmed R3-1. approvalForAgentRow now owns the agent-row cases, and the DELETE handler calls it:

  • a read error, or no row, answers checked: false with a fixed reason and no chain read;
  • a row read with no wallet means no approval can exist;
  • a row with a wallet goes to approvalAfterUnbind.

Run by Claude Code through the fenced wrapper (grok-review.v4.mjs, reviewer profile, read-only, MCP off). The wrapper accepted the answer: the nonce matched, the checkout was on a3812614aeea8909c64552b751a44703e4c9207f, and all 8 cited files were opened.

Spec covered:

  • R1–R2: who may unbind is unchanged, and so is revoke.
  • R3: a missing row or a failed read is NOT_CHECKED, with no chain call.
  • R4: "no approval" only for a chain read of 0 on 84532, or for a row read with no wallet.
  • R5: no error text in onchain_approval.
  • R6: a live approval is stated with approve(agentWallet, 0).
  • R7: the tests cover all of this.

Evidence:

  • r4.r3.test-output-head.txt: 11/11 pass.
  • r4.r3.test-output-old-src.txt: the same tests against agent-spend.ts and byok.ts at 1a4e4b54. The 4 new tests fail there because the helper does not exist on that source. The old route's missing-row answer, "no wallet, so no approval", is what the existing no-wallet assertion pins.

Result: NO_FINDINGS, nothing listed as not checked. My adjudication: agree.

Gates on a3812614 now:

  • Strix: re-review passed.
  • Claude: fixed the confirmed finding; tsc clean.
  • Grok r3: NO_FINDINGS.
  • CI: green except test, still running at the time of this comment.

This is the only push to #1559 tonight. Not merged, and auto-merge is off.

DealAppSeo added a commit that referenced this pull request Nov 16, 2026
#1558)

* feat(stake): gasless owner deposit via USDC EIP-3009 (GASLESS_DEPOSIT_MODE, default off)

A newcomer has testnet USDC and no ETH. The owner signs a transferWithAuthorization (owner ->
stake escrow) in their wallet; POST /api/v1/stake/deposit/gasless checks it, the escrow submits it
and pays the gas, and depositStake's verified path credits it.

Nothing new verifies a signature: verifyEip3009Local (the x402 path) checks it against USDC's
name/version read from the chain and matched to its DOMAIN_SEPARATOR (resolveAndVerifyDomain).
The send is the escrow's guarded path: realSender's body is now escrowCall, shared by the refund,
the stake payout and the relay, and the relay joins the same one-at-a-time queue (one nonce).

Refused before the escrow spends gas: wrong recipient, zero amount, expired or expiring within
120 s, bad signature, no account for the payer, nonce already used on chain (replay), balance too
low, any unreadable read. A concurrent second submission of one authorization is serialized and
refused. off: refused without reading. shadow: every check, nothing sent. on: submit, credit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(stake): a gasless deposit whose credit throws still returns its tx hash (Grok r1 lead on #1558)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(stake): gasless deposits have a 1 USDC floor and a bounded share of the escrow queue (Strix on #1558)

The keyless route refused only value <= 0, so a 1-micro-USDC authorization made the escrow pay a
full transaction; and the per-authorization lock never makes two different authorizations wait, so
a caller could queue more escrow sends than one signer drains, ahead of refunds and agent payouts.

- MIN_GASLESS_DEPOSIT = 1 USDC, refused before any send.
- createGaslessAdmission(4/min), process-wide, injected as deps.admit: past it, 429 escrow_busy and
  nothing is queued. Shadow mode and refused deposits use no admission.

Not changed: depositStake and the owner-signed withdraw have no floor of their own; withdrawal needs
the owner's signature, so it is not this keyless path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(stake): gasless answers never carry chain/relay error text; admission after the in-lock re-check

- No chain, DB, relay or credit error text reaches a gasless answer; it is logged server-side. ethers
  puts the request URL in its messages and a provider URL can carry an API key (the class Strix
  found on #1559). depositStake's error can carry verifyDeposit's raw RPC text too, so it is logged.
- The admission slot is now taken after the in-lock authorizationState re-check, just before the
  relay, so a concurrent replay refused there uses no slot (Grok r3 on #1558).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(stake): one gasless admission slot per payer per minute, on top of the global cap (Strix on #1558)

One wallet could take all 4 global slots with concurrent deposits the escrow then refused, keeping
the keyless route at 429 for everyone else. createGaslessAdmission(4, 1) now also bounds each payer
(case-insensitive) to 1 a minute; rotating wallets still meets the global cap, and each wallet needs
an account and the USDC it signs for. Tests fail on the previous source.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(stake): name the per-payer admission variable for what it holds (a wallet), not 'key'

credential-safety-architecture flagged `r.payer === key` as a secret comparison. It compares wallet
addresses, so the variable is renamed rather than allowlisted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@DealAppSeo
DealAppSeo merged commit af0a746 into main Nov 16, 2026
19 checks passed
@DealAppSeo
DealAppSeo deleted the claude/r4-unbind-allowance branch November 16, 2026 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant