mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-05-04 17:00:52 +02:00
6c7a17a8e0eec377f83ed1399f003ae70b898270 psbt: support externally provided preimages for Miniscript satisfaction (Antoine Poinsot) 840a396029316896beda46600aec3c1af09a899c qa: add a "smart" Miniscript fuzz target (Antoine Poinsot) 17e3547241d593bc92c5c6b36c54284d9d9f3feb qa: add a fuzz target generating random nodes from a binary encoding (Antoine Poinsot) 611e12502a5887ffb751bb92fadaa334d484824b qa: functional test Miniscript signing with key and timelocks (Antoine Poinsot) d57b7f2021d2369f6e88cdf0f562aab27c51beaf refactor: make descriptors in Miniscript functional test more readable (Antoine Poinsot) 0a8fc9e200b5018c1efd6f9126eb405ca0beeea3 wallet: check solvability using descriptor in AvailableCoins (Antoine Poinsot) 560e62b1e221832ae99ff8684559a7b8f9df84a7 script/sign: signing support for Miniscripts with hash preimage challenges (Antoine Poinsot) a2f81b6a8f1ff3b0750711409c7538812a52ef40 script/sign: signing support for Miniscript with timelocks (Antoine Poinsot) 61c6d1a8440db09c44d7fd367a6f2c641ea93d40 script/sign: basic signing support for Miniscript descriptors (Antoine Poinsot) 4242c1c52127df3a24be0c15b88d4fc463af04fc Align 'e' property of or_d and andor with website spec (Pieter Wuille) f5deb417804b9f267830bd40177677987df4526d Various additional explanations of the satisfaction logic from Pieter (Pieter Wuille) 22c5b00345063bdeb8b6d3da8b5692d18f92bfb7 miniscript: satisfaction support (Antoine Poinsot) Pull request description: This makes the Miniscript descriptors solvable. Note this introduces signing support for much more complex scripts than the wallet was previously able to solve, and the whole tooling isn't provided for a complete Miniscript integration in the wallet. Particularly, the PSBT<->Miniscript integration isn't entirely covered in this PR. ACKs for top commit: achow101: ACK 6c7a17a8e0eec377f83ed1399f003ae70b898270 sipa: utACK 6c7a17a8e0eec377f83ed1399f003ae70b898270 (to the extent that it's not my own code). Tree-SHA512: a71ec002aaf66bd429012caa338fc58384067bcd2f453a46e21d381ed1bacc8e57afb9db57c0fb4bf40de43b30808815e9ebc0ae1fbd9e61df0e7b91a17771cc
140 lines
4.3 KiB
C++
140 lines
4.3 KiB
C++
// Copyright (c) 2011-2022 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 <arith_uint256.h>
|
|
#include <pubkey.h>
|
|
#include <script/sign.h>
|
|
#include <script/signingprovider.h>
|
|
#include <script/standard.h>
|
|
#include <test/util/setup_common.h>
|
|
#include <txorphanage.h>
|
|
|
|
#include <array>
|
|
#include <cstdint>
|
|
|
|
#include <boost/test/unit_test.hpp>
|
|
|
|
BOOST_FIXTURE_TEST_SUITE(orphanage_tests, TestingSetup)
|
|
|
|
class TxOrphanageTest : public TxOrphanage
|
|
{
|
|
public:
|
|
inline size_t CountOrphans() const EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
|
|
{
|
|
LOCK(m_mutex);
|
|
return m_orphans.size();
|
|
}
|
|
|
|
CTransactionRef RandomOrphan() EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
|
|
{
|
|
LOCK(m_mutex);
|
|
std::map<uint256, OrphanTx>::iterator it;
|
|
it = m_orphans.lower_bound(InsecureRand256());
|
|
if (it == m_orphans.end())
|
|
it = m_orphans.begin();
|
|
return it->second.tx;
|
|
}
|
|
};
|
|
|
|
static void MakeNewKeyWithFastRandomContext(CKey& key)
|
|
{
|
|
std::vector<unsigned char> keydata;
|
|
keydata = g_insecure_rand_ctx.randbytes(32);
|
|
key.Set(keydata.data(), keydata.data() + keydata.size(), /*fCompressedIn=*/true);
|
|
assert(key.IsValid());
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE(DoS_mapOrphans)
|
|
{
|
|
// This test had non-deterministic coverage due to
|
|
// randomly selected seeds.
|
|
// This seed is chosen so that all branches of the function
|
|
// ecdsa_signature_parse_der_lax are executed during this test.
|
|
// Specifically branches that run only when an ECDSA
|
|
// signature's R and S values have leading zeros.
|
|
g_insecure_rand_ctx = FastRandomContext{uint256{33}};
|
|
|
|
TxOrphanageTest orphanage;
|
|
CKey key;
|
|
MakeNewKeyWithFastRandomContext(key);
|
|
FillableSigningProvider keystore;
|
|
BOOST_CHECK(keystore.AddKey(key));
|
|
|
|
// 50 orphan transactions:
|
|
for (int i = 0; i < 50; i++)
|
|
{
|
|
CMutableTransaction tx;
|
|
tx.vin.resize(1);
|
|
tx.vin[0].prevout.n = 0;
|
|
tx.vin[0].prevout.hash = InsecureRand256();
|
|
tx.vin[0].scriptSig << OP_1;
|
|
tx.vout.resize(1);
|
|
tx.vout[0].nValue = 1*CENT;
|
|
tx.vout[0].scriptPubKey = GetScriptForDestination(PKHash(key.GetPubKey()));
|
|
|
|
orphanage.AddTx(MakeTransactionRef(tx), i);
|
|
}
|
|
|
|
// ... and 50 that depend on other orphans:
|
|
for (int i = 0; i < 50; i++)
|
|
{
|
|
CTransactionRef txPrev = orphanage.RandomOrphan();
|
|
|
|
CMutableTransaction tx;
|
|
tx.vin.resize(1);
|
|
tx.vin[0].prevout.n = 0;
|
|
tx.vin[0].prevout.hash = txPrev->GetHash();
|
|
tx.vout.resize(1);
|
|
tx.vout[0].nValue = 1*CENT;
|
|
tx.vout[0].scriptPubKey = GetScriptForDestination(PKHash(key.GetPubKey()));
|
|
SignatureData empty;
|
|
BOOST_CHECK(SignSignature(keystore, *txPrev, tx, 0, SIGHASH_ALL, empty));
|
|
|
|
orphanage.AddTx(MakeTransactionRef(tx), i);
|
|
}
|
|
|
|
// This really-big orphan should be ignored:
|
|
for (int i = 0; i < 10; i++)
|
|
{
|
|
CTransactionRef txPrev = orphanage.RandomOrphan();
|
|
|
|
CMutableTransaction tx;
|
|
tx.vout.resize(1);
|
|
tx.vout[0].nValue = 1*CENT;
|
|
tx.vout[0].scriptPubKey = GetScriptForDestination(PKHash(key.GetPubKey()));
|
|
tx.vin.resize(2777);
|
|
for (unsigned int j = 0; j < tx.vin.size(); j++)
|
|
{
|
|
tx.vin[j].prevout.n = j;
|
|
tx.vin[j].prevout.hash = txPrev->GetHash();
|
|
}
|
|
SignatureData empty;
|
|
BOOST_CHECK(SignSignature(keystore, *txPrev, tx, 0, SIGHASH_ALL, empty));
|
|
// Re-use same signature for other inputs
|
|
// (they don't have to be valid for this test)
|
|
for (unsigned int j = 1; j < tx.vin.size(); j++)
|
|
tx.vin[j].scriptSig = tx.vin[0].scriptSig;
|
|
|
|
BOOST_CHECK(!orphanage.AddTx(MakeTransactionRef(tx), i));
|
|
}
|
|
|
|
// Test EraseOrphansFor:
|
|
for (NodeId i = 0; i < 3; i++)
|
|
{
|
|
size_t sizeBefore = orphanage.CountOrphans();
|
|
orphanage.EraseForPeer(i);
|
|
BOOST_CHECK(orphanage.CountOrphans() < sizeBefore);
|
|
}
|
|
|
|
// Test LimitOrphanTxSize() function:
|
|
orphanage.LimitOrphans(40);
|
|
BOOST_CHECK(orphanage.CountOrphans() <= 40);
|
|
orphanage.LimitOrphans(10);
|
|
BOOST_CHECK(orphanage.CountOrphans() <= 10);
|
|
orphanage.LimitOrphans(0);
|
|
BOOST_CHECK(orphanage.CountOrphans() == 0);
|
|
}
|
|
|
|
BOOST_AUTO_TEST_SUITE_END()
|