From bb530efa1872ec963417f61da9a95185c7a7a7d6 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Thu, 23 Aug 2018 17:01:14 -0700 Subject: [PATCH] Disallow extended encoding for non-witness transactions --- src/primitives/transaction.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/primitives/transaction.h b/src/primitives/transaction.h index fb9db508d25ee..c1568f9b2ac1b 100644 --- a/src/primitives/transaction.h +++ b/src/primitives/transaction.h @@ -220,6 +220,10 @@ inline void UnserializeTransaction(TxType& tx, Stream& s) { for (size_t i = 0; i < tx.vin.size(); i++) { s >> tx.vin[i].scriptWitness.stack; } + if (!tx.HasWitness()) { + /* It's illegal to encode witnesses when all witness stacks are empty. */ + throw std::ios_base::failure("Superfluous witness record"); + } } if (flags) { /* Unknown flag in the serialization */