diff --git a/src/Makefile.test.include b/src/Makefile.test.include index e5e5f0dd15332e..888979a60b2c08 100644 --- a/src/Makefile.test.include +++ b/src/Makefile.test.include @@ -283,6 +283,7 @@ test_fuzz_fuzz_SOURCES = \ $(FUZZ_WALLET_SRC) \ test/fuzz/addition_overflow.cpp \ test/fuzz/addrman.cpp \ + test/fuzz/anyprevout.cpp \ test/fuzz/asmap.cpp \ test/fuzz/asmap_direct.cpp \ test/fuzz/autofile.cpp \ diff --git a/src/script/interpreter.cpp b/src/script/interpreter.cpp index 53df4248a841b0..7497ae8df10ae4 100644 --- a/src/script/interpreter.cpp +++ b/src/script/interpreter.cpp @@ -1671,9 +1671,11 @@ bool SignatureHashSchnorr(uint256& hash_out, ScriptExecutionData& execdata, cons ss << cache.m_spent_outputs[in_pos]; ss << tx_to.vin[in_pos].nSequence; } else if (input_type == SIGHASH_ANYPREVOUT) { + assert(keyversion == KeyVersion::ANYPREVOUT); ss << cache.m_spent_outputs[in_pos]; ss << tx_to.vin[in_pos].nSequence; } else if (input_type == SIGHASH_ANYPREVOUTANYSCRIPT) { + assert(keyversion == KeyVersion::ANYPREVOUT); ss << tx_to.vin[in_pos].nSequence; } else { ss << in_pos; @@ -1698,6 +1700,8 @@ bool SignatureHashSchnorr(uint256& hash_out, ScriptExecutionData& execdata, cons assert(execdata.m_tapleaf_hash_init); if (input_type != SIGHASH_ANYPREVOUTANYSCRIPT) { ss << execdata.m_tapleaf_hash; + } else { + assert(keyversion == KeyVersion::ANYPREVOUT); } ss << uint8_t(keyversion); assert(execdata.m_codeseparator_pos_init); diff --git a/src/test/fuzz/anyprevout.cpp b/src/test/fuzz/anyprevout.cpp new file mode 100644 index 00000000000000..a38a344ecb2004 --- /dev/null +++ b/src/test/fuzz/anyprevout.cpp @@ -0,0 +1,187 @@ +// Copyright (c) 2020 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include +#include +#include