mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-04-20 11:49:07 +02:00
Use ParamsWrapper for witness serialization
This commit is contained in:
@@ -31,7 +31,7 @@ FUZZ_TARGET(block, .init = initialize_block)
|
||||
int nVersion;
|
||||
ds >> nVersion;
|
||||
ds.SetVersion(nVersion);
|
||||
ds >> block;
|
||||
ds >> TX_WITH_WITNESS(block);
|
||||
} catch (const std::ios_base::failure&) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ FUZZ_TARGET(bloom_filter)
|
||||
assert(present);
|
||||
},
|
||||
[&] {
|
||||
const std::optional<CMutableTransaction> mut_tx = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider);
|
||||
const std::optional<CMutableTransaction> mut_tx = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider, TX_WITH_WITNESS);
|
||||
if (!mut_tx) {
|
||||
good_data = false;
|
||||
return;
|
||||
|
||||
@@ -114,7 +114,7 @@ FUZZ_TARGET(coins_view, .init = initialize_coins_view)
|
||||
random_coin = *opt_coin;
|
||||
},
|
||||
[&] {
|
||||
const std::optional<CMutableTransaction> opt_mutable_transaction = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider);
|
||||
const std::optional<CMutableTransaction> opt_mutable_transaction = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider, TX_WITH_WITNESS);
|
||||
if (!opt_mutable_transaction) {
|
||||
good_data = false;
|
||||
return;
|
||||
|
||||
@@ -217,7 +217,7 @@ FUZZ_TARGET_DESERIALIZE(psbt_output_deserialize, {
|
||||
})
|
||||
FUZZ_TARGET_DESERIALIZE(block_deserialize, {
|
||||
CBlock block;
|
||||
DeserializeFromFuzzingInput(buffer, block);
|
||||
DeserializeFromFuzzingInput(buffer, TX_WITH_WITNESS(block));
|
||||
})
|
||||
FUZZ_TARGET_DESERIALIZE(blocklocator_deserialize, {
|
||||
CBlockLocator bl;
|
||||
@@ -225,7 +225,7 @@ FUZZ_TARGET_DESERIALIZE(blocklocator_deserialize, {
|
||||
})
|
||||
FUZZ_TARGET_DESERIALIZE(blockmerkleroot, {
|
||||
CBlock block;
|
||||
DeserializeFromFuzzingInput(buffer, block);
|
||||
DeserializeFromFuzzingInput(buffer, TX_WITH_WITNESS(block));
|
||||
bool mutated;
|
||||
BlockMerkleRoot(block, &mutated);
|
||||
})
|
||||
|
||||
@@ -27,7 +27,7 @@ FUZZ_TARGET(merkleblock)
|
||||
},
|
||||
[&] {
|
||||
CMerkleBlock merkle_block;
|
||||
const std::optional<CBlock> opt_block = ConsumeDeserializable<CBlock>(fuzzed_data_provider);
|
||||
const std::optional<CBlock> opt_block = ConsumeDeserializable<CBlock>(fuzzed_data_provider, TX_WITH_WITNESS);
|
||||
CBloomFilter bloom_filter;
|
||||
std::set<uint256> txids;
|
||||
if (opt_block && !opt_block->vtx.empty()) {
|
||||
|
||||
@@ -44,7 +44,7 @@ FUZZ_TARGET(partially_downloaded_block, .init = initialize_pdb)
|
||||
{
|
||||
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
|
||||
|
||||
auto block{ConsumeDeserializable<CBlock>(fuzzed_data_provider)};
|
||||
auto block{ConsumeDeserializable<CBlock>(fuzzed_data_provider, TX_WITH_WITNESS)};
|
||||
if (!block || block->vtx.size() == 0 ||
|
||||
block->vtx.size() >= std::numeric_limits<uint16_t>::max()) {
|
||||
return;
|
||||
|
||||
@@ -37,7 +37,7 @@ FUZZ_TARGET(policy_estimator, .init = initialize_policy_estimator)
|
||||
CallOneOf(
|
||||
fuzzed_data_provider,
|
||||
[&] {
|
||||
const std::optional<CMutableTransaction> mtx = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider);
|
||||
const std::optional<CMutableTransaction> mtx = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider, TX_WITH_WITNESS);
|
||||
if (!mtx) {
|
||||
good_data = false;
|
||||
return;
|
||||
@@ -52,7 +52,7 @@ FUZZ_TARGET(policy_estimator, .init = initialize_policy_estimator)
|
||||
std::vector<CTxMemPoolEntry> mempool_entries;
|
||||
LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 10000)
|
||||
{
|
||||
const std::optional<CMutableTransaction> mtx = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider);
|
||||
const std::optional<CMutableTransaction> mtx = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider, TX_WITH_WITNESS);
|
||||
if (!mtx) {
|
||||
good_data = false;
|
||||
break;
|
||||
|
||||
@@ -24,8 +24,8 @@ FUZZ_TARGET(primitives_transaction)
|
||||
const CTxOut tx_out_1{ConsumeMoney(fuzzed_data_provider), script};
|
||||
const CTxOut tx_out_2{ConsumeMoney(fuzzed_data_provider), ConsumeScript(fuzzed_data_provider)};
|
||||
assert((tx_out_1 == tx_out_2) != (tx_out_1 != tx_out_2));
|
||||
const std::optional<CMutableTransaction> mutable_tx_1 = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider);
|
||||
const std::optional<CMutableTransaction> mutable_tx_2 = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider);
|
||||
const std::optional<CMutableTransaction> mutable_tx_1 = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider, TX_WITH_WITNESS);
|
||||
const std::optional<CMutableTransaction> mutable_tx_2 = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider, TX_WITH_WITNESS);
|
||||
if (mutable_tx_1 && mutable_tx_2) {
|
||||
const CTransaction tx_1{*mutable_tx_1};
|
||||
const CTransaction tx_2{*mutable_tx_2};
|
||||
|
||||
@@ -33,7 +33,7 @@ FUZZ_TARGET(rbf, .init = initialize_rbf)
|
||||
{
|
||||
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
|
||||
SetMockTime(ConsumeTime(fuzzed_data_provider));
|
||||
std::optional<CMutableTransaction> mtx = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider);
|
||||
std::optional<CMutableTransaction> mtx = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider, TX_WITH_WITNESS);
|
||||
if (!mtx) {
|
||||
return;
|
||||
}
|
||||
@@ -42,7 +42,7 @@ FUZZ_TARGET(rbf, .init = initialize_rbf)
|
||||
|
||||
LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 10000)
|
||||
{
|
||||
const std::optional<CMutableTransaction> another_mtx = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider);
|
||||
const std::optional<CMutableTransaction> another_mtx = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider, TX_WITH_WITNESS);
|
||||
if (!another_mtx) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -249,13 +249,13 @@ std::string ConsumeScalarRPCArgument(FuzzedDataProvider& fuzzed_data_provider, b
|
||||
},
|
||||
[&] {
|
||||
// hex encoded block
|
||||
std::optional<CBlock> opt_block = ConsumeDeserializable<CBlock>(fuzzed_data_provider);
|
||||
std::optional<CBlock> opt_block = ConsumeDeserializable<CBlock>(fuzzed_data_provider, TX_WITH_WITNESS);
|
||||
if (!opt_block) {
|
||||
good_data = false;
|
||||
return;
|
||||
}
|
||||
CDataStream data_stream{SER_NETWORK, PROTOCOL_VERSION};
|
||||
data_stream << *opt_block;
|
||||
data_stream << TX_WITH_WITNESS(*opt_block);
|
||||
r = HexStr(data_stream);
|
||||
},
|
||||
[&] {
|
||||
@@ -271,13 +271,14 @@ std::string ConsumeScalarRPCArgument(FuzzedDataProvider& fuzzed_data_provider, b
|
||||
},
|
||||
[&] {
|
||||
// hex encoded tx
|
||||
std::optional<CMutableTransaction> opt_tx = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider);
|
||||
std::optional<CMutableTransaction> opt_tx = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider, TX_WITH_WITNESS);
|
||||
if (!opt_tx) {
|
||||
good_data = false;
|
||||
return;
|
||||
}
|
||||
CDataStream data_stream{SER_NETWORK, fuzzed_data_provider.ConsumeBool() ? PROTOCOL_VERSION : (PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS)};
|
||||
data_stream << *opt_tx;
|
||||
DataStream data_stream;
|
||||
auto allow_witness = (fuzzed_data_provider.ConsumeBool() ? TX_WITH_WITNESS : TX_NO_WITNESS);
|
||||
data_stream << allow_witness(*opt_tx);
|
||||
r = HexStr(data_stream);
|
||||
},
|
||||
[&] {
|
||||
|
||||
@@ -54,7 +54,7 @@ CMutableTransaction TxFromHex(const std::string& str)
|
||||
{
|
||||
CMutableTransaction tx;
|
||||
try {
|
||||
SpanReader{SERIALIZE_TRANSACTION_NO_WITNESS, CheckedParseHex(str)} >> tx;
|
||||
SpanReader{0, CheckedParseHex(str)} >> TX_NO_WITNESS(tx);
|
||||
} catch (const std::ios_base::failure&) {
|
||||
throw std::runtime_error("Tx deserialization failure");
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ FUZZ_TARGET(script_flags)
|
||||
}
|
||||
|
||||
try {
|
||||
const CTransaction tx(deserialize, ds);
|
||||
const CTransaction tx(deserialize, TX_WITH_WITNESS, ds);
|
||||
|
||||
unsigned int verify_flags;
|
||||
ds >> verify_flags;
|
||||
|
||||
@@ -20,13 +20,13 @@ FUZZ_TARGET(script_interpreter)
|
||||
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
|
||||
{
|
||||
const CScript script_code = ConsumeScript(fuzzed_data_provider);
|
||||
const std::optional<CMutableTransaction> mtx = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider);
|
||||
const std::optional<CMutableTransaction> mtx = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider, TX_WITH_WITNESS);
|
||||
if (mtx) {
|
||||
const CTransaction tx_to{*mtx};
|
||||
const unsigned int in = fuzzed_data_provider.ConsumeIntegral<unsigned int>();
|
||||
if (in < tx_to.vin.size()) {
|
||||
(void)SignatureHash(script_code, tx_to, in, fuzzed_data_provider.ConsumeIntegral<int>(), ConsumeMoney(fuzzed_data_provider), fuzzed_data_provider.PickValueInArray({SigVersion::BASE, SigVersion::WITNESS_V0}), nullptr);
|
||||
const std::optional<CMutableTransaction> mtx_precomputed = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider);
|
||||
const std::optional<CMutableTransaction> mtx_precomputed = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider, TX_WITH_WITNESS);
|
||||
if (mtx_precomputed) {
|
||||
const CTransaction tx_precomputed{*mtx_precomputed};
|
||||
const PrecomputedTransactionData precomputed_transaction_data{tx_precomputed};
|
||||
|
||||
@@ -30,7 +30,7 @@ FUZZ_TARGET(script_sigcache, .init = initialize_script_sigcache)
|
||||
{
|
||||
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
|
||||
|
||||
const std::optional<CMutableTransaction> mutable_transaction = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider);
|
||||
const std::optional<CMutableTransaction> mutable_transaction = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider, TX_WITH_WITNESS);
|
||||
const CTransaction tx{mutable_transaction ? *mutable_transaction : CMutableTransaction{}};
|
||||
const unsigned int n_in = fuzzed_data_provider.ConsumeIntegral<unsigned int>();
|
||||
const CAmount amount = ConsumeMoney(fuzzed_data_provider);
|
||||
|
||||
@@ -86,7 +86,7 @@ FUZZ_TARGET(script_sign, .init = initialize_script_sign)
|
||||
}
|
||||
|
||||
{
|
||||
const std::optional<CMutableTransaction> mutable_transaction = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider);
|
||||
const std::optional<CMutableTransaction> mutable_transaction = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider, TX_WITH_WITNESS);
|
||||
const std::optional<CTxOut> tx_out = ConsumeDeserializable<CTxOut>(fuzzed_data_provider);
|
||||
const unsigned int n_in = fuzzed_data_provider.ConsumeIntegral<unsigned int>();
|
||||
if (mutable_transaction && tx_out && mutable_transaction->vin.size() > n_in) {
|
||||
@@ -100,7 +100,7 @@ FUZZ_TARGET(script_sign, .init = initialize_script_sign)
|
||||
if (mutable_transaction) {
|
||||
CTransaction tx_from{*mutable_transaction};
|
||||
CMutableTransaction tx_to;
|
||||
const std::optional<CMutableTransaction> opt_tx_to = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider);
|
||||
const std::optional<CMutableTransaction> opt_tx_to = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider, TX_WITH_WITNESS);
|
||||
if (opt_tx_to) {
|
||||
tx_to = *opt_tx_to;
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ void initialize_signet()
|
||||
FUZZ_TARGET(signet, .init = initialize_signet)
|
||||
{
|
||||
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
|
||||
const std::optional<CBlock> block = ConsumeDeserializable<CBlock>(fuzzed_data_provider);
|
||||
const std::optional<CBlock> block = ConsumeDeserializable<CBlock>(fuzzed_data_provider, TX_WITH_WITNESS);
|
||||
if (!block) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ FUZZ_TARGET(transaction, .init = initialize_transaction)
|
||||
bool valid_tx = true;
|
||||
const CTransaction tx = [&] {
|
||||
try {
|
||||
return CTransaction(deserialize, ds);
|
||||
return CTransaction(deserialize, TX_WITH_WITNESS, ds);
|
||||
} catch (const std::ios_base::failure&) {
|
||||
valid_tx = false;
|
||||
return CTransaction{CMutableTransaction{}};
|
||||
@@ -53,7 +53,7 @@ FUZZ_TARGET(transaction, .init = initialize_transaction)
|
||||
int nVersion;
|
||||
ds_mtx >> nVersion;
|
||||
ds_mtx.SetVersion(nVersion);
|
||||
ds_mtx >> mutable_tx;
|
||||
ds_mtx >> TX_WITH_WITNESS(mutable_tx);
|
||||
} catch (const std::ios_base::failure&) {
|
||||
valid_mutable_tx = false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user