Repository navigation
fix(sdk-api): require previous transactions for v1 non-segwit psbt inputs - #10190
Open
prikshitchawla300 wants to merge 1 commit into
Open
prikshitchawla300 wants to merge 1 commit into
prikshitchawla300 wants to merge 1 commit into
Conversation
…puts The legacy sighash used by non-segwit (p2sh) inputs does not commit to the input value, so the full previous transaction is needed to know what an input spends. - signPsbtRequest refuses a PSBT if any p2sh input lacks nonWitnessUtxo or its nonWitnessUtxo does not hash to the txid the input spends, and signs in safe mode instead of withUnsafeNonSegwit. - The v1 PSBT builder attaches the previous transaction of every p2sh input instead of using skipNonWitnessUtxo. It is taken from the unspent's prevTx or fetched from the block explorer, and must match the input's txid, script and value. - createTransaction no longer falls back to the legacy format when a previous transaction contradicts the unspent data (PrevTxMismatchError). Other PSBT build errors still fall back. BREAKING CHANGE: v1 signTransaction no longer signs PSBTs whose p2sh inputs only carry witnessUtxo. PSBTs built by this SDK now include the previous transactions; PSBTs built elsewhere must include nonWitnessUtxo for p2sh inputs. Ticket: CSHLD-2230
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.
Contributor
Contributor
|
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The legacy sighash used by non-segwit (p2sh) inputs does not commit to the input value, so the full previous transaction (
nonWitnessUtxo) is needed to know what an input spends. The v1 PSBT path built and signed p2sh inputs fromwitnessUtxoonly (skipNonWitnessUtxo+withUnsafeNonSegwit). This change makes it require and verify the previous transaction.Behaviour change
signPsbtRequest): refuses the whole PSBT if any p2sh input has nononWitnessUtxo, or itsnonWitnessUtxodoes not hash to the txid the input spends. Signing now runs in safe mode (withUnsafeNonSegwit(..., false)). Segwit and taproot inputs are unchanged.createTransactionwithusePsbt): attaches the previous transaction of every p2sh input instead of usingskipNonWitnessUtxo. It is taken from the unspent'sprevTxif present, otherwise fetched from the block explorer (samebtcExplorerBaseUrlendpoint already used for CPFP). It must match the input's txid, and the spent output must have the unspent's script and value.PrevTxMismatchError),createTransactionrejects instead of falling back to the legacy format. Other PSBT build errors, including a failed explorer fetch, still fall back as before.BREAKING CHANGE: v1
signTransactionno longer signs PSBTs whose p2sh inputs only carrywitnessUtxo. PSBTs built by this SDK now include the previous transactions. PSBTs built elsewhere must includenonWitnessUtxofor p2sh inputs.Changes
modules/sdk-api/src/v1/signPsbt.ts:nonWitnessUtxocheck, safe-mode signingmodules/sdk-api/src/v1/transactionBuilder.ts: fetch and verify previous transactions,PrevTxMismatchErrormodules/sdk-api/src/v1/wallet.ts: no legacy fallback onPrevTxMismatchErrortest/unit/v1/signPsbt.tsandtest/unit/v1/wallet.tsTesting
sdk-apiunit tests: 296 passingnonWitnessUtxorefused, one bad input refuses the whole PSBT,nonWitnessUtxoof another transaction refused, segwit inputs still sign fromwitnessUtxo, explorer fetch, value / txid / script mismatch rejected without fallback, and a failed fetch still falling back.Ticket: CSHLD-2230