Repository navigation
Conversation
On EdDSA MPCv2 wallets a Canton UTXO split failed client-side, before any
signing round, in two stages.
1. wallet.signAndSendTxRequest passes no txParams, so resolveEffectiveTxParams
(sdk-core) rebuilds recipients from the persisted intent. It read
recipient.address.address, which is undefined when the client stores the
address as a plain string (the retail split does), and Canton
verifyTransaction then crashed with "Cannot read properties of undefined
(reading 'split')". Accept both the { address } object and a plain string,
and copy numberOfSplits from the intent into the effective txParams (like
executorPartyId) so a coin verifier can validate the split count. Adds
numberOfSplits to TransactionParams and PopulatedIntent.
2. IMS builds a split as one root WalletUserProxy_BatchTransfer whose children
are numberOfSplits TransferFactory_Transfer self-transfers. verifyTransaction
only parsed the first transfer and compared it with the intent amount (the
full value of the selected unspents), so it failed with "Tx outputs do not
match with expected txParams recipients". Only the first transfer was ever
inspected, so further transfers in a batch were unverified too.
When txParams.numberOfSplits > 1, verify the whole batch: parseBatchTransfers
returns every transfer and throws unless the transaction has a single
BatchTransfer root whose children are all TransferFactory_Transfer. Each
transfer must go from the wallet's own address to itself, carry the expected
token, and the transfer count must equal numberOfSplits. The total must be
within less than numberOfSplits atomic units of the intent amount to allow for
rounding dust. numberOfSplits of 0 or 1 keep the existing recipient-matching
path. A recipient without an address now fails with a clear error instead of
the TypeError.
Tests use captured staging/test txRequests for a native split, a token split
and a multi-input token split, plus tampering cases (a transfer rewritten to a
foreign party, wrong count, amount, wallet or token).
Ticket: CHALO-2192
Co-Authored-By: Claude <noreply@anthropic.com>
There was a problem hiding this comment.
Claude Code Review
This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.
Tip: disable this comment in your organization's Code Review settings.
|
@claude review |
|
Claude finished @at31416's task in 18s —— View job Review of #10196: verify Canton split transactions as a batchI read the Should fix
Smaller points
Tests: per the PR description, they cover tampering with a foreign party, count, amount, wallet and token, plus three captured fixtures. I'd add two cases: one where the wallet has no |
|
|
| // Equal-value outputs may leave less than one atomic unit per split of rounding dust in the change holding. | ||
| const unsplit = new BigNumber(amount).minus(total); |
There was a problem hiding this comment.
🟡 (optional) A Canton split passes verification for any batch total when the expected amount is missing or not numeric. The amount check fails open. new BigNumber(amount) turns an undefined or non-numeric amount into NaN. Both isNegative() and gte(numberOfSplits) return false for NaN, so no error is thrown. Fix: reject the split unless the expected amount is a finite, non-negative integer string (BigNumber.isFinite()) before comparing totals. Then a broken or missing intent amount can no longer skip the check.
Why this was flagged
In verifySplitTransaction (canton.ts:289), amount comes from txParams.recipients[0]. On the TSS path resolveEffectiveTxParams sets it to intentRecipient.amount.value (recipientUtils.ts:157), a server-supplied value, and the code never checks that it exists or is numeric. If it is undefined or non-numeric, new BigNumber(amount) is NaN, unsplit at canton.ts:305 is NaN, and unsplit.isNegative() || unsplit.gte(numberOfSplits) is false. The 'does not match expected amount' error never fires, so the batch total goes unchecked and the split is approved for signing. The check is new in this PR. The other checks (sender, receiver, token, count) do not stand in for the amount bound.
Verification: nit. Trigger: the split recipient's amount reaches verifySplitTransaction as undefined or non-numeric. At canton.ts:307-309: const unsplit = new BigNumber(amount).minus(total); if (unsplit.isNegative() || unsplit.gte(numberOfSplits)) throw .... The error never fires and the method returns true. It is lost validation, not a fund-loss path.
| if (txParams.numberOfSplits !== undefined && txParams.numberOfSplits > 1) { | ||
| return this.verifySplitTransaction(transaction, txParams, params.wallet); | ||
| } |
There was a problem hiding this comment.
🟣 pre-existing, not blocking: pre-existing, security-relevant: a batch transfer with no split count is still checked only by its first transfer, so extra transfers go unverified. The batch check runs only when numberOfSplits > 1, and that value comes from the server-supplied intent. Otherwise the recipient path compares just the first TransferFactory_Transfer that parseRawCantonTransactionData finds. Fix: in the regular Send path, reject any prepared transaction whose root is WalletUserProxy_BatchTransfer or that has more than one TransferFactory_Transfer, or else verify every transfer, so leaving out numberOfSplits cannot skip the batch check.
A small fix can ride a push you are already making; otherwise a short reply is enough.
Why this was flagged
The split branch at canton.ts:225 only runs when txParams.numberOfSplits > 1. resolveEffectiveTxParams (recipientUtils.ts:183-187) fills that value in from txRequest.intent, which the server controls. Suppose the intent leaves out numberOfSplits, or sets it to 0 or 1, and the prepared transaction is a WalletUserProxy_BatchTransfer. Verification then falls through to the recipient path at canton.ts:228. explainTransaction there uses parseRawCantonTransactionData, whose default case (utils.ts findExerciseNodeFields('TransferFactory_Transfer')) reads only the first transfer node. If that first transfer matches the user's recipient, the rest of the batch can send funds to other parties and still pass. The base branch behaves the same way, and the PR description names this gap. The new parseBatchTransfers shape check is never applied on this path, so the fix is partial.
Verification: Pre-existing and security-relevant. The new split branch only runs on if (txParams.numberOfSplits !== undefined && txParams.numberOfSplits > 1) (canton.ts:225). In every other case, verification falls through to the old recipient path (canton.ts:228-257). So only the first child of a batch is checked. The base commit has the same Send path.
kisslove-dewangan
left a comment
There was a problem hiding this comment.
codeowners files lgtm
On EdDSA MPCv2 wallets a Canton UTXO split failed client-side, before any signing round, in two stages.
wallet.signAndSendTxRequest passes no txParams, so resolveEffectiveTxParams (sdk-core) rebuilds recipients from the persisted intent. It read recipient.address.address, which is undefined when the client stores the address as a plain string (the retail split does), and Canton verifyTransaction then crashed with "Cannot read properties of undefined (reading 'split')". Accept both the { address } object and a plain string, and copy numberOfSplits from the intent into the effective txParams (like executorPartyId) so a coin verifier can validate the split count. Adds numberOfSplits to TransactionParams and PopulatedIntent.
IMS builds a split as one root WalletUserProxy_BatchTransfer whose children are numberOfSplits TransferFactory_Transfer self-transfers. verifyTransaction only parsed the first transfer and compared it with the intent amount (the full value of the selected unspents), so it failed with "Tx outputs do not match with expected txParams recipients". Only the first transfer was ever inspected, so further transfers in a batch were unverified too.
When txParams.numberOfSplits > 1, verify the whole batch: parseBatchTransfers returns every transfer and throws unless the transaction has a single BatchTransfer root whose children are all TransferFactory_Transfer. Each transfer must go from the wallet's own address to itself, carry the expected token, and the transfer count must equal numberOfSplits. The total must be within less than numberOfSplits atomic units of the intent amount to allow for rounding dust. numberOfSplits of 0 or 1 keep the existing recipient-matching path. A recipient without an address now fails with a clear error instead of the TypeError.
Tests use captured staging/test txRequests for a native split, a token split and a multi-input token split, plus tampering cases (a transfer rewritten to a foreign party, wrong count, amount, wallet or token).
Ticket: CHALO-2192