From d51d8b301034331642fd0bacff3f23b57a6a0070 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Thu, 22 Aug 2024 14:07:33 -0400 Subject: [PATCH] Consensus: witness program push must be minimal. --- include/bitcoin/system/impl/chain/script.ipp | 1 + test/chain/script.hpp | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/include/bitcoin/system/impl/chain/script.ipp b/include/bitcoin/system/impl/chain/script.ipp index d696d33017..ea10e8b4e6 100644 --- a/include/bitcoin/system/impl/chain/script.ipp +++ b/include/bitcoin/system/impl/chain/script.ipp @@ -88,6 +88,7 @@ VCONSTEXPR bool script::is_witness_program_pattern( { return ops.size() == 2 && ops[0].is_version() + && ops[1].is_minimal_push() && ops[1].data().size() >= min_witness_program && ops[1].data().size() <= max_witness_program; } diff --git a/test/chain/script.hpp b/test/chain/script.hpp index c985f8e575..00e5d3c23c 100644 --- a/test/chain/script.hpp +++ b/test/chain/script.hpp @@ -522,7 +522,8 @@ const script_test_list valid_context_free_scripts { "[42424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242]", "[2.42424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242] equal", "basic push signedness check" }, { "[1.42424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242]", "[2.42424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242] equal", "basic pushdata1 signedness check" }, { "0x00", "size 0 equal", "basic op_0 execution" }, - { "", "0 1 equal size 0 equal", "boolean encoding" } + { "", "0 1 equal size 0 equal", "boolean encoding" }, + { "[4242]", "zero [1.4242424242424242424242]", "non-minimal push should not match as witness program" } }}; // These are always invalid.