Skip to content

fix: txHex needs to be set for the txn in case of TSS#8789

Merged
bhuvanr159 merged 1 commit into
masterfrom
CHALO-349-txHex-fixes
May 18, 2026
Merged

fix: txHex needs to be set for the txn in case of TSS#8789
bhuvanr159 merged 1 commit into
masterfrom
CHALO-349-txHex-fixes

Conversation

@bhuvanr159
Copy link
Copy Markdown
Contributor

TICKET: CHALO-349

@linear-code
Copy link
Copy Markdown

linear-code Bot commented May 18, 2026

CHALO-349

@bhuvanr159 bhuvanr159 marked this pull request as ready for review May 18, 2026 08:27
@bhuvanr159 bhuvanr159 requested review from a team as code owners May 18, 2026 08:27
@bhuvanr159 bhuvanr159 requested review from Marzooqa and bdesoky May 18, 2026 08:27
Comment thread modules/sdk-core/src/bitgo/wallet/wallet.ts Outdated
Comment thread modules/sdk-core/src/bitgo/wallet/wallet.ts Outdated
@bhuvanr159 bhuvanr159 force-pushed the CHALO-349-txHex-fixes branch from 8f36134 to 1d5faf4 Compare May 18, 2026 08:41
@bhuvanr159 bhuvanr159 requested a review from bhavidhingra May 18, 2026 10:13
Copy link
Copy Markdown
Contributor

@pritam-gembali pritam-gembali left a comment

Choose a reason for hiding this comment

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

unit tests?

bhavidhingra
bhavidhingra previously approved these changes May 18, 2026
@bhuvanr159 bhuvanr159 force-pushed the CHALO-349-txHex-fixes branch from 1d5faf4 to 99c4623 Compare May 18, 2026 10:20
@bhuvanr159 bhuvanr159 requested a review from a team as a code owner May 18, 2026 10:20
@bhuvanr159 bhuvanr159 force-pushed the CHALO-349-txHex-fixes branch from 99c4623 to f928cdb Compare May 18, 2026 10:26
Copy link
Copy Markdown
Contributor

@pritam-gembali pritam-gembali left a comment

Choose a reason for hiding this comment

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

The if (unsignedTx?.serializedTxHex) guard at modules/sdk-core/src/bitgo/wallet/wallet.ts:3534-3536 is a silent fallback. If the txRequest comes back in an unexpected shape, the assignment is skipped, no error is raised, and the prebuild is returned with txHex still missing — re-introducing the very bug this PR is fixing, just with an extra HTTP round-trip.

Concrete failure mode

Imagine the backend returns apiVersion: 'full' but transactions is [] (or its first element has no unsignedTx field — e.g. a future API rename):

  1. Build returns { txRequestId: 'req-1', stakingParams: {...} } with no txHex.
  2. We enter the new branch, fetch the txRequest. ✓
  3. txRequest.transactions?.[0]?.unsignedTxundefined.
  4. if (unsignedTx?.serializedTxHex) → false. Block silently skipped.
  5. Prebuild is returned without txHex.
  6. Caller hits prebuildAndSignTransactionverifyTransaction at wallet.ts:2189, which sees txPrebuild?.txHex is undefined and either skips verification or throws something downstream that looks unrelated (e.g. a coin-specific verify failing on undefined.length).

The user sees the downstream error and has no breadcrumb pointing back to the real cause seven steps earlier. Debugging means re-running with a debugger.

Suggested fix

if (!unsignedTx?.serializedTxHex) {
  throw new Error(
    `Expected serializedTxHex on TSS resource management prebuild for txRequestId ${prebuild.txRequestId}`
  );
}
prebuild = _.extend({}, prebuild, { txHex: unsignedTx.serializedTxHex });

This matches the assertive style already used at wallet.ts:4193-4202 in prebuildTransactionTxRequests, where missing/malformed txRequest shapes throw explicitly.

Test to update

The new test should leave txHex undefined when txRequest has no serializedTxHex in modules/sdk-core/test/unit/bitgo/wallet/resourceManagement.ts pins the silent-skip behavior as intended. Once that test merges, future reviewers will assume the silent fallback is by design — making it harder to harden later. Please flip it to expect a thrown error:

await wallet.buildResourceDelegations({ delegations: [delegations[0]] })
  .should.be.rejectedWith(/Expected serializedTxHex/);

Happy to approve once the throw is in place and the test is updated.

@bhuvanr159 bhuvanr159 force-pushed the CHALO-349-txHex-fixes branch from f928cdb to 11e1a85 Compare May 18, 2026 10:56
@bhuvanr159 bhuvanr159 requested a review from pritam-gembali May 18, 2026 11:27
@bhuvanr159 bhuvanr159 merged commit 5f53e4a into master May 18, 2026
22 checks passed
@bhuvanr159 bhuvanr159 deleted the CHALO-349-txHex-fixes branch May 19, 2026 05:43
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