mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 06:58:57 +01:00
Fix PSBT deserialization of 0-input transactions
0-input transactions can be ambiguously deserialized as being witness transactions. Since the unsigned transaction is never serialized as a witness transaction as it has no witnesses, we should always deserialize it as a non-witness transaction and set the serialization flags as such. Also always serialize the unsigned transaction as a non-witness transaction.
This commit is contained in:
@@ -547,7 +547,8 @@ struct PartiallySignedTransaction
|
||||
SerializeToVector(s, PSBT_GLOBAL_UNSIGNED_TX);
|
||||
|
||||
// Write serialized tx to a stream
|
||||
SerializeToVector(s, *tx);
|
||||
OverrideStream<Stream> os(&s, s.GetType(), s.GetVersion() | SERIALIZE_TRANSACTION_NO_WITNESS);
|
||||
SerializeToVector(os, *tx);
|
||||
|
||||
// Write the unknown things
|
||||
for (auto& entry : unknown) {
|
||||
@@ -601,7 +602,9 @@ struct PartiallySignedTransaction
|
||||
throw std::ios_base::failure("Global unsigned tx key is more than one byte type");
|
||||
}
|
||||
CMutableTransaction mtx;
|
||||
UnserializeFromVector(s, mtx);
|
||||
// Set the stream to serialize with non-witness since this should always be non-witness
|
||||
OverrideStream<Stream> os(&s, s.GetType(), s.GetVersion() | SERIALIZE_TRANSACTION_NO_WITNESS);
|
||||
UnserializeFromVector(os, mtx);
|
||||
tx = std::move(mtx);
|
||||
// Make sure that all scriptSigs and scriptWitnesses are empty
|
||||
for (const CTxIn& txin : tx->vin) {
|
||||
|
||||
Reference in New Issue
Block a user