Skip to content

Commit 3c8206a

Browse files
committed
Merge #525: [0.17] Disallow extended encoding for non-witness transactions
e11c6f5 Disallow extended encoding for non-witness transactions (Pieter Wuille) Pull request description: backport of #402 which is a backport of upstream Tree-SHA512: 01cccbc0d54a9f039ed16c88f1d9ec7ebac3a936fb4a77e664c9103e06bb142741a743ac980887ec16570429ccc0f9614e5b3076084b1c949190b3169844ed7d
2 parents 406580e + e11c6f5 commit 3c8206a

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

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)