Skip to content

Commit 5279d8b

Browse files
committed
psbt: Allow both non_witness_utxo and witness_utxo
1 parent 72f6bec commit 5279d8b

File tree

5 files changed

+0
-53
lines changed

5 files changed

+0
-53
lines changed

src/psbt.cpp

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,6 @@ bool PartiallySignedTransaction::Merge(const PartiallySignedTransaction& psbt)
3535
return true;
3636
}
3737

38-
bool PartiallySignedTransaction::IsSane() const
39-
{
40-
for (PSBTInput input : inputs) {
41-
if (!input.IsSane()) return false;
42-
}
43-
return true;
44-
}
45-
4638
bool PartiallySignedTransaction::AddInput(const CTxIn& txin, PSBTInput& psbtin)
4739
{
4840
if (std::find(tx->vin.begin(), tx->vin.end(), txin) != tx->vin.end()) {
@@ -158,18 +150,6 @@ void PSBTInput::Merge(const PSBTInput& input)
158150
if (final_script_witness.IsNull() && !input.final_script_witness.IsNull()) final_script_witness = input.final_script_witness;
159151
}
160152

161-
bool PSBTInput::IsSane() const
162-
{
163-
// Cannot have both witness and non-witness utxos
164-
if (!witness_utxo.IsNull() && non_witness_utxo) return false;
165-
166-
// If we have a witness_script or a scriptWitness, we must also have a witness utxo
167-
if (!witness_script.empty() && witness_utxo.IsNull()) return false;
168-
if (!final_script_witness.IsNull() && witness_utxo.IsNull()) return false;
169-
170-
return true;
171-
}
172-
173153
void PSBTOutput::FillSignatureData(SignatureData& sigdata) const
174154
{
175155
if (!redeem_script.empty()) {
@@ -261,11 +241,6 @@ bool SignPSBTInput(const SigningProvider& provider, PartiallySignedTransaction&
261241
bool require_witness_sig = false;
262242
CTxOut utxo;
263243

264-
// Verify input sanity, which checks that at most one of witness or non-witness utxos is provided.
265-
if (!input.IsSane()) {
266-
return false;
267-
}
268-
269244
if (input.non_witness_utxo) {
270245
// If we're taking our information from a non-witness UTXO, verify that it matches the prevout.
271246
COutPoint prevout = tx.vin[index].prevout;
@@ -356,10 +331,6 @@ TransactionError CombinePSBTs(PartiallySignedTransaction& out, const std::vector
356331
return TransactionError::PSBT_MISMATCH;
357332
}
358333
}
359-
if (!out.IsSane()) {
360-
return TransactionError::INVALID_PSBT;
361-
}
362-
363334
return TransactionError::OK;
364335
}
365336

src/psbt.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ struct PSBTInput
6262
void FillSignatureData(SignatureData& sigdata) const;
6363
void FromSignatureData(const SignatureData& sigdata);
6464
void Merge(const PSBTInput& input);
65-
bool IsSane() const;
6665
PSBTInput() {}
6766

6867
template <typename Stream>
@@ -284,7 +283,6 @@ struct PSBTOutput
284283
void FillSignatureData(SignatureData& sigdata) const;
285284
void FromSignatureData(const SignatureData& sigdata);
286285
void Merge(const PSBTOutput& output);
287-
bool IsSane() const;
288286
PSBTOutput() {}
289287

290288
template <typename Stream>
@@ -401,7 +399,6 @@ struct PartiallySignedTransaction
401399
/** Merge psbt into this. The two psbts must have the same underlying CTransaction (i.e. the
402400
* same actual Bitcoin transaction.) Returns true if the merge succeeded, false otherwise. */
403401
NODISCARD bool Merge(const PartiallySignedTransaction& psbt);
404-
bool IsSane() const;
405402
bool AddInput(const CTxIn& txin, PSBTInput& psbtin);
406403
bool AddOutput(const CTxOut& txout, const PSBTOutput& psbtout);
407404
PartiallySignedTransaction() {}
@@ -551,10 +548,6 @@ struct PartiallySignedTransaction
551548
if (outputs.size() != tx->vout.size()) {
552549
throw std::ios_base::failure("Outputs provided does not match the number of outputs in transaction.");
553550
}
554-
// Sanity check
555-
if (!IsSane()) {
556-
throw std::ios_base::failure("PSBT is not sane.");
557-
}
558551
}
559552

560553
template <typename Stream>

src/test/fuzz/psbt.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ void test_one_input(const std::vector<uint8_t>& buffer)
3939
}
4040

4141
(void)psbt.IsNull();
42-
(void)psbt.IsSane();
4342

4443
Optional<CMutableTransaction> tx = psbt.tx;
4544
if (tx) {
@@ -50,7 +49,6 @@ void test_one_input(const std::vector<uint8_t>& buffer)
5049
for (const PSBTInput& input : psbt.inputs) {
5150
(void)PSBTInputSigned(input);
5251
(void)input.IsNull();
53-
(void)input.IsSane();
5452
}
5553

5654
for (const PSBTOutput& output : psbt.outputs) {

src/wallet/scriptpubkeyman.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -597,11 +597,6 @@ TransactionError LegacyScriptPubKeyMan::FillPSBT(PartiallySignedTransaction& psb
597597
continue;
598598
}
599599

600-
// Verify input looks sane. This will check that we have at most one uxto, witness or non-witness.
601-
if (!input.IsSane()) {
602-
return TransactionError::INVALID_PSBT;
603-
}
604-
605600
// Get the Sighash type
606601
if (sign && input.sighash_type > 0 && input.sighash_type != sighash_type) {
607602
return TransactionError::SIGHASH_MISMATCH;
@@ -2086,11 +2081,6 @@ TransactionError DescriptorScriptPubKeyMan::FillPSBT(PartiallySignedTransaction&
20862081
continue;
20872082
}
20882083

2089-
// Verify input looks sane. This will check that we have at most one uxto, witness or non-witness.
2090-
if (!input.IsSane()) {
2091-
return TransactionError::INVALID_PSBT;
2092-
}
2093-
20942084
// Get the Sighash type
20952085
if (sign && input.sighash_type > 0 && input.sighash_type != sighash_type) {
20962086
return TransactionError::SIGHASH_MISMATCH;

src/wallet/wallet.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2491,11 +2491,6 @@ TransactionError CWallet::FillPSBT(PartiallySignedTransaction& psbtx, bool& comp
24912491
continue;
24922492
}
24932493

2494-
// Verify input looks sane. This will check that we have at most one uxto, witness or non-witness.
2495-
if (!input.IsSane()) {
2496-
return TransactionError::INVALID_PSBT;
2497-
}
2498-
24992494
// If we have no utxo, grab it from the wallet.
25002495
if (!input.non_witness_utxo && input.witness_utxo.IsNull()) {
25012496
const uint256& txhash = txin.prevout.hash;

0 commit comments

Comments
 (0)