Skip to content

Commit

Permalink
Merge #74: Enforce minimal VERIFY when parsing from Script
Browse files Browse the repository at this point in the history
2b99303 miniscript: rule out Scripts with non-minimal VERIFY (Antoine Poinsot)

Pull request description:

  Based on #69

ACKs for top commit:
  sipa:
    utACK 2b99303

Tree-SHA512: 3cba6db30886659d36f8433fc1b0fd533e3e3c2bffdb46aeef65b013da2835a637f467da7477ec408d30f32fb99542b8291dbfd4ebe0a4a4a8bde5afd64402b6
  • Loading branch information
sipa committed Dec 8, 2021
2 parents f7a9cf0 + 2b99303 commit 2e0734d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions bitcoin/script/miniscript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,9 @@ bool DecomposeScript(const CScript& script, std::vector<std::pair<opcodetype, st
opcode = OP_VERIFY;
} else if (IsPushdataOp(opcode)) {
if (!CheckMinimalPush(push_data, opcode)) return false;
} else if (it != itend && (opcode == OP_CHECKSIG || opcode == OP_CHECKMULTISIG || opcode == OP_EQUAL) && (*it == OP_VERIFY)) {
// Rule out non minimal VERIFY sequences
return false;
}
out.emplace_back(opcode, std::move(push_data));
}
Expand Down
4 changes: 4 additions & 0 deletions bitcoin/test/miniscript_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,10 @@ BOOST_AUTO_TEST_CASE(fixed_tests)
std::vector<unsigned char> nonminpush = ParseHex("0000210232780000feff00ffffffffffff21ff005f00ae21ae00000000060602060406564c2102320000060900fe00005f00ae21ae00100000060606060606000000000000000000000000000000000000000000000000000000000000000000");
const CScript nonminpush_script(nonminpush.begin(), nonminpush.end());
BOOST_CHECK(miniscript::FromScript(nonminpush_script, CONVERTER) == nullptr);
// A non-minimal VERIFY (<key> CHECKSIG VERIFY 1)
std::vector<unsigned char> nonminverify = ParseHex("2103a0434d9e47f3c86235477c7b1ae6ae5d3442d49b1943c2b752a68e2a47e247c7ac6951");
const CScript nonminverify_script(nonminverify.begin(), nonminverify.end());
BOOST_CHECK(miniscript::FromScript(nonminverify_script, CONVERTER) == nullptr);
// A threshold as large as the number of subs is valid.
Test("thresh(2,c:pk_k(03d30199d74fb5a22d47b6e054e2f378cedacffcb89904a61d75d0dbd407143e65),altv:after(100))", "2103d30199d74fb5a22d47b6e054e2f378cedacffcb89904a61d75d0dbd407143e65ac6b6300670164b16951686c935287", TESTMODE_VALID | TESTMODE_NEEDSIG | TESTMODE_NONMAL);
// A threshold of 1 is valid.
Expand Down

0 comments on commit 2e0734d

Please sign in to comment.