aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Chow <achow101-github@achow101.com>2018-08-13 14:59:31 -0700
committerfanquake <fanquake@gmail.com>2018-08-15 09:58:49 +0800
commit8c4cd2bd895fe7467307867fefc3cd45a685367c (patch)
tree7f8dd38e219a0788e5a08c5ff31e6157ba01a353 /src
parentff41e479a0a3c2485f6116abcffa1bacbd86ca72 (diff)
downloadbitcoin-8c4cd2bd895fe7467307867fefc3cd45a685367c.tar.xz
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. GitHub-Pull: #13960 Rebased-From: 43811e6
Diffstat (limited to 'src')
-rw-r--r--src/script/sign.h7
-rw-r--r--src/streams.h1
2 files changed, 6 insertions, 2 deletions
diff --git a/src/script/sign.h b/src/script/sign.h
index 24cddda51b..86188cbb38 100644
--- a/src/script/sign.h
+++ b/src/script/sign.h
@@ -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) {
diff --git a/src/streams.h b/src/streams.h
index 2dcca6646d..096ebfc9c2 100644
--- a/src/streams.h
+++ b/src/streams.h
@@ -61,6 +61,7 @@ public:
int GetVersion() const { return nVersion; }
int GetType() const { return nType; }
+ size_t size() const { return stream->size(); }
};
template<typename S>