mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 15:09:59 +01:00
remove libbitcoinconsensus
This was deprecated in v27.0, for removal in v28.0. See discussion in PR #29189.
This commit is contained in:
@@ -2,10 +2,6 @@
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#if defined(HAVE_CONFIG_H)
|
||||
#include <config/bitcoin-config.h>
|
||||
#endif
|
||||
|
||||
#include <test/data/script_tests.json.h>
|
||||
#include <test/data/bip341_wallet_vectors.json.h>
|
||||
|
||||
@@ -27,10 +23,6 @@
|
||||
#include <util/fs.h>
|
||||
#include <util/strencodings.h>
|
||||
|
||||
#if defined(HAVE_CONSENSUS_LIB)
|
||||
#include <script/bitcoinconsensus.h>
|
||||
#endif
|
||||
|
||||
#include <cstdint>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
@@ -143,21 +135,6 @@ void DoTest(const CScript& scriptPubKey, const CScript& scriptSig, const CScript
|
||||
if (combined_flags & SCRIPT_VERIFY_WITNESS && ~combined_flags & SCRIPT_VERIFY_P2SH) continue;
|
||||
BOOST_CHECK_MESSAGE(VerifyScript(scriptSig, scriptPubKey, &scriptWitness, combined_flags, MutableTransactionSignatureChecker(&tx, 0, txCredit.vout[0].nValue, MissingDataBehavior::ASSERT_FAIL), &err) == expect, message + strprintf(" (with flags %x)", combined_flags));
|
||||
}
|
||||
|
||||
#if defined(HAVE_CONSENSUS_LIB)
|
||||
DataStream stream;
|
||||
stream << TX_WITH_WITNESS(tx2);
|
||||
uint32_t libconsensus_flags{flags & bitcoinconsensus_SCRIPT_FLAGS_VERIFY_ALL};
|
||||
if (libconsensus_flags == flags) {
|
||||
int expectedSuccessCode = expect ? 1 : 0;
|
||||
if (flags & bitcoinconsensus_SCRIPT_FLAGS_VERIFY_WITNESS) {
|
||||
BOOST_CHECK_MESSAGE(bitcoinconsensus_verify_script_with_amount(scriptPubKey.data(), scriptPubKey.size(), txCredit.vout[0].nValue, UCharCast(stream.data()), stream.size(), 0, libconsensus_flags, nullptr) == expectedSuccessCode, message);
|
||||
} else {
|
||||
BOOST_CHECK_MESSAGE(bitcoinconsensus_verify_script_with_amount(scriptPubKey.data(), scriptPubKey.size(), 0, UCharCast(stream.data()), stream.size(), 0, libconsensus_flags, nullptr) == expectedSuccessCode, message);
|
||||
BOOST_CHECK_MESSAGE(bitcoinconsensus_verify_script(scriptPubKey.data(), scriptPubKey.size(), UCharCast(stream.data()), stream.size(), 0, libconsensus_flags, nullptr) == expectedSuccessCode, message);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void static NegateSignatureS(std::vector<unsigned char>& vchSig) {
|
||||
@@ -1498,179 +1475,6 @@ static CScriptWitness ScriptWitnessFromJSON(const UniValue& univalue)
|
||||
return scriptwitness;
|
||||
}
|
||||
|
||||
#if defined(HAVE_CONSENSUS_LIB)
|
||||
|
||||
/* Test simple (successful) usage of bitcoinconsensus_verify_script */
|
||||
BOOST_AUTO_TEST_CASE(bitcoinconsensus_verify_script_returns_true)
|
||||
{
|
||||
unsigned int libconsensus_flags = 0;
|
||||
int nIn = 0;
|
||||
|
||||
CScript scriptPubKey;
|
||||
CScript scriptSig;
|
||||
CScriptWitness wit;
|
||||
|
||||
scriptPubKey << OP_1;
|
||||
CTransaction creditTx{BuildCreditingTransaction(scriptPubKey, 1)};
|
||||
CTransaction spendTx{BuildSpendingTransaction(scriptSig, wit, creditTx)};
|
||||
|
||||
DataStream stream;
|
||||
stream << TX_WITH_WITNESS(spendTx);
|
||||
|
||||
bitcoinconsensus_error err;
|
||||
int result = bitcoinconsensus_verify_script(scriptPubKey.data(), scriptPubKey.size(), UCharCast(stream.data()), stream.size(), nIn, libconsensus_flags, &err);
|
||||
BOOST_CHECK_EQUAL(result, 1);
|
||||
BOOST_CHECK_EQUAL(err, bitcoinconsensus_ERR_OK);
|
||||
}
|
||||
|
||||
/* Test bitcoinconsensus_verify_script returns invalid tx index err*/
|
||||
BOOST_AUTO_TEST_CASE(bitcoinconsensus_verify_script_tx_index_err)
|
||||
{
|
||||
unsigned int libconsensus_flags = 0;
|
||||
int nIn = 3;
|
||||
|
||||
CScript scriptPubKey;
|
||||
CScript scriptSig;
|
||||
CScriptWitness wit;
|
||||
|
||||
scriptPubKey << OP_EQUAL;
|
||||
CTransaction creditTx{BuildCreditingTransaction(scriptPubKey, 1)};
|
||||
CTransaction spendTx{BuildSpendingTransaction(scriptSig, wit, creditTx)};
|
||||
|
||||
DataStream stream;
|
||||
stream << TX_WITH_WITNESS(spendTx);
|
||||
|
||||
bitcoinconsensus_error err;
|
||||
int result = bitcoinconsensus_verify_script(scriptPubKey.data(), scriptPubKey.size(), UCharCast(stream.data()), stream.size(), nIn, libconsensus_flags, &err);
|
||||
BOOST_CHECK_EQUAL(result, 0);
|
||||
BOOST_CHECK_EQUAL(err, bitcoinconsensus_ERR_TX_INDEX);
|
||||
}
|
||||
|
||||
/* Test bitcoinconsensus_verify_script returns tx size mismatch err*/
|
||||
BOOST_AUTO_TEST_CASE(bitcoinconsensus_verify_script_tx_size)
|
||||
{
|
||||
unsigned int libconsensus_flags = 0;
|
||||
int nIn = 0;
|
||||
|
||||
CScript scriptPubKey;
|
||||
CScript scriptSig;
|
||||
CScriptWitness wit;
|
||||
|
||||
scriptPubKey << OP_EQUAL;
|
||||
CTransaction creditTx{BuildCreditingTransaction(scriptPubKey, 1)};
|
||||
CTransaction spendTx{BuildSpendingTransaction(scriptSig, wit, creditTx)};
|
||||
|
||||
DataStream stream;
|
||||
stream << TX_WITH_WITNESS(spendTx);
|
||||
|
||||
bitcoinconsensus_error err;
|
||||
int result = bitcoinconsensus_verify_script(scriptPubKey.data(), scriptPubKey.size(), UCharCast(stream.data()), stream.size() * 2, nIn, libconsensus_flags, &err);
|
||||
BOOST_CHECK_EQUAL(result, 0);
|
||||
BOOST_CHECK_EQUAL(err, bitcoinconsensus_ERR_TX_SIZE_MISMATCH);
|
||||
}
|
||||
|
||||
/* Test bitcoinconsensus_verify_script returns invalid tx serialization error */
|
||||
BOOST_AUTO_TEST_CASE(bitcoinconsensus_verify_script_tx_serialization)
|
||||
{
|
||||
unsigned int libconsensus_flags = 0;
|
||||
int nIn = 0;
|
||||
|
||||
CScript scriptPubKey;
|
||||
CScript scriptSig;
|
||||
CScriptWitness wit;
|
||||
|
||||
scriptPubKey << OP_EQUAL;
|
||||
CTransaction creditTx{BuildCreditingTransaction(scriptPubKey, 1)};
|
||||
CTransaction spendTx{BuildSpendingTransaction(scriptSig, wit, creditTx)};
|
||||
|
||||
DataStream stream;
|
||||
stream << 0xffffffff;
|
||||
|
||||
bitcoinconsensus_error err;
|
||||
int result = bitcoinconsensus_verify_script(scriptPubKey.data(), scriptPubKey.size(), UCharCast(stream.data()), stream.size(), nIn, libconsensus_flags, &err);
|
||||
BOOST_CHECK_EQUAL(result, 0);
|
||||
BOOST_CHECK_EQUAL(err, bitcoinconsensus_ERR_TX_DESERIALIZE);
|
||||
}
|
||||
|
||||
/* Test bitcoinconsensus_verify_script returns amount required error */
|
||||
BOOST_AUTO_TEST_CASE(bitcoinconsensus_verify_script_amount_required_err)
|
||||
{
|
||||
unsigned int libconsensus_flags = bitcoinconsensus_SCRIPT_FLAGS_VERIFY_WITNESS;
|
||||
int nIn = 0;
|
||||
|
||||
CScript scriptPubKey;
|
||||
CScript scriptSig;
|
||||
CScriptWitness wit;
|
||||
|
||||
scriptPubKey << OP_EQUAL;
|
||||
CTransaction creditTx{BuildCreditingTransaction(scriptPubKey, 1)};
|
||||
CTransaction spendTx{BuildSpendingTransaction(scriptSig, wit, creditTx)};
|
||||
|
||||
DataStream stream;
|
||||
stream << TX_WITH_WITNESS(spendTx);
|
||||
|
||||
bitcoinconsensus_error err;
|
||||
int result = bitcoinconsensus_verify_script(scriptPubKey.data(), scriptPubKey.size(), UCharCast(stream.data()), stream.size(), nIn, libconsensus_flags, &err);
|
||||
BOOST_CHECK_EQUAL(result, 0);
|
||||
BOOST_CHECK_EQUAL(err, bitcoinconsensus_ERR_AMOUNT_REQUIRED);
|
||||
}
|
||||
|
||||
/* Test bitcoinconsensus_verify_script returns invalid flags err */
|
||||
BOOST_AUTO_TEST_CASE(bitcoinconsensus_verify_script_invalid_flags)
|
||||
{
|
||||
unsigned int libconsensus_flags = 1 << 3;
|
||||
int nIn = 0;
|
||||
|
||||
CScript scriptPubKey;
|
||||
CScript scriptSig;
|
||||
CScriptWitness wit;
|
||||
|
||||
scriptPubKey << OP_EQUAL;
|
||||
CTransaction creditTx{BuildCreditingTransaction(scriptPubKey, 1)};
|
||||
CTransaction spendTx{BuildSpendingTransaction(scriptSig, wit, creditTx)};
|
||||
|
||||
DataStream stream;
|
||||
stream << TX_WITH_WITNESS(spendTx);
|
||||
|
||||
bitcoinconsensus_error err;
|
||||
int result = bitcoinconsensus_verify_script(scriptPubKey.data(), scriptPubKey.size(), UCharCast(stream.data()), stream.size(), nIn, libconsensus_flags, &err);
|
||||
BOOST_CHECK_EQUAL(result, 0);
|
||||
BOOST_CHECK_EQUAL(err, bitcoinconsensus_ERR_INVALID_FLAGS);
|
||||
}
|
||||
|
||||
/* Test bitcoinconsensus_verify_script returns spent outputs required err */
|
||||
BOOST_AUTO_TEST_CASE(bitcoinconsensus_verify_script_spent_outputs_required_err)
|
||||
{
|
||||
unsigned int libconsensus_flags{bitcoinconsensus_SCRIPT_FLAGS_VERIFY_TAPROOT};
|
||||
const int nIn{0};
|
||||
|
||||
CScript scriptPubKey;
|
||||
CScript scriptSig;
|
||||
CScriptWitness wit;
|
||||
|
||||
scriptPubKey << OP_EQUAL;
|
||||
CTransaction creditTx{BuildCreditingTransaction(scriptPubKey, 1)};
|
||||
CTransaction spendTx{BuildSpendingTransaction(scriptSig, wit, creditTx)};
|
||||
|
||||
DataStream stream;
|
||||
stream << TX_WITH_WITNESS(spendTx);
|
||||
|
||||
bitcoinconsensus_error err;
|
||||
int result{bitcoinconsensus_verify_script_with_spent_outputs(scriptPubKey.data(), scriptPubKey.size(), creditTx.vout[0].nValue, UCharCast(stream.data()), stream.size(), nullptr, 0, nIn, libconsensus_flags, &err)};
|
||||
BOOST_CHECK_EQUAL(result, 0);
|
||||
BOOST_CHECK_EQUAL(err, bitcoinconsensus_ERR_SPENT_OUTPUTS_REQUIRED);
|
||||
|
||||
result = bitcoinconsensus_verify_script_with_amount(scriptPubKey.data(), scriptPubKey.size(), creditTx.vout[0].nValue, UCharCast(stream.data()), stream.size(), nIn, libconsensus_flags, &err);
|
||||
BOOST_CHECK_EQUAL(result, 0);
|
||||
BOOST_CHECK_EQUAL(err, bitcoinconsensus_ERR_SPENT_OUTPUTS_REQUIRED);
|
||||
|
||||
result = bitcoinconsensus_verify_script(scriptPubKey.data(), scriptPubKey.size(), UCharCast(stream.data()), stream.size(), nIn, libconsensus_flags, &err);
|
||||
BOOST_CHECK_EQUAL(result, 0);
|
||||
BOOST_CHECK_EQUAL(err, bitcoinconsensus_ERR_SPENT_OUTPUTS_REQUIRED);
|
||||
}
|
||||
|
||||
#endif // defined(HAVE_CONSENSUS_LIB)
|
||||
|
||||
static std::vector<unsigned int> AllConsensusFlags()
|
||||
{
|
||||
std::vector<unsigned int> ret;
|
||||
@@ -1718,28 +1522,12 @@ static void AssetTest(const UniValue& test)
|
||||
txdata.Init(tx, std::vector<CTxOut>(prevouts));
|
||||
CachingTransactionSignatureChecker txcheck(&tx, idx, prevouts[idx].nValue, true, txdata);
|
||||
|
||||
#if defined(HAVE_CONSENSUS_LIB)
|
||||
DataStream stream;
|
||||
stream << TX_WITH_WITNESS(tx);
|
||||
std::vector<UTXO> utxos;
|
||||
utxos.resize(prevouts.size());
|
||||
for (size_t i = 0; i < prevouts.size(); i++) {
|
||||
utxos[i].scriptPubKey = prevouts[i].scriptPubKey.data();
|
||||
utxos[i].scriptPubKeySize = prevouts[i].scriptPubKey.size();
|
||||
utxos[i].value = prevouts[i].nValue;
|
||||
}
|
||||
#endif
|
||||
|
||||
for (const auto flags : ALL_CONSENSUS_FLAGS) {
|
||||
// "final": true tests are valid for all flags. Others are only valid with flags that are
|
||||
// a subset of test_flags.
|
||||
if (fin || ((flags & test_flags) == flags)) {
|
||||
bool ret = VerifyScript(tx.vin[idx].scriptSig, prevouts[idx].scriptPubKey, &tx.vin[idx].scriptWitness, flags, txcheck, nullptr);
|
||||
BOOST_CHECK(ret);
|
||||
#if defined(HAVE_CONSENSUS_LIB)
|
||||
int lib_ret = bitcoinconsensus_verify_script_with_spent_outputs(prevouts[idx].scriptPubKey.data(), prevouts[idx].scriptPubKey.size(), prevouts[idx].nValue, UCharCast(stream.data()), stream.size(), utxos.data(), utxos.size(), idx, flags, nullptr);
|
||||
BOOST_CHECK(lib_ret == 1);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1752,27 +1540,11 @@ static void AssetTest(const UniValue& test)
|
||||
txdata.Init(tx, std::vector<CTxOut>(prevouts));
|
||||
CachingTransactionSignatureChecker txcheck(&tx, idx, prevouts[idx].nValue, true, txdata);
|
||||
|
||||
#if defined(HAVE_CONSENSUS_LIB)
|
||||
DataStream stream;
|
||||
stream << TX_WITH_WITNESS(tx);
|
||||
std::vector<UTXO> utxos;
|
||||
utxos.resize(prevouts.size());
|
||||
for (size_t i = 0; i < prevouts.size(); i++) {
|
||||
utxos[i].scriptPubKey = prevouts[i].scriptPubKey.data();
|
||||
utxos[i].scriptPubKeySize = prevouts[i].scriptPubKey.size();
|
||||
utxos[i].value = prevouts[i].nValue;
|
||||
}
|
||||
#endif
|
||||
|
||||
for (const auto flags : ALL_CONSENSUS_FLAGS) {
|
||||
// If a test is supposed to fail with test_flags, it should also fail with any superset thereof.
|
||||
if ((flags & test_flags) == test_flags) {
|
||||
bool ret = VerifyScript(tx.vin[idx].scriptSig, prevouts[idx].scriptPubKey, &tx.vin[idx].scriptWitness, flags, txcheck, nullptr);
|
||||
BOOST_CHECK(!ret);
|
||||
#if defined(HAVE_CONSENSUS_LIB)
|
||||
int lib_ret = bitcoinconsensus_verify_script_with_spent_outputs(prevouts[idx].scriptPubKey.data(), prevouts[idx].scriptPubKey.size(), prevouts[idx].nValue, UCharCast(stream.data()), stream.size(), utxos.data(), utxos.size(), idx, flags, nullptr);
|
||||
BOOST_CHECK(lib_ret == 0);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user