Skip to content

Commit 39da18d

Browse files
feat(psbt): change default to accept witness UTXOs for non-segwit inputs
Default PSBT behavior now allows signing non-segwit inputs with witnessUtxos instead of requiring the full previous transaction. This reduces potential DDoS attack vectors by not requiring the storage of previous transaction data in the input map. Issue: BTC-2285
1 parent 4a530b7 commit 39da18d

File tree

3 files changed

+14
-23
lines changed

3 files changed

+14
-23
lines changed

src/psbt.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,11 @@ class Psbt {
7171
__TX: this.data.globalMap.unsignedTx.tx,
7272
// Psbt's predecesor (TransactionBuilder - now removed) behavior
7373
// was to not confirm input values before signing.
74-
// Even though we highly encourage people to get
75-
// the full parent transaction to verify values, the ability to
76-
// sign non-segwit inputs without the full transaction was often
77-
// requested. So the only way to activate is to use @ts-ignore.
78-
// We will disable exporting the Psbt when unsafe sign is active.
79-
// because it is not BIP174 compliant.
80-
__UNSAFE_SIGN_NONSEGWIT: false,
74+
// Due to the potential of DDoS by requiring the previous
75+
// transaction to be in the input map, we are defaulting the
76+
// behavior to not require the previous transaction and instead
77+
// use a witnessUtxo.
78+
__UNSAFE_SIGN_NONSEGWIT: true,
8179
__WARN_UNSAFE_SIGN_NONSEGWIT: true,
8280
__TX_FROM_BUFFER: buf =>
8381
this.constructor.transactionFromBuffer(buf, this.opts.network),
@@ -696,7 +694,8 @@ function canFinalize(input, script, scriptType) {
696694
}
697695
function checkCache(cache) {
698696
if (cache.__UNSAFE_SIGN_NONSEGWIT !== false) {
699-
throw new Error('Not BIP174 compliant, can not export');
697+
// Do not throw in this case as we are now defaulting this to true
698+
// throw new Error('Not BIP174 compliant, can not export');
700699
}
701700
}
702701
function hasSigs(neededSigs, partialSig, pubkeys) {

test/fixtures/psbt.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,6 @@ export const fixtures = {
155155
},
156156
],
157157
failSignChecks: [
158-
{
159-
description: 'A Witness UTXO is provided for a non-witness input',
160-
errorMessage: 'Input #0 has witnessUtxo but non-segwit script',
161-
psbt:
162-
'cHNidP8BAKACAAAAAqsJSaCMWvfEm4IS9Bfi8Vqz9cM9zxU4IagTn4d6W3vkAAAAAAD+////qwlJoIxa98SbghL0F+LxWrP1wz3PFTghqBOfh3pbe+QBAAAAAP7///8CYDvqCwAAAAAZdqkUdopAu9dAy+gdmI5x3ipNXHE5ax2IrI4kAAAAAAAAGXapFG9GILVT+glechue4O/p+gOcykWXiKwAAAAAAAEBItPf9QUAAAAAGXapFNSO0xELlAFMsRS9Mtb00GbcdCVriKwAAQEgAOH1BQAAAAAXqRQ1RebjO4MsRwUPJNPuuTycA5SLx4cBBBYAFIXRNTfy4mVAWjTbr6nj3aAfuCMIACICAurVlmh8qAYEPtw94RbN8p1eklfBls0FXPaYyNAr8k6ZELSmumcAAACAAAAAgAIAAIAAIgIDlPYr6d8ZlSxVh3aK63aYBhrSxKJciU9H2MFitNchPQUQtKa6ZwAAAIABAACAAgAAgAA=',
163-
inputToCheck: 0,
164-
},
165158
{
166159
description:
167160
'redeemScript with non-witness UTXO does not match the scriptPubKey',

ts_src/psbt.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,11 @@ export class Psbt {
145145
__TX: (this.data.globalMap.unsignedTx as PsbtTransaction).tx,
146146
// Psbt's predecesor (TransactionBuilder - now removed) behavior
147147
// was to not confirm input values before signing.
148-
// Even though we highly encourage people to get
149-
// the full parent transaction to verify values, the ability to
150-
// sign non-segwit inputs without the full transaction was often
151-
// requested. So the only way to activate is to use @ts-ignore.
152-
// We will disable exporting the Psbt when unsafe sign is active.
153-
// because it is not BIP174 compliant.
154-
__UNSAFE_SIGN_NONSEGWIT: false,
148+
// Due to the potential of DDoS by requiring the previous
149+
// transaction to be in the input map, we are defaulting the
150+
// behavior to not require the previous transaction and instead
151+
// use a witnessUtxo.
152+
__UNSAFE_SIGN_NONSEGWIT: true,
155153
__WARN_UNSAFE_SIGN_NONSEGWIT: true,
156154
__TX_FROM_BUFFER: buf =>
157155
(this.constructor as typeof Psbt).transactionFromBuffer(
@@ -950,7 +948,8 @@ function canFinalize(
950948

951949
function checkCache(cache: PsbtCache): void {
952950
if (cache.__UNSAFE_SIGN_NONSEGWIT !== false) {
953-
throw new Error('Not BIP174 compliant, can not export');
951+
// Do not throw in this case as we are now defaulting this to true
952+
// throw new Error('Not BIP174 compliant, can not export');
954953
}
955954
}
956955

0 commit comments

Comments
 (0)