Disallow extended encoding for non-witness transactions

This commit is contained in:
Pieter Wuille 2018-08-23 17:01:14 -07:00 committed by Steven Roose
parent 899690be2f
commit e11c6f5580

View file

@ -351,6 +351,10 @@ inline void UnserializeTransaction(TxType& tx, Stream& s) {
const_cast<CTxWitness*>(&tx.witness)->vtxinwit.resize(tx.vin.size());
const_cast<CTxWitness*>(&tx.witness)->vtxoutwit.resize(tx.vout.size());
s >> tx.witness;
if (!tx.HasWitness()) {
/* It's illegal to encode witnesses when all witness stacks are empty. */
throw std::ios_base::failure("Superfluous witness record");
}
}
} else {
const bool fAllowWitness = !(s.GetVersion() & SERIALIZE_TRANSACTION_NO_WITNESS);
@ -381,6 +385,10 @@ inline void UnserializeTransaction(TxType& tx, Stream& s) {
s >> tx.witness.vtxinwit[i].m_pegin_witness.stack;
}
}
if (!tx.HasWitness()) {
/* It's illegal to encode witnesses when all witness stacks are empty. */
throw std::ios_base::failure("Superfluous witness record");
}
}
s >> tx.nLockTime;
}