Skip to content

fix(blockrun): remove default x402 payment cap - #684

Merged
jjcc123312 merged 1 commit into
mainfrom
codex/remove-blockrun-payment-cap
Aug 11, 2026
Merged

fix(blockrun): remove default x402 payment cap#684
jjcc123312 merged 1 commit into
mainfrom
codex/remove-blockrun-payment-cap

Conversation

@jjcc123312

Copy link
Copy Markdown

Problem / background

BlockRun x402 requests are rejected before signing whenever the upstream payment quote exceeds the hard-coded 5 USDC default cap. Request 202608110702314015628818268d9d62ioY87Dv quoted 13.8367 USDC for /v1/responses, causing the gateway to return HTTP 500 with amount 13836700 exceeds per-call cap 5000000.

Evidence / root cause

SignX402Payment and the image branch of Adaptor.DoRequest passed maxAmountAtomicUSDC into the shared payment validator. assertAmountWithinCap rejected the upstream 402 amount before creating an ERC-3009 signature, so the request failed without an on-chain charge.

Scope / design

  • Remove the default amount ceiling for BlockRun Chat, Responses, and image requests by passing a nil amount cap.
  • Keep positive decimal amount validation.
  • Preserve the Base/Base Sepolia network allowlist, Base USDC asset check, pay-to address validation, and authorization-window limits.
  • Preserve explicit caller-provided caps. The Seedance video path therefore retains its existing 10 USDC limit.
  • Add a regression test using the observed 13.8367 USDC quote and retain explicit-cap coverage.

Impact and risks

This intentionally expands wallet exposure: the default BlockRun paths will sign any positive amount advertised by an otherwise valid upstream 402 response. A compromised BlockRun service or TLS boundary could request a very large payment. The network, asset, recipient-shape, time-window, and ERC-3009 nonce protections remain, but they do not bound the single-transfer amount.

The change is multi-node safe: it introduces no shared mutable or process-local coordination state. Every router instance applies the same stateless validation after deployment, and ERC-3009 nonces continue to make each authorization single-use.

Validation

  • go test ./relay/channel/blockrun -run "Test(ValidatePaymentOption|LooksLikeEthAddress|ExtractPaymentRequired|ParsePrivateKey|CacheRequestBody|X402)" -count=1
  • go test ./relay/channel/blockrun -run "^$"
  • go test ./relay/channel/task/blockrunseedance/...
  • git diff --check
  • GitNexus change detection: one expected affected process, DoRequest -> SetupLogger; medium risk due relay-path behavior change.

The full go test ./relay/channel/blockrun/... suite still has existing image polling/download failures because the test environment leaves the global HTTP client uninitialized. The x402-specific tests and package compilation pass.

Acceptance criteria

  • A valid BlockRun 402 quote of 13.8367 USDC is accepted on Chat/Responses/image paths.
  • Invalid, zero, and negative amounts remain rejected.
  • Explicit amount caps remain enforceable for callers such as Seedance video.
  • Network, asset, pay-to, and authorization-window guards remain unchanged.

Production deployment recommendation

  • Router deploy: required.
  • Reason: this changes BlockRun relay payment signing for /v1 model and image traffic.
  • Other deploy targets: newapi-console, newapi-web, Terraform, and Cloudflare are not involved.
  • Risk / validation: high financial exposure if upstream advertises an abnormal amount; smoke-test a paid BlockRun Responses request in staging and confirm the quote, signature, response, and settlement log before production rollout.

@jjcc123312
jjcc123312 merged commit 4c2e4c1 into main Aug 11, 2026
1 check passed
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