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>
| throw new Error(`unsupported transaction type 0x${first.toString(16).padStart(2, '0')}`); | ||
| } | ||
|
|
||
| const UINT_FIELDS = ['chainId', 'nonce', 'gasLimit', 'value', 'maxFeePerGas', 'maxPriorityFeePerGas', 'gasPrice']; |
There was a problem hiding this comment.
🔴 - Critical | Remote signer binding is never enforced before broadcast
The new assertEvmSignedMatches and assertSolanaSignedMatches functions are not imported or called from src/trading.js. The Privy branches accept signed_transaction and the WalletConnect branches accept signedTransaction/signature data, then proceed to executeTransaction or wallet broadcast without comparing the returned bytes to the transaction that was preflighted and sent for signing. A compromised, buggy, or malicious remote signer could therefore substitute a different recipient, calldata, value, nonce, or Solana message and the CLI would broadcast it. The tests only validate the standalone helpers and do not cover their integration into the real signing paths.
| BROADCAST_FAILED: { group: 'trade', description: 'The transaction could not be broadcast.' }, | ||
| TX_REVERTED: { group: 'trade', description: 'The transaction reverted or failed on chain.' }, | ||
| TXHASH_MISMATCH: { group: 'trade', description: 'The RPC returned a different transaction hash than the one signed.' }, | ||
| SIGNED_TX_MISMATCH: { group: 'trade', description: 'The remote signer (Privy or WalletConnect) returned a transaction that differs from the one checked; the CLI did not broadcast it.' }, |
There was a problem hiding this comment.
🔵 - Low | Missing changeset for a user-facing trading security change
This PR changes trade execution behavior and adds a new public SIGNED_TX_MISMATCH error code, but no .changeset file is included. Per the repository instructions, user-facing bug fixes and output/error changes require a changeset so the published package and changelog reflect the change.
nansen-pr-reviewer summaryThe change adds signed-transaction binding helpers and a new error code, but the helpers are not integrated into any Privy or WalletConnect signing path. Remote signers can still return substituted transactions that proceed to broadcast, leaving the central security objective unenforced. The user-facing error-code change also lacks the required changeset. Findings by Severity
Deterministic check: failure — Found 2 critical severity finding(s) (max: 0) Risk: 5/5 (Critical) — raised by: complexity: 787 added lines Findings not posted inline
Token usage: 81,001 input, 1,530 output, 13,398 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 |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| BROADCAST_FAILED: { group: 'trade', description: 'The transaction could not be broadcast.' }, | ||
| TX_REVERTED: { group: 'trade', description: 'The transaction reverted or failed on chain.' }, | ||
| TXHASH_MISMATCH: { group: 'trade', description: 'The RPC returned a different transaction hash than the one signed.' }, | ||
| SIGNED_TX_MISMATCH: { group: 'trade', description: 'The remote signer (Privy or WalletConnect) returned a transaction that differs from the one checked; the CLI did not broadcast it.' }, |
There was a problem hiding this comment.
🔵 - Low | Missing changeset for the user-facing trading security change
This change adds the public SIGNED_TX_MISMATCH error code and changes trade execution safety behavior, but no .changeset file is included. Repository instructions require a changeset for user-facing bug fixes and output/error changes, so the published package changelog will not describe this change.
What
Adds
src/signed-tx-binding.js. It checks that the signed bytes a remote signer (Privy or WalletConnect) returns are the transaction the CLI sent it, signed by the expected wallet.assertSolanaSignedMatches): the message bytes after the signature section are identical, the signature count is the same, the wallet is one of the required signers, and the wallet's signature slot verifies (ed25519). The check uses the wallet's slot, not slot 0, because in an x402 payment the facilitator is the fee payer and the wallet signs a later slot.decodeSignedEvmTransaction,assertEvmSignedMatches):A mismatch throws the new error code
SIGNED_TX_MISMATCH(added tosrc/error-codes.js, withdocs/error-codes.mdregenerated).trade executetreats it as terminal: it does not move on to the next quote, which would go to the same signer.Also adds shared test helpers for the follow-up PRs:
fixtures/remote-signers.js: fixed test keys and signers that sign what a stub receives.fixtures/execute-harness.js: quote builders, a network stub that records what reaches the execute endpoint, and anexecute()wrapper.Why
On the Privy and WalletConnect paths, every pre-sign check (target, intent binding, value, fee cap, simulation) runs on the unsigned transaction. The signed bytes the signer returns were then broadcast as they came back. A response encoding a different transaction would have been broadcast unchecked.
Part 1 of 3
Nothing calls these checks yet, so this PR changes no behaviour. The next two PRs wire them in and open once this one merges:
Testing
src/__tests__/signed-tx-binding.test.js: 32 unit tests.npm test: 6368 passed.npm run lintandnpm run error-codes:checkare clean.No changeset in this PR. The user-facing changesets come with the Privy and WalletConnect PRs.
🤖 Generated with Claude Code