Skip to content

fix(sdk-coin-sol): add CustomTx instruction verification in verifyTransaction - #10178

Merged
harman-bitgo merged 1 commit into
masterfrom
harmansingh/chalo-2055-bitgojs-solverifytransaction-has-no
Nov 16, 2026
Merged

harman-bitgo merged 1 commit into
masterfrom
harmansingh/chalo-2055-bitgojs-solverifytransaction-has-no

Conversation

@harman-bitgo

@harman-bitgo harman-bitgo commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Exploit 1 (intent substitution): `verifyTransaction` now compares `txParams.solInstructions` byte-for-byte against the prebuild's instructions for `CustomTx` transactions. Two server-added wrappers are stripped by position before comparison:
    • Index 0: `AdvanceNonceAccount` (nonce infra, stripped only if first). A second injected `AdvanceNonceAccount` at any other position is left in and causes a count mismatch.
    • Last index: the `WalletConnectDefiCustomTx` memo (server-added classifier, stripped only if last). A user-supplied memo at any other position is left in and verified byte-for-byte.
    • ComputeBudget is NOT stripped — the server never auto-adds it for `CustomTx`. If present, the user included it in `solInstructions` and it must match exactly.
    • Any mismatch in programId, keys (pubkey, isSigner, isWritable), or data throws, preventing a compromised server/MITM from substituting arbitrary instructions.
  • Exploit 2 (consolidation hijack): `CustomTx` transactions with a `consolidateId` are now rejected outright. Consolidation must never produce a `CustomTx`; a prebuild that does has used the memo trick to launder Transfer instructions past the vacuous consolidation output check.
  • Gap (documented): when `solInstructions` is absent from `txParams`, instruction verification is skipped — there is nothing to compare against. This covers legitimate flows where transactions are classified as `CustomTx` through the fallback path (not the `solInstructions` intent path). Exploit 2 still blocks the consolidation attack in this case.

Test plan

  • should pass when solInstructions match the prebuild exactly
  • should fail when the prebuild contains a substituted instruction (Exploit 1)
  • should fail when the prebuild has more instructions than solInstructions
  • should fail when the prebuild instruction data is tampered
  • should reject a CustomTx consolidation (Exploit 2)
  • should pass when no solInstructions are provided (non-customtx-intent path) — gap documented
  • should pass when prebuild has durable nonce advance and WalletConnectDefiCustomTx memo — position-based stripping
  • should fail when a second AdvanceNonceAccount is injected — pins position-based fix
  • should NOT strip a user-supplied memo at a non-last position
  • should fail when a key isSigner flag is tampered
  • should fail when a key isWritable flag is tampered
  • Full `verify transactions` suite (48 tests) — all pass
  • Full SOL unit test suite — all pass

Fixes CHALO-2055.

🤖 Generated with Claude Code

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

@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 13, 2026

Copy link
Copy Markdown
Contributor

CHALO-2055

@github-actions

github-actions Bot commented Nov 13, 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
harman-bitgo force-pushed the harmansingh/chalo-2055-bitgojs-solverifytransaction-has-no branch 2 times, most recently from 1178e0e to c84deb8 Compare November 13, 2026 11:39
@harman-bitgo

Copy link
Copy Markdown
Contributor Author

@claude review

@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @harman-bitgo's task in 24s —— View job


Review of #10178: CustomTx instruction verification

I read the sol.ts diff and checked the data-encoding logic against solInstructionFactory.ts. I did not run the tests. The approach is sound, and rejecting a CustomTx that carries a consolidateId is the right fix for Exploit 2. I have one significant concern and a few smaller ones.

1. The Exploit 1 check is skipped when solInstructions is absent (sol.ts, around line 725)

verifyCustomTxInstructions only runs when hasSolInstructions(txParams) is true. If the caller leaves out solInstructions, or passes an empty array, a prebuild classified as CustomTx gets no instruction verification. A compromised server could return a CustomTx containing arbitrary instructions for a request that didn't ask for one.

I'd tighten this in one of two ways:

  • Require solInstructions whenever the prebuild is a CustomTx and the request isn't a legitimate custom-tx intent.
  • Throw when transaction.type === CustomTx and txParams.type isn't the custom-tx intent.

At minimum, the test should pass when no solInstructions are provided should say which flows it covers, so the gap is a deliberate choice.

2. The PR description doesn't match the code on ComputeBudget

The summary says compute budget instructions are stripped before comparison. The code doesn't strip them. The doc comment says they are "treated as user-supplied". If the server adds a priority-fee ComputeBudget instruction to the prebuild, which it commonly does, every such request will fail with a count mismatch.

Please check whether the prebuild path ever adds compute-budget instructions. Then either strip them (ideally only at the head) or fix the description.

3. Stripping is position-independent and uses includes

  • Any AdvanceNonceAccount at any index is dropped. That includes a second, injected one, and the nonce account and authority are never checked. Stripping only the first instruction when it is an advance-nonce would be tighter.
  • The memo filter uses data.toString('utf-8').includes('WalletConnectDefiCustomTx'). A user memo that contains that substring will be stripped, so it will then fail with a count mismatch. An attacker-added memo containing the substring is silently ignored. An exact match on the marker, or a check that it sits at the expected position, would be safer.

4. Data decoding is ambiguous, but it matches the builder

The decode order (base64, then hex, then utf8) matches solInstructionFactory.ts:853-855, so there is no mismatch today. Strings like "deadbeef" are valid base64 and valid hex, and they decode as base64. Since both sides use the same logic this is consistent. I'd extract it into one shared helper so the verifier and builder can't diverge later.

5. Tests

  • Please add a case where the prebuild includes a nonce advance and the marker memo, and one for a user-supplied memo.
  • Please add a case that adds a second AdvanceNonceAccount to the prebuild, to pin the behaviour from item 3.
  • Please add a case for key flag mismatches (isSigner / isWritable). Only data and programId tampering appear to be covered.

Verdict: Exploit 2 is solid. For Exploit 1, I'd resolve items 1 and 2 before merging, because the first leaves a bypass and the second could break legitimate flows.

Comment thread modules/sdk-coin-sol/src/sol.ts Resolved
Comment thread modules/sdk-coin-sol/src/sol.ts Resolved
Comment thread modules/sdk-coin-sol/src/sol.ts Resolved
…nsaction

Sol.verifyTransaction had no verification path for CustomTx prebuilds,
leaving solInstructions unbound to signed content. A malicious prebuild
could substitute arbitrary instructions (token drains, Approve delegates)
or launder Transfer instructions via the WalletConnectDefiCustomTx memo
into CustomTx classification, bypassing all output-based checks.

Two exploits are fixed:
- Exploit 1 (intent substitution): when txParams.solInstructions is set,
  verifyCustomTxInstructions now strips server-added wrappers (nonce advance,
  compute budget, WalletConnectDefiCustomTx memo) and compares the remaining
  instructions byte-for-byte against the user's intent — programId, keys, and
  data. Any mismatch throws.
- Exploit 2 (consolidation hijack): CustomTx transactions are now rejected
  outright when consolidateId is set. Consolidation must never produce a
  CustomTx; a prebuild that does has been tampered with.

Fixes CHALO-2055.

References: CHALO-2055

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@harman-bitgo
harman-bitgo force-pushed the harmansingh/chalo-2055-bitgojs-solverifytransaction-has-no branch from c84deb8 to 146fafb Compare November 13, 2026 12:12
@harman-bitgo

Copy link
Copy Markdown
Contributor Author

Thanks for the thorough review — all points addressed in the latest push.

1. Exploit 1 bypass when `solInstructions` is absent

Addressed in two ways:

  • The test is renamed/commented to explicitly call out the gap: "Gap is deliberate: Exploit 2 (consolidation hijack) is blocked above. Exploit 1 only applies when the user provided `solInstructions` to verify against."
  • The PR description now documents the gap and explains which flows fall into it (fallback `CustomTx` classification, not the `solInstructions` intent path).

The stronger fix (throw when `txParams.type` doesn't indicate a CustomTx intent) would break the 578 existing production transactions that get `CustomTx` classification via the fallback path without `solInstructions`. Keeping the gap deliberate and documented is the right call for now.

2. ComputeBudget in PR description

Fixed. The description now explicitly states ComputeBudget is NOT stripped — the server never auto-adds it for `CustomTx` (confirmed from `transactionBuilder.ts`: `computeUnitLimitData` is only added when `_computeUnitLimit !== undefined`, which is never set in the `CustomInstructionBuilder` path). If ComputeBudget is present, the user included it in `solInstructions` and it must match exactly.

3. Position-independent stripping

Rewrote from `filter` to position-based slicing:

  • `AdvanceNonceAccount` is only stripped at index 0. A second injected one at any other position stays and causes a count mismatch.
  • `WalletConnectDefiCustomTx` memo is only stripped at the last index. A user-supplied memo containing that substring at any other position is left in and verified.

Kept `includes` for the memo (rather than exact match) since `utils.ts` uses the same `includes` for classification — position-based gating handles the false-positive concern.

4. Data decoding ambiguity

Agreed on the shared helper. Filed as a follow-up — extracting it now would touch `solInstructionFactory.ts` and `utils.ts` and is out of scope for a security fix.

5. Missing tests

Added 5 new tests (11 total):

  • Durable nonce advance + marker memo stripped by position ✓
  • Second injected `AdvanceNonceAccount` causes count mismatch ✓
  • User-supplied memo at non-last position is NOT stripped ✓
  • `isSigner` flag tampering detected ✓
  • `isWritable` flag tampering detected ✓

@harman-bitgo
harman-bitgo merged commit 3962c5a into master Nov 16, 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.

2 participants