Skip to content

fix(sdk-coin-trx): validate consolidation destination in TransferContract and TriggerSmartContract - #10168

Merged
harman-bitgo merged 1 commit into
masterfrom
CHALO-2125
Nov 12, 2026
Merged

harman-bitgo merged 1 commit into
masterfrom
CHALO-2125

Conversation

@harman-bitgo

Copy link
Copy Markdown
Contributor

Summary

  • Security fix: validateTransferContract and validateTriggerSmartContract skipped destination validation when txParams.recipients was absent (consolidation flow), returning true after only checking amount > 0. A compromised platform could return a consolidation prebuild redirecting funds to an attacker address — verifyTransaction would pass and signTransaction would sign it. For Tron receive addresses, the user's single signature is sufficient on-chain, enabling immediate fund theft without BitGo co-signature.
  • When recipients are absent/empty (consolidation), the destination is now validated against the wallet's base address via wallet.coinSpecific().baseAddress
  • When recipients has >1 entry (sendMany/bulk withdrawal), the prebuild is validated against all recipients (must match at least one)
  • Extracted shared validateConsolidationDestination helper used by both native TRX and TRC20 paths
  • Passes wallet from verifyTransaction down to both validator methods

Test plan

  • Existing 140+ unit tests pass unchanged (normal sends, TSS, on-chain multisig, TRC20)
  • New tests: consolidation with matching wallet base address passes
  • New tests: consolidation with non-matching destination throws
  • New tests: consolidation with missing wallet base address throws
  • New tests: multi-recipient (sendMany) matching one recipient passes
  • New tests: multi-recipient matching no recipients throws
  • New tests: TRC20 consolidation destination validation (pass + fail)
  • Full sdk-coin-trx unit test suite: 152 pass, 0 fail

TICKET: CHALO-2125

🤖 Generated with Claude Code

@harman-bitgo
harman-bitgo requested a review from a team as a code owner November 11, 2026 17:44

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@linear-code

linear-code Bot commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

CHALO-2125

@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Compatibility checks are failing on Node.js 27-nightly (experimental, non-blocking). This does not block merge, but it signals an incompatibility to fix before this release becomes supported.

View run

@harman-bitgo

Copy link
Copy Markdown
Contributor Author

@claude review

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing blocking. The comments below are optional suggestions. There is no need to push a fix for them before merging.

Comment thread modules/sdk-coin-trx/src/trx.ts Resolved
Comment thread modules/sdk-coin-trx/src/trx.ts Resolved
Comment thread modules/sdk-coin-trx/src/trx.ts Resolved
@harman-bitgo

Copy link
Copy Markdown
Contributor Author

Deep Regression Analysis

Code Path Trace (17 scenarios)

# Scenario Before After Verdict
A Normal send, 1 recipient (TSS, TransferContract) Validate dest+amount Same — wallet passed but unused in this branch SAFE
B Normal send, 1 recipient (on-chain multisig, TransferContract) Validate dest+amount Same — wallet passed but unused SAFE
C sendMany, 3 recipients (TSS, TransferContract) BUG: recipients.length !== 1 → skip all validation, return true Validate prebuild matches at least one recipient via .some() IMPROVEMENT
D sendMany, 3 recipients (on-chain multisig, TransferContract) BUG: same skip Same improvement as C IMPROVEMENT
E Consolidation, recipients=undefined (TSS, TransferContract) CRITICAL BUG: return true, no dest check Validate dest = wallet.coinSpecific().baseAddress CRITICAL FIX
F Consolidation, recipients=undefined (on-chain multisig, TransferContract) CRITICAL BUG: return true Same fix as E CRITICAL FIX
G Consolidation, recipients=[] (TSS, TransferContract) CRITICAL BUG: empty array treated as no recipients, return true Validate dest = wallet base address CRITICAL FIX
H TRC20 consolidation (TSS, through native Trx.verifyTransaction) CRITICAL BUG: return true, no dest check Validate dest = wallet base address via validateConsolidationDestination CRITICAL FIX
I TRC20 consolidation (TSS, through TrxToken.verifyTransaction) CRITICAL BUG: return true params.wallet now passed; dest validated CRITICAL FIX
J TRC20 consolidation (on-chain multisig, TrxToken) Throw "missing required property recipients" Same — on-chain multisig TrxToken path untouched SAME
K Normal TRC20 send, 1 recipient (TSS) Validate dest+amount Same — wallet passed but unused (recipients branch taken) SAFE
L AccountPermissionUpdate / non-Transfer contract (TSS) Return true (bypasses validateTransferContract) Same — non-Transfer contracts not routed to changed methods SAFE
M FreezeBalance / non-Transfer (on-chain multisig) Return true (contract.type !== 'TransferContract') Same SAFE
N wallet={} with recipients present Validate dest+amount (wallet unused) Same — wallet unused when recipients exist SAFE
O wallet={} without recipients CRITICAL BUG: return true Throw "missing wallet base address" — correct fail-closed behavior SAFE
P sendMany, prebuild matches recipient #2 (not #1) BUG: no validation at all .some() iterates all recipients, finds match at #2 IMPROVEMENT
Q recipients=[] empty array (TSS) CRITICAL BUG: return true Validate dest = wallet base address CRITICAL FIX

Call Site Verification — All 8 production callers pass wallet

Location Code wallet value
wallet.ts:900 prebuildAndSignTransaction → verify wallet: this
wallet.ts:2430 signTransaction → verify wallet: this as IWallet
wallet.ts:2914 prebuildAndSignTransaction main path wallet: this
wallet.ts:4063 sendAccountConsolidations wallet: this
ecdsa.ts:1072 TSS ECDSA with serializedTxHex wallet: this.wallet
ecdsa.ts:1079 TSS ECDSA with signableHex wallet: this.wallet
ecdsaMPCv2.ts:992 TSS ECDSAv2 with serializedTxHex wallet: this.wallet
ecdsaMPCv2.ts:1002 TSS ECDSAv2 with signableHex wallet: this.wallet

All production callers pass a real Wallet instance → coinSpecific() always available with baseAddress.

Regression Risk Summary

  • 10 scenarios: Behavior identical (normal sends, non-Transfer contracts)
  • 6 scenarios: Previously had zero validation → now properly validated (security fixes)
  • 1 scenario (wallet={}): Now throws instead of silently passing — correct fail-closed, not a production path
  • Zero regressions identified

Suggested Manual Test Plan (post-merge)

P0 — Must test:

  1. Native TRX consolidation (TSS wallet)
  2. Native TRX consolidation (on-chain multisig wallet)
  3. TRC20 token consolidation (TSS wallet)
  4. Native TRX single send (TSS + on-chain)
  5. TRX sendMany / bulk withdrawal with 2+ recipients

P1 — Should test:
6. TRC20 single send (TSS, both via TrxToken and native Trx coin instance)
7. TRC20 single send (on-chain multisig)
8. Non-Transfer contracts (permission update, freeze, vote)

P2 — Good to test:
9. Batch consolidation (sendAccountConsolidations plural)
10. Consolidation triggering pending approval

Confidence Rating: 9/10

Not 10 because validateTriggerSmartContract doesn't handle recipients.length > 1 for TRC20 sendMany (pre-existing gap, unchanged by this PR).

Unit Tests: 152 pass, 0 fail

  • 140 existing tests unchanged
  • 12 new tests covering: consolidation pass/fail (TransferContract + TRC20), sendMany match/no-match, missing wallet base address

0xPrabh
0xPrabh previously approved these changes Nov 11, 2026
…ract and TriggerSmartContract

validateTransferContract and validateTriggerSmartContract skipped
destination validation when txParams.recipients was absent (consolidation
flow), returning true after checking only that amount > 0. A compromised
platform could return a consolidation prebuild sending funds to an
attacker address, and verifyTransaction would sign it without inspecting
the destination.

Now:
- When recipients is absent/empty, validate the destination matches the
  wallet's base address (via wallet.coinSpecific().baseAddress).
- When recipients has >1 entry (sendMany/bulk withdrawal), validate the
  prebuild matches at least one recipient.
- Extract shared validateConsolidationDestination helper for both paths.
- Pass wallet from verifyTransaction down to both validators.

TICKET: CHALO-2125

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@harman-bitgo
harman-bitgo merged commit 1f5203c into master Nov 12, 2026
27 checks 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.

3 participants