Repository navigation
Conversation
… it was sent Adds src/signed-tx-binding.js, which compares the signed bytes a remote signer (Privy, WalletConnect) returns with the transaction the CLI sent it: - Solana: identical message bytes and signature count, the wallet is one of the required signers, and its signature slot verifies (ed25519). - EVM: decode the signed transaction (replay-protected legacy, type 1 or type 2; blob and set-code transactions are refused), recover the sender, and compare it and the given fields with what was sent. A mismatch is a new error code, SIGNED_TX_MISMATCH, which execute treats as terminal. Nothing calls the checks yet; the Privy and WalletConnect changes that use them follow separately. Also adds the shared test helpers they use: honest test signers with fixed keys, and an execute harness. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Privy signs remotely and returns signed bytes, which the CLI broadcast as they came back. Every pre-sign check had run on the transaction sent for signing, so a response encoding a different transaction would have been broadcast unchecked. signEvmTransaction and signSolanaTransaction now take the wallet address and refuse a response that is not the transaction sent, signed by that wallet (SIGNED_TX_MISMATCH; nothing is broadcast). EVM: every field sent must match. Solana: same message, and the wallet's signature slot verifies (an x402 payment has the facilitator as fee payer, so the wallet signs a later slot). Every caller passes the wallet: swaps, approvals and allowance revokes, wallet send (Solana), limit orders and x402 payments. Tests sign with fixed test keys instead of returning placeholder bytes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| }, { from: walletAddress, label: 'swap transaction' }); | ||
| signedTransaction = signResult.data?.signed_transaction || signResult.signed_transaction; | ||
|
|
||
| } else if (chainType === 'solana') { |
There was a problem hiding this comment.
🟠 - High | WalletConnect signed transactions are not bound to the preflight-checked transaction
The new binding logic is only invoked from PrivyClient. In the WalletConnect trading path, the CLI validates txBase64 before asking the wallet to sign, but then directly assigns the returned signedTransaction and sends it to the Trading API without decoding it, comparing its message/fields, or verifying the expected wallet signature. A malicious, compromised, or buggy WalletConnect adapter can therefore substitute a different recipient, calldata, amount, or Solana message after the CLI's checks and before broadcast. The same gap exists for WalletConnect-backed wallet sends in transfer.js. This contradicts the changeset and error-code documentation claiming the protection covers WalletConnect.
nansen-pr-reviewer summaryThe diff adds strong binding checks for returned signed transaction bytes from Privy and WalletConnect, and covers the tested signing paths. However, WalletConnect still accepts hash-only responses from its send-and-broadcast path without verifying that the hash identifies the transaction the CLI preflighted, so a compromised or buggy adapter can still substitute a transaction while the CLI treats it as successful. Findings by Severity
Deterministic check: failure — Found 2 high severity finding(s) (max: 0) Risk: 4/5 (High) — raised by: complexity: 1522 added lines Token usage: 124,705 input, 2,043 output, 40,436 cache read | Usage Guide Cooldown: for the next 10 minutes (counting from when this review finished), new pushes to this PR will not trigger another review — the next push after the window expires will. Need a fresh review sooner? Comment |
…ore broadcasting it When a WalletConnect wallet returns signed bytes instead of broadcasting itself, the CLI broadcast them as they came back, although every pre-sign check had run on the transaction it sent the wallet. The send functions now take the wallet address and refuse returned bytes that are not signed by it or differ from what was sent (EVM: chain, recipient, value, calldata and gas limit; the wallet still picks nonce and fees. Solana: the same message). A signature-only Solana reply must verify. The error is SIGNED_TX_MISMATCH and says the wallet may have sent the transaction itself. A reply carrying only a hash is unchanged. Covers swaps, approvals, allowance revokes, wallet send and limit orders. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| if (parsed.signedTransaction) return { signedTransaction: parsed.signedTransaction }; | ||
|
|
||
| throw new Error('Unexpected response from walletconnect send-transaction'); | ||
| }); |
There was a problem hiding this comment.
🟠 - High | WalletConnect hash-only responses remain unbound to the preflight-checked transaction
The new validation only runs when WalletConnect returns signed transaction bytes. When the wallet returns transactionHash or txHash, the function returns that hash immediately and never fetches or decodes the corresponding transaction, verifies its sender, or compares its chain, recipient, value, calldata, and gas limit with the transaction the CLI checked. Because send-transaction may broadcast through the wallet before returning, a compromised or buggy WalletConnect adapter can substitute a different transaction and report its hash; the CLI then marks the quote executed and proceeds as though the checked transaction was broadcast. The same unverified hash path is used by WalletConnect-backed EVM transfers and approvals.
What
Privy and WalletConnect sign remotely and hand back signed bytes, which the CLI then broadcast as they came back. This PR checks that those bytes are the transaction the CLI sent, signed by the wallet, on every remote-signer path. A mismatch fails with the new error
SIGNED_TX_MISMATCHand nothing is broadcast. Execute treats it as terminal: it doesn't try the next quote, which would go to the same signer.The checks (
src/signed-tx-binding.js):Privy (
src/privy.js):signEvmTransactionandsignSolanaTransactiontake the wallet address and check the response.trade executeswaps, approvals and allowance revokeswallet sendon SolanaWalletConnect (
src/walletconnect-trading.js): when the wallet returns signed bytes, the send functions check them against the connected wallet.wallet sendand limit orders.Why
Every pre-sign check (target, intent binding, value, fee cap, simulation) runs on the transaction sent for signing. A signer response encoding a different transaction would have been broadcast unchecked. On WalletConnect, a gas limit lower than requested would make a swap revert and still burn fees.
Before / after
Why this isn't split
This PR is 1711 lines, over the usual 1000. It was split into three PRs: the shared checks (#848), Privy and WalletConnect (#850). Separately, each earlier part left the next part's paths open, so the review bot rated each one Critical or High. Together they close every remote-signer path in one step.
Of the 1711 lines, about 960 are tests:
Testing
signed-tx-binding.test.js: 32 unit tests.privy-signed-tx.test.jsandwalletconnect-signed-tx.test.js: execute-level tests with honest controls and substituted responses (table above). The refusal tests fail without the fix.npm test: 6399 passed. Lint and the error-code docs check are clean.🤖 Generated with Claude Code