Skip to content

Commit e11c6f5

Browse files
sipastevenroose
authored andcommitted
Disallow extended encoding for non-witness transactions
1 parent 899690b commit e11c6f5

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/primitives/transaction.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,10 @@ inline void UnserializeTransaction(TxType& tx, Stream& s) {
351351
const_cast<CTxWitness*>(&tx.witness)->vtxinwit.resize(tx.vin.size());
352352
const_cast<CTxWitness*>(&tx.witness)->vtxoutwit.resize(tx.vout.size());
353353
s >> tx.witness;
354+
if (!tx.HasWitness()) {
355+
/* It's illegal to encode witnesses when all witness stacks are empty. */
356+
throw std::ios_base::failure("Superfluous witness record");
357+
}
354358
}
355359
} else {
356360
const bool fAllowWitness = !(s.GetVersion() & SERIALIZE_TRANSACTION_NO_WITNESS);
@@ -381,6 +385,10 @@ inline void UnserializeTransaction(TxType& tx, Stream& s) {
381385
s >> tx.witness.vtxinwit[i].m_pegin_witness.stack;
382386
}
383387
}
388+
if (!tx.HasWitness()) {
389+
/* It's illegal to encode witnesses when all witness stacks are empty. */
390+
throw std::ios_base::failure("Superfluous witness record");
391+
}
384392
}
385393
s >> tx.nLockTime;
386394
}

0 commit comments

Comments
 (0)