Skip to content

fix(stake): gasless deposit follow-ups before the flag goes on (stacked on #1558) - #1564

Closed
DealAppSeo wants to merge 7 commits into
mainfrom
claude/r3b-gasless-followups
Closed

DealAppSeo wants to merge 7 commits into
mainfrom
claude/r3b-gasless-followups

Conversation

@DealAppSeo

Copy link
Copy Markdown
Owner

Owner action

You merge (MAJOR: money path), and only after #1558. This PR is stacked on #1558 (base claude/r3-gasless-deposit-eip3009). When #1558 squash-merges, retarget this PR to main with gh pr edit <this> --base main and rebase it. One decision is needed from you, item 4 below. Nothing here turns the flag on; GASLESS_DEPOSIT_MODE stays off by default.

What this is

These are follow-ups for #1558 from an independent review, to fix before GASLESS_DEPOSIT_MODE=on. They live here so #1558's reviewed head (64e02092) stays fixed for tonight's packet.

  1. A failed relay re-reads authorizationState before it says "no USDC moved". Anyone can submit a signed authorization, and its to is the escrow, so a revert can mean another submitter used it and the USDC moved.
    • used (or canceled) → 202 authorization_used_elsewhere
    • unreadable → 202 send_not_checked
    • only an unused authorization → 502 not_sent
  2. Chain id. verifyEip3009Local takes the EIP-712 chainId from NETWORK (getActiveNetwork), but the escrow sends only on Base Sepolia (84532). A server with NETWORK set to another chain, or to an unknown name, now refuses with 503 wrong_network before any chain read.
  3. The route catch-all (src/routes/v1.ts) answers a fixed message. The error text goes to the log only. ethers puts the RPC URL, and any key in it, in its messages.
  4. Decision for you: the global 4/min admission budget can be griefed. Four wallets, each with an account and 1 USDC, can hold every slot each minute and keep everyone else at 429. The escrow pays all the gas, and the griefers' USDC comes back by withdrawal. The per-payer slot only stops one wallet. This PR states it as a ponytail: ceiling in createGaslessAdmission and does not pick a fix. The options are to gate admission on something a rotated wallet cannot make for free (account age, a stake already held, a signed connect), or to charge the gas back from the deposit.
  5. escrow-refunder.ts header now names all three kinds of send on the escrow's one queue: refunds, gasless relays and agent payouts.

Evidence

  • E:\dev\reports\2026-11-16\r-loop\r3b.test-output-head.txt: 46/46 pass across the gasless, route, auth-bypass and relay suites.
  • r3b.test-output-old-src.txt: the new tests against feat(stake): gasless owner deposit via USDC EIP-3009, default off (R3) #1558's gasless-deposit.ts and v1.ts at 64e02092. 4 fail: used-elsewhere, re-read-fails, wrong-network and route catch-all. The still-unused → 502 control passes on both.
  • tsc --noEmit is clean.

Not merged by Claude. Strix and the fenced Grok review have not run on this PR yet.

🤖 Generated with Claude Code

DealAppSeo and others added 7 commits November 15, 2026 20:12
…_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>
…x hash (Grok r1 lead on #1558)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…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>
…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>
…f 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>
…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>
- A relay that fails re-reads authorizationState: used (or canceled) answers 202
  authorization_used_elsewhere, an unreadable state answers 202 send_not_checked, and only an
  unused one answers 502 "no USDC moved". A signed authorization can be submitted by anyone and
  pays the escrow, so a revert can mean the USDC did move.
- Refuse with 503 wrong_network unless NETWORK resolves to Base Sepolia: verifyEip3009Local takes
  the EIP-712 chainId from NETWORK while the escrow sends only on 84532.
- The route's catch-all answers a fixed message; the error text goes to the log.
- The global 4/min admission budget can be griefed by four funded wallets: stated as a ponytail
  ceiling with the upgrade options (a decision, not decided here).
- escrow-refunder.ts header names all three kinds of send on the escrow's one queue.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Base automatically changed from claude/r3-gasless-deposit-eip3009 to main November 16, 2026 16:46
@DealAppSeo

Copy link
Copy Markdown
Owner Author

Superseded by #1568. #1558 squash-merged, so this branch conflicted with main, and the guard blocks merging main into a branch. #1568 is the same commit cherry-picked onto main (identical diff, head 90dea71). The branch is kept; reopen this if you'd rather keep it here.

🤖 Addressed by Claude Code

@DealAppSeo DealAppSeo closed this Nov 16, 2026
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