Skip to content

Commit 90f7d8a

Browse files
committed
Merge bitcoin/bitcoin#28539: lib: add taproot support to libconsensus
ff8e2fc fuzz: add coverage for `bitcoinconsensus_verify_script_with_spent_outputs` (brunoerg) c5f2a75 docs: add release notes for #28539 (brunoerg) de54882 docs: add docs for additional libconsensus functions (Jake Rawsthorne) 70106e0 docs: link to rust-bitcoinconsensus (Jake Rawsthorne) fb0db07 lib: add Taproot support to libconsensus (Jake Rawsthorne) Pull request description: Grabbed from #21158. Closes #21133. ACKs for top commit: achow101: ACK ff8e2fc theStack: ACK ff8e2fc darosior: re-ACK ff8e2fc Tree-SHA512: bf6f500c7e8c9ff6884137c2cd9b4522c586e52848dd639b774b94d998b0516b877498d24f3a6cc7425aedf81d18b0d30c1ccf19e2d527fdfdfa3955ca49b6e7
2 parents 08ea835 + ff8e2fc commit 90f7d8a

File tree

6 files changed

+175
-6
lines changed

6 files changed

+175
-6
lines changed

doc/release-notes-123.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Tools and Utilities
2+
---
3+
4+
- A new `bitcoinconsensus_verify_script_with_spent_outputs` function is available in libconsensus which optionally accepts the spent outputs of the transaction being verified.
5+
- A new `bitcoinconsensus_SCRIPT_FLAGS_VERIFY_TAPROOT` flag is available in libconsensus that will verify scripts with the Taproot spending rules.

doc/shared-libraries.md

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ The interface is defined in the C header `bitcoinconsensus.h` located in `src/sc
1111

1212
#### Version
1313

14-
`bitcoinconsensus_version` returns an `unsigned int` with the API version *(currently `1`)*.
14+
`bitcoinconsensus_version` returns an `unsigned int` with the API version *(currently `2`)*.
1515

1616
#### Script Validation
1717

18-
`bitcoinconsensus_verify_script` returns an `int` with the status of the verification. It will be `1` if the input script correctly spends the previous output `scriptPubKey`.
18+
`bitcoinconsensus_verify_script`, `bitcoinconsensus_verify_script_with_amount` and `bitcoinconsensus_verify_script_with_spent_outputs` return an `int` with the status of the verification. It will be `1` if the input script correctly spends the previous output `scriptPubKey`.
1919

2020
##### Parameters
21+
###### bitcoinconsensus_verify_script
2122
- `const unsigned char *scriptPubKey` - The previous output script that encumbers spending.
2223
- `unsigned int scriptPubKeyLen` - The number of bytes for the `scriptPubKey`.
2324
- `const unsigned char *txTo` - The transaction with the input that is spending the previous output.
@@ -26,6 +27,28 @@ The interface is defined in the C header `bitcoinconsensus.h` located in `src/sc
2627
- `unsigned int flags` - The script validation flags *(see below)*.
2728
- `bitcoinconsensus_error* err` - Will have the error/success code for the operation *(see below)*.
2829

30+
###### bitcoinconsensus_verify_script_with_amount
31+
- `const unsigned char *scriptPubKey` - The previous output script that encumbers spending.
32+
- `unsigned int scriptPubKeyLen` - The number of bytes for the `scriptPubKey`.
33+
- `int64_t amount` - The amount spent in the input
34+
- `const unsigned char *txTo` - The transaction with the input that is spending the previous output.
35+
- `unsigned int txToLen` - The number of bytes for the `txTo`.
36+
- `unsigned int nIn` - The index of the input in `txTo` that spends the `scriptPubKey`.
37+
- `unsigned int flags` - The script validation flags *(see below)*.
38+
- `bitcoinconsensus_error* err` - Will have the error/success code for the operation *(see below)*.
39+
40+
###### bitcoinconsensus_verify_script_with_spent_outputs
41+
- `const unsigned char *scriptPubKey` - The previous output script that encumbers spending.
42+
- `unsigned int scriptPubKeyLen` - The number of bytes for the `scriptPubKey`.
43+
- `int64_t amount` - The amount spent in the input
44+
- `const unsigned char *txTo` - The transaction with the input that is spending the previous output.
45+
- `unsigned int txToLen` - The number of bytes for the `txTo`.
46+
- `UTXO *spentOutputs` - Previous outputs spent in the transaction. `UTXO` is a struct composed by `const unsigned char *scriptPubKey`, `unsigned int scriptPubKeySize` (the number of bytes for the `scriptPubKey`) and `unsigned int value`.
47+
- `unsigned int spentOutputsLen` - The number of bytes for the `spentOutputs`.
48+
- `unsigned int nIn` - The index of the input in `txTo` that spends the `scriptPubKey`.
49+
- `unsigned int flags` - The script validation flags *(see below)*.
50+
- `bitcoinconsensus_error* err` - Will have the error/success code for the operation *(see below)*.
51+
2952
##### Script Flags
3053
- `bitcoinconsensus_SCRIPT_FLAGS_VERIFY_NONE`
3154
- `bitcoinconsensus_SCRIPT_FLAGS_VERIFY_P2SH` - Evaluate P2SH ([BIP16](https://github.com/bitcoin/bips/blob/master/bip-0016.mediawiki)) subscripts
@@ -34,6 +57,7 @@ The interface is defined in the C header `bitcoinconsensus.h` located in `src/sc
3457
- `bitcoinconsensus_SCRIPT_FLAGS_VERIFY_CHECKLOCKTIMEVERIFY` - Enable CHECKLOCKTIMEVERIFY ([BIP65](https://github.com/bitcoin/bips/blob/master/bip-0065.mediawiki))
3558
- `bitcoinconsensus_SCRIPT_FLAGS_VERIFY_CHECKSEQUENCEVERIFY` - Enable CHECKSEQUENCEVERIFY ([BIP112](https://github.com/bitcoin/bips/blob/master/bip-0112.mediawiki))
3659
- `bitcoinconsensus_SCRIPT_FLAGS_VERIFY_WITNESS` - Enable WITNESS ([BIP141](https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki))
60+
- `bitcoinconsensus_SCRIPT_FLAGS_VERIFY_TAPROOT` - Enable TAPROOT ([BIP340](https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki), [BIP341](https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki), [BIP342](https://github.com/bitcoin/bips/blob/master/bip-0342.mediawiki))
3761

3862
##### Errors
3963
- `bitcoinconsensus_ERR_OK` - No errors with input parameters *(see the return value of `bitcoinconsensus_verify_script` for the verification status)*
@@ -42,9 +66,12 @@ The interface is defined in the C header `bitcoinconsensus.h` located in `src/sc
4266
- `bitcoinconsensus_ERR_DESERIALIZE` - An error deserializing `txTo`
4367
- `bitcoinconsensus_ERR_AMOUNT_REQUIRED` - Input amount is required if WITNESS is used
4468
- `bitcoinconsensus_ERR_INVALID_FLAGS` - Script verification `flags` are invalid (i.e. not part of the libconsensus interface)
69+
- `bitcoinconsensus_ERR_SPENT_OUTPUTS_REQUIRED` - Spent outputs are required if TAPROOT is used
70+
- `bitcoinconsensus_ERR_SPENT_OUTPUTS_MISMATCH` - Spent outputs size doesn't match tx inputs size
4571

4672
### Example Implementations
4773
- [NBitcoin](https://github.com/MetacoSA/NBitcoin/blob/5e1055cd7c4186dee4227c344af8892aea54faec/NBitcoin/Script.cs#L979-#L1031) (.NET Bindings)
4874
- [node-libbitcoinconsensus](https://github.com/bitpay/node-libbitcoinconsensus) (Node.js Bindings)
4975
- [java-libbitcoinconsensus](https://github.com/dexX7/java-libbitcoinconsensus) (Java Bindings)
5076
- [bitcoinconsensus-php](https://github.com/Bit-Wasp/bitcoinconsensus-php) (PHP Bindings)
77+
- [rust-bitcoinconsensus](https://github.com/rust-bitcoin/rust-bitcoinconsensus) (Rust Bindings)

src/script/bitcoinconsensus.cpp

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,34 @@ static bool verify_flags(unsigned int flags)
7272

7373
static int verify_script(const unsigned char *scriptPubKey, unsigned int scriptPubKeyLen, CAmount amount,
7474
const unsigned char *txTo , unsigned int txToLen,
75+
const UTXO *spentOutputs, unsigned int spentOutputsLen,
7576
unsigned int nIn, unsigned int flags, bitcoinconsensus_error* err)
7677
{
7778
if (!verify_flags(flags)) {
7879
return set_error(err, bitcoinconsensus_ERR_INVALID_FLAGS);
7980
}
81+
82+
if (flags & bitcoinconsensus_SCRIPT_FLAGS_VERIFY_TAPROOT && spentOutputs == nullptr) {
83+
return set_error(err, bitcoinconsensus_ERR_SPENT_OUTPUTS_REQUIRED);
84+
}
85+
8086
try {
8187
TxInputStream stream(PROTOCOL_VERSION, txTo, txToLen);
8288
CTransaction tx(deserialize, stream);
89+
90+
std::vector<CTxOut> spent_outputs;
91+
if (spentOutputs != nullptr) {
92+
if (spentOutputsLen != tx.vin.size()) {
93+
return set_error(err, bitcoinconsensus_ERR_SPENT_OUTPUTS_MISMATCH);
94+
}
95+
for (size_t i = 0; i < spentOutputsLen; i++) {
96+
CScript spk = CScript(spentOutputs[i].scriptPubKey, spentOutputs[i].scriptPubKey + spentOutputs[i].scriptPubKeySize);
97+
const CAmount& value = spentOutputs[i].value;
98+
CTxOut tx_out = CTxOut(value, spk);
99+
spent_outputs.push_back(tx_out);
100+
}
101+
}
102+
83103
if (nIn >= tx.vin.size())
84104
return set_error(err, bitcoinconsensus_ERR_TX_INDEX);
85105
if (GetSerializeSize(tx, PROTOCOL_VERSION) != txToLen)
@@ -89,18 +109,34 @@ static int verify_script(const unsigned char *scriptPubKey, unsigned int scriptP
89109
set_error(err, bitcoinconsensus_ERR_OK);
90110

91111
PrecomputedTransactionData txdata(tx);
112+
113+
if (spentOutputs != nullptr && flags & bitcoinconsensus_SCRIPT_FLAGS_VERIFY_TAPROOT) {
114+
txdata.Init(tx, std::move(spent_outputs));
115+
}
116+
92117
return VerifyScript(tx.vin[nIn].scriptSig, CScript(scriptPubKey, scriptPubKey + scriptPubKeyLen), &tx.vin[nIn].scriptWitness, flags, TransactionSignatureChecker(&tx, nIn, amount, txdata, MissingDataBehavior::FAIL), nullptr);
93118
} catch (const std::exception&) {
94119
return set_error(err, bitcoinconsensus_ERR_TX_DESERIALIZE); // Error deserializing
95120
}
96121
}
97122

123+
int bitcoinconsensus_verify_script_with_spent_outputs(const unsigned char *scriptPubKey, unsigned int scriptPubKeyLen, int64_t amount,
124+
const unsigned char *txTo , unsigned int txToLen,
125+
const UTXO *spentOutputs, unsigned int spentOutputsLen,
126+
unsigned int nIn, unsigned int flags, bitcoinconsensus_error* err)
127+
{
128+
CAmount am(amount);
129+
return ::verify_script(scriptPubKey, scriptPubKeyLen, am, txTo, txToLen, spentOutputs, spentOutputsLen, nIn, flags, err);
130+
}
131+
98132
int bitcoinconsensus_verify_script_with_amount(const unsigned char *scriptPubKey, unsigned int scriptPubKeyLen, int64_t amount,
99133
const unsigned char *txTo , unsigned int txToLen,
100134
unsigned int nIn, unsigned int flags, bitcoinconsensus_error* err)
101135
{
102136
CAmount am(amount);
103-
return ::verify_script(scriptPubKey, scriptPubKeyLen, am, txTo, txToLen, nIn, flags, err);
137+
UTXO *spentOutputs = nullptr;
138+
unsigned int spentOutputsLen = 0;
139+
return ::verify_script(scriptPubKey, scriptPubKeyLen, am, txTo, txToLen, spentOutputs, spentOutputsLen, nIn, flags, err);
104140
}
105141

106142

@@ -113,7 +149,9 @@ int bitcoinconsensus_verify_script(const unsigned char *scriptPubKey, unsigned i
113149
}
114150

115151
CAmount am(0);
116-
return ::verify_script(scriptPubKey, scriptPubKeyLen, am, txTo, txToLen, nIn, flags, err);
152+
UTXO *spentOutputs = nullptr;
153+
unsigned int spentOutputsLen = 0;
154+
return ::verify_script(scriptPubKey, scriptPubKeyLen, am, txTo, txToLen, spentOutputs, spentOutputsLen, nIn, flags, err);
117155
}
118156

119157
unsigned int bitcoinconsensus_version()

src/script/bitcoinconsensus.h

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
extern "C" {
3232
#endif
3333

34-
#define BITCOINCONSENSUS_API_VER 1
34+
#define BITCOINCONSENSUS_API_VER 2
3535

3636
typedef enum bitcoinconsensus_error_t
3737
{
@@ -41,6 +41,8 @@ typedef enum bitcoinconsensus_error_t
4141
bitcoinconsensus_ERR_TX_DESERIALIZE,
4242
bitcoinconsensus_ERR_AMOUNT_REQUIRED,
4343
bitcoinconsensus_ERR_INVALID_FLAGS,
44+
bitcoinconsensus_ERR_SPENT_OUTPUTS_REQUIRED,
45+
bitcoinconsensus_ERR_SPENT_OUTPUTS_MISMATCH
4446
} bitcoinconsensus_error;
4547

4648
/** Script verification flags */
@@ -53,11 +55,19 @@ enum
5355
bitcoinconsensus_SCRIPT_FLAGS_VERIFY_CHECKLOCKTIMEVERIFY = (1U << 9), // enable CHECKLOCKTIMEVERIFY (BIP65)
5456
bitcoinconsensus_SCRIPT_FLAGS_VERIFY_CHECKSEQUENCEVERIFY = (1U << 10), // enable CHECKSEQUENCEVERIFY (BIP112)
5557
bitcoinconsensus_SCRIPT_FLAGS_VERIFY_WITNESS = (1U << 11), // enable WITNESS (BIP141)
58+
bitcoinconsensus_SCRIPT_FLAGS_VERIFY_TAPROOT = (1U << 17), // enable TAPROOT (BIPs 341 & 342)
5659
bitcoinconsensus_SCRIPT_FLAGS_VERIFY_ALL = bitcoinconsensus_SCRIPT_FLAGS_VERIFY_P2SH | bitcoinconsensus_SCRIPT_FLAGS_VERIFY_DERSIG |
5760
bitcoinconsensus_SCRIPT_FLAGS_VERIFY_NULLDUMMY | bitcoinconsensus_SCRIPT_FLAGS_VERIFY_CHECKLOCKTIMEVERIFY |
58-
bitcoinconsensus_SCRIPT_FLAGS_VERIFY_CHECKSEQUENCEVERIFY | bitcoinconsensus_SCRIPT_FLAGS_VERIFY_WITNESS
61+
bitcoinconsensus_SCRIPT_FLAGS_VERIFY_CHECKSEQUENCEVERIFY | bitcoinconsensus_SCRIPT_FLAGS_VERIFY_WITNESS |
62+
bitcoinconsensus_SCRIPT_FLAGS_VERIFY_TAPROOT
5963
};
6064

65+
typedef struct {
66+
const unsigned char *scriptPubKey;
67+
unsigned int scriptPubKeySize;
68+
int64_t value;
69+
} UTXO;
70+
6171
/// Returns 1 if the input nIn of the serialized transaction pointed to by
6272
/// txTo correctly spends the scriptPubKey pointed to by scriptPubKey under
6373
/// the additional constraints specified by flags.
@@ -70,6 +80,11 @@ EXPORT_SYMBOL int bitcoinconsensus_verify_script_with_amount(const unsigned char
7080
const unsigned char *txTo , unsigned int txToLen,
7181
unsigned int nIn, unsigned int flags, bitcoinconsensus_error* err);
7282

83+
EXPORT_SYMBOL int bitcoinconsensus_verify_script_with_spent_outputs(const unsigned char *scriptPubKey, unsigned int scriptPubKeyLen, int64_t amount,
84+
const unsigned char *txTo , unsigned int txToLen,
85+
const UTXO *spentOutputs, unsigned int spentOutputsLen,
86+
unsigned int nIn, unsigned int flags, bitcoinconsensus_error* err);
87+
7388
EXPORT_SYMBOL unsigned int bitcoinconsensus_version();
7489

7590
#ifdef __cplusplus

src/test/fuzz/script_bitcoin_consensus.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,23 @@ FUZZ_TARGET(script_bitcoin_consensus)
2828
}
2929
(void)bitcoinconsensus_verify_script(random_bytes_1.data(), random_bytes_1.size(), random_bytes_2.data(), random_bytes_2.size(), n_in, flags, err_p);
3030
(void)bitcoinconsensus_verify_script_with_amount(random_bytes_1.data(), random_bytes_1.size(), money, random_bytes_2.data(), random_bytes_2.size(), n_in, flags, err_p);
31+
32+
std::vector<UTXO> spent_outputs;
33+
std::vector<std::vector<unsigned char>> spent_spks;
34+
if (n_in <= 24386) {
35+
spent_outputs.reserve(n_in);
36+
spent_spks.reserve(n_in);
37+
for (size_t i = 0; i < n_in; ++i) {
38+
spent_spks.push_back(ConsumeRandomLengthByteVector(fuzzed_data_provider));
39+
const CAmount value{ConsumeMoney(fuzzed_data_provider)};
40+
const auto spk_size{static_cast<unsigned>(spent_spks.back().size())};
41+
spent_outputs.push_back({.scriptPubKey = spent_spks.back().data(), .scriptPubKeySize = spk_size, .value = value});
42+
}
43+
}
44+
45+
const auto spent_outs_size{static_cast<unsigned>(spent_outputs.size())};
46+
47+
(void)bitcoinconsensus_verify_script_with_spent_outputs(
48+
random_bytes_1.data(), random_bytes_1.size(), money, random_bytes_2.data(), random_bytes_2.size(),
49+
spent_outputs.data(), spent_outs_size, n_in, flags, err_p);
3150
}

src/test/script_tests.cpp

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1637,6 +1637,37 @@ BOOST_AUTO_TEST_CASE(bitcoinconsensus_verify_script_invalid_flags)
16371637
BOOST_CHECK_EQUAL(err, bitcoinconsensus_ERR_INVALID_FLAGS);
16381638
}
16391639

1640+
/* Test bitcoinconsensus_verify_script returns spent outputs required err */
1641+
BOOST_AUTO_TEST_CASE(bitcoinconsensus_verify_script_spent_outputs_required_err)
1642+
{
1643+
unsigned int libconsensus_flags{bitcoinconsensus_SCRIPT_FLAGS_VERIFY_TAPROOT};
1644+
const int nIn{0};
1645+
1646+
CScript scriptPubKey;
1647+
CScript scriptSig;
1648+
CScriptWitness wit;
1649+
1650+
scriptPubKey << OP_EQUAL;
1651+
CTransaction creditTx{BuildCreditingTransaction(scriptPubKey, 1)};
1652+
CTransaction spendTx{BuildSpendingTransaction(scriptSig, wit, creditTx)};
1653+
1654+
CDataStream stream(SER_NETWORK, PROTOCOL_VERSION);
1655+
stream << spendTx;
1656+
1657+
bitcoinconsensus_error err;
1658+
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)};
1659+
BOOST_CHECK_EQUAL(result, 0);
1660+
BOOST_CHECK_EQUAL(err, bitcoinconsensus_ERR_SPENT_OUTPUTS_REQUIRED);
1661+
1662+
result = bitcoinconsensus_verify_script_with_amount(scriptPubKey.data(), scriptPubKey.size(), creditTx.vout[0].nValue, UCharCast(stream.data()), stream.size(), nIn, libconsensus_flags, &err);
1663+
BOOST_CHECK_EQUAL(result, 0);
1664+
BOOST_CHECK_EQUAL(err, bitcoinconsensus_ERR_SPENT_OUTPUTS_REQUIRED);
1665+
1666+
result = bitcoinconsensus_verify_script(scriptPubKey.data(), scriptPubKey.size(), UCharCast(stream.data()), stream.size(), nIn, libconsensus_flags, &err);
1667+
BOOST_CHECK_EQUAL(result, 0);
1668+
BOOST_CHECK_EQUAL(err, bitcoinconsensus_ERR_SPENT_OUTPUTS_REQUIRED);
1669+
}
1670+
16401671
#endif // defined(HAVE_CONSENSUS_LIB)
16411672

16421673
static std::vector<unsigned int> AllConsensusFlags()
@@ -1685,12 +1716,29 @@ static void AssetTest(const UniValue& test)
16851716
PrecomputedTransactionData txdata;
16861717
txdata.Init(tx, std::vector<CTxOut>(prevouts));
16871718
CachingTransactionSignatureChecker txcheck(&tx, idx, prevouts[idx].nValue, true, txdata);
1719+
1720+
#if defined(HAVE_CONSENSUS_LIB)
1721+
CDataStream stream(SER_NETWORK, PROTOCOL_VERSION);
1722+
stream << tx;
1723+
std::vector<UTXO> utxos;
1724+
utxos.resize(prevouts.size());
1725+
for (size_t i = 0; i < prevouts.size(); i++) {
1726+
utxos[i].scriptPubKey = prevouts[i].scriptPubKey.data();
1727+
utxos[i].scriptPubKeySize = prevouts[i].scriptPubKey.size();
1728+
utxos[i].value = prevouts[i].nValue;
1729+
}
1730+
#endif
1731+
16881732
for (const auto flags : ALL_CONSENSUS_FLAGS) {
16891733
// "final": true tests are valid for all flags. Others are only valid with flags that are
16901734
// a subset of test_flags.
16911735
if (fin || ((flags & test_flags) == flags)) {
16921736
bool ret = VerifyScript(tx.vin[idx].scriptSig, prevouts[idx].scriptPubKey, &tx.vin[idx].scriptWitness, flags, txcheck, nullptr);
16931737
BOOST_CHECK(ret);
1738+
#if defined(HAVE_CONSENSUS_LIB)
1739+
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);
1740+
BOOST_CHECK(lib_ret == 1);
1741+
#endif
16941742
}
16951743
}
16961744
}
@@ -1702,11 +1750,28 @@ static void AssetTest(const UniValue& test)
17021750
PrecomputedTransactionData txdata;
17031751
txdata.Init(tx, std::vector<CTxOut>(prevouts));
17041752
CachingTransactionSignatureChecker txcheck(&tx, idx, prevouts[idx].nValue, true, txdata);
1753+
1754+
#if defined(HAVE_CONSENSUS_LIB)
1755+
CDataStream stream(SER_NETWORK, PROTOCOL_VERSION);
1756+
stream << tx;
1757+
std::vector<UTXO> utxos;
1758+
utxos.resize(prevouts.size());
1759+
for (size_t i = 0; i < prevouts.size(); i++) {
1760+
utxos[i].scriptPubKey = prevouts[i].scriptPubKey.data();
1761+
utxos[i].scriptPubKeySize = prevouts[i].scriptPubKey.size();
1762+
utxos[i].value = prevouts[i].nValue;
1763+
}
1764+
#endif
1765+
17051766
for (const auto flags : ALL_CONSENSUS_FLAGS) {
17061767
// If a test is supposed to fail with test_flags, it should also fail with any superset thereof.
17071768
if ((flags & test_flags) == test_flags) {
17081769
bool ret = VerifyScript(tx.vin[idx].scriptSig, prevouts[idx].scriptPubKey, &tx.vin[idx].scriptWitness, flags, txcheck, nullptr);
17091770
BOOST_CHECK(!ret);
1771+
#if defined(HAVE_CONSENSUS_LIB)
1772+
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);
1773+
BOOST_CHECK(lib_ret == 0);
1774+
#endif
17101775
}
17111776
}
17121777
}

0 commit comments

Comments
 (0)