Skip to content

fix(sdk-coin-sol): verify deserialized versioned tx message - #10219

Open
Venkat-Annavazzala wants to merge 1 commit into
masterfrom
venkatpavan/chalo-447-security-solana-versioned-transaction
Open

Venkat-Annavazzala wants to merge 1 commit into
masterfrom
venkatpavan/chalo-447-security-solana-versioned-transaction

Conversation

@Venkat-Annavazzala

@Venkat-Annavazzala Venkat-Annavazzala commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Ticket
CHALO-447 (Parent: WAL-1449)

Summary
Replaces the structural-only stub in Sol.verifyVersionedTransaction() with full wire deserialization, canonical encoding validation, fail-closed parameter guards, and exact MessageV0 equivalence verification against txParams.solVersionedTransactionData.

Root Cause
Previously, Sol.verifyVersionedTransaction() (modules/sdk-coin-sol/src/sol.ts) only checked that txParams.solVersionedTransactionData had non-empty fields and that a single byte in the raw transaction had bit 7 set ((versionByte & 0x80) !== 0). It never deserialized the raw transaction bytes or compared the message against user intent. A compromised Wallet Platform could substitute an arbitrary v0 transaction (e.g., a System Program or SPL Token transfer draining wallet funds) and client-side verification would still return true.

Changes

  • modules/sdk-coin-sol/src/lib/customInstructionBuilder.ts & modules/sdk-coin-sol/src/lib/index.ts
    • Extracted injectVersionedNonceAdvanceInstruction() as a shared pure deterministic helper used by both CustomInstructionBuilder and Sol.verifyVersionedTransaction() so build and verification cannot drift.
  • modules/sdk-coin-sol/src/sol.ts
    • Fail-closed param guards: Reject solVersionedTransactionData when txParams.type is present and !== 'customTx', when txParams.recipients is non-empty, when consolidation flags (consolidateId / consolidationToBaseAddress) are set, or when version !== 0.
    • Strict intent validation: Validate canonical non-duplicate staticAccountKeys, consistent messageHeader counts, valid ALT keys and uint8 indexes, in-bounds instruction indexes, and valid base58 instruction data (allowing empty string "").
    • Full wire deserialization & canonical check: Deserialize via VersionedTransaction.deserialize(), enforce tx.version === 0, and enforce Buffer.from(tx.serialize()).equals(txBytes) to block trailing bytes and non-canonical encodings.
    • Exact MessageV0 comparison: Verify header, staticAccountKeys, addressTableLookups (accountKey, writableIndexes, readonlyIndexes), and compiledInstructions (programIdIndex, accountKeyIndexes, raw data bytes) match txParams.solVersionedTransactionData byte-for-byte:
      • Direct match (same instruction count): Standard WalletConnect / v0 flow.
      • WP-injected durable nonce (expected + 1 instructions): Allowed only if instruction 0 is strictly SystemProgram.AdvanceNonceAccount (writable nonce account + SYSVAR_RECENT_BLOCKHASHES + signer authority), matches params.durableNonce when provided, does not escalate any existing non-signer or read-only account in versionedData when params.durableNonce is omitted, and matches injectVersionedNonceAdvanceInstruction() identically across the entire message.
    • Fee payer & wallet signer checks: Enforce declaredFeePayer against staticAccountKeys[0] when provided, and verify wallet.coinSpecific().rootAddress is in staticAccountKeys.slice(0, numRequiredSignatures).
  • modules/sdk-coin-sol/test/unit/sol.ts
    • Added 19 unit tests covering valid v0 flows (base64, hex, ALTs, real multi-instruction/multi-ALT Jupiter swap fixture, DEFI-820 blockhash refresh, third-party gasless fee payer, sponsored fee payer, empty instruction data, WP-injected durable nonce with shifted ALT indexes) and attack/tampering cases (substituted SystemProgram.transfer drain, tampered data/accountKeyIndexes/staticAccountKeys/ALTs/header, extra non-nonce instruction, privilege escalation via nonce injection, tampered user instruction paired with valid nonce injection, mismatched durableNonce, 2-byte [0x00, 0x80] stub bypass, legacy tx, v1 0x81, trailing bytes, non-customTx type, non-empty recipients, consolidation flags, version: 1, wrong fee payer, missing wallet root signer).

Design Note for Security Review (Why Exact MessageV0 Equivalence Instead of Instruction Allow-List / Offline ALT Resolution)

  • In production (last 90 days in BITGO2__TRANSACTION_REQUEST: 74 versioned txRequests, 54 delivered), solVersionedTransactionData is used exclusively for customTx (WalletConnect DeFi swaps such as Jupiter): 100% are customTx, 100% pass empty recipients, 91% use Address Lookup Tables (ALTs), and 100% include the wallet root address in required signers (70/74 at index 0; 4/74 with a third-party gasless fee payer at index 0 and wallet root at signer index 1).
  • Failing closed on unrecognized DeFi programs or attempting offline on-chain ALT resolution would break WalletConnect DeFi.
  • Comparing the deserialized MessageV0 byte-for-byte against txParams.solVersionedTransactionData is strictly stronger for customTx: a compromised Wallet Platform cannot substitute any instruction (System, SPL, or DeFi), alter any instruction data/account index, swap any static key or ALT reference/index, or escalate any signer/writable flag.
  • recentBlockhash is intentionally not pinned to versionedData.recentBlockhash to preserve DEFI-820 (refreshIntentBeforeSigning blockhash refresh on hot wallets / pending approvals), as blockhash cannot alter instructions, accounts, or amounts.

@Venkat-Annavazzala
Venkat-Annavazzala requested a review from a team as a code owner November 23, 2026 08:22

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

Copy link
Copy Markdown
Contributor

CHALO-447

@Venkat-Annavazzala
Venkat-Annavazzala force-pushed the venkatpavan/chalo-447-security-solana-versioned-transaction branch from 99d0314 to 4f5d549 Compare November 23, 2026 09:11
@github-actions

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

@Venkat-Annavazzala

Copy link
Copy Markdown
Contributor Author

@claude review always

@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @Venkat-Annavazzala's task in 26s —— View job


Review of #10219: verify deserialized versioned tx message

I read the src diff, mainly sol.ts. I didn't read the test diff line by line, and I didn't run the build or the tests.

The design is sound. Comparing the deserialized MessageV0 to solVersionedTransactionData is stronger than an instruction allow-list for customTx. The fail-closed guards, the re-serialize equality check and the shared injectVersionedNonceAdvanceInstruction helper all look right. I found no blocking issues. These are the things I'd look at before merging.

Suggestions

  1. The wallet-signer check is skipped when the wallet is missing (sol.ts, end of verifyVersionedTransaction). The check only runs if (walletRootAddress). If params.wallet is absent, or coinSpecific() has no rootAddress, verification returns true without confirming the wallet is a required signer. The PR says production traffic always includes the root signer, so this likely matters only for callers that omit wallet. If so, I'd either require it for versioned txs or add a test that pins the skip as intended.

  2. The nonce privilege-escalation guard only runs when durableNonce is omitted, and only checks static keys.

    • With durableNonce supplied, the caller is trusted and injectVersionedNonceAdvanceInstruction may promote an existing read-only account to writable. That is probably intended, but a comment saying so would help.
    • In both modes, an injected nonce or authority key that also appears in an ALT lookup is not detected, because indexOf only searches staticAccountKeys. The impact looks low: it would be a duplicate static key, and an AdvanceNonce on a non-nonce account fails on-chain. It's still worth a line in the design note.
  3. Hex versus base64 detection is ambiguous. HEX_REGEX.test(rawTx) && rawTx.length % 2 === 0 is tried first. A valid base64 string made only of [0-9a-f] characters would be decoded as hex. It would then fail the deserialize or canonical check, so it fails closed. That is safe, but the failure would be confusing. It is very unlikely for real tx sizes, so I'd note it and leave it.

  4. The fee payer fallback is loosely typed. The 'feePayer' in txParams && typeof txParams.feePayer === 'string' chain works, but adding feePayer?: string to the txParams type would remove the narrowing code.

  5. Redundant validation. validateVersionedTransactionData rejects version values other than 0 and undefined. The type guard and the top-level checks may already cover that. It's harmless.

Positives

  • The re-serialization equality check closes trailing bytes, non-canonical compact-u16 encodings, and signature-count tricks in one place.
  • The [0x00, 0x80] stub bypass, legacy txs, v1 0x81, and "valid nonce injection plus tampered user instruction" all have test cases.
  • Not pinning recentBlockhash is the right call for DEFI-820 and is documented.

Open item

  • GitHub Actions reports the Node 27-nightly job as failing. It's non-blocking and experimental. I haven't checked whether it relates to this PR, so please confirm it doesn't.

@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 on lines +911 to +913
const reserializedBytes = Buffer.from(deserializedTx.serialize());
if (!reserializedBytes.equals(txBytes)) {
throw new Error('versioned transaction has non-canonical encoding or trailing bytes');

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟣 pre-existing, not blocking: Pre-existing, security-relevant: a compromised Wallet Platform can still get TSS Solana wallets to co-sign a draining v0 transaction. The new strict check only inspects serializedTxHex. The MPCv2 signer at eddsaMPCv2.ts:605-609 signs signableHex, a separate server field nobody compares. Fix: tie the verified message to the signed bytes. Have eddsaMPCv2 pass signableHex. Then add a Sol assertSignableConsistency that requires it to equal deserializedTx.message.serialize(), as ecdsaMPCv2.ts:1004-1005 already does. This needs an sdk-core change beyond this PR.
A small fix can ride a push you are already making; otherwise a short reply is enough.

Why this was flagged

In the TSS sign path, eddsaMPCv2.ts:605 sets txOrMessageToSign = unsignedTx.signableHex and eddsaMPCv2.ts:608 makes bufferContent from it. That is what userDsg.initDsg signs at eddsaMPCv2.ts:629. But eddsaMPCv2.ts:610 passes only txHex: unsignedTx.serializedTxHex to verifyTransaction, which routes to verifyVersionedTransaction. Both fields come from the server separately. A compromised WP can return a benign serializedTxHex that passes the new header, key, ALT and instruction equality checks (sol.ts:902-913 and assertVersionedMessageMatchesData). It can pair it with a signableHex holding a System or SPL drain message, and the wallet signs the drain. The ECDSA paths guard this with assertSignableConsistency (ecdsaMPCv2.ts:1004-1005, ecdsa.ts:1079-1080). The EdDSA path has no such check, and Sol does not implement the method. The base branch has the same gap, so this is pre-existing. It leaves open the exact threat the PR description says it closes: WP substituting an arbitrary v0 transaction while client-side verification returns true.

Verification: In modules/sdk-core/src/bitgo/utils/tss/eddsa/eddsaMPCv2.ts:605 the code sets txOrMessageToSign = unsignedTx.signableHex. Line 629 signs those bytes. But lines 609-610 pass only serializedTxHex to verifyTransaction. Sol has no assertSignableConsistency method. The base branch already signs signableHex unchecked in the same place.

This branch has not been deployed

No deployments
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