aboutsummaryrefslogtreecommitdiff
path: root/src/test/fuzz/txorphan.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/fuzz/txorphan.cpp')
-rw-r--r--src/test/fuzz/txorphan.cpp43
1 files changed, 17 insertions, 26 deletions
diff --git a/src/test/fuzz/txorphan.cpp b/src/test/fuzz/txorphan.cpp
index a44f47b00d..7bebb987b1 100644
--- a/src/test/fuzz/txorphan.cpp
+++ b/src/test/fuzz/txorphan.cpp
@@ -37,13 +37,12 @@ FUZZ_TARGET(txorphan, .init = initialize_orphanage)
SetMockTime(ConsumeTime(fuzzed_data_provider));
TxOrphanage orphanage;
- std::vector<COutPoint> outpoints;
+ std::set<COutPoint> outpoints;
+
// initial outpoints used to construct transactions later
for (uint8_t i = 0; i < 4; i++) {
- outpoints.emplace_back(Txid::FromUint256(uint256{i}), 0);
+ outpoints.emplace(Txid::FromUint256(uint256{i}), 0);
}
- // if true, allow duplicate input when constructing tx
- const bool duplicate_input = fuzzed_data_provider.ConsumeBool();
CTransactionRef ptx_potential_parent = nullptr;
@@ -53,29 +52,22 @@ FUZZ_TARGET(txorphan, .init = initialize_orphanage)
const CTransactionRef tx = [&] {
CMutableTransaction tx_mut;
const auto num_in = fuzzed_data_provider.ConsumeIntegralInRange<uint32_t>(1, outpoints.size());
- const auto num_out = fuzzed_data_provider.ConsumeIntegralInRange<uint32_t>(1, outpoints.size());
- // pick unique outpoints from outpoints as input
+ const auto num_out = fuzzed_data_provider.ConsumeIntegralInRange<uint32_t>(1, 256);
+ // pick outpoints from outpoints as input. We allow input duplicates on purpose, given we are not
+ // running any transaction validation logic before adding transactions to the orphanage
for (uint32_t i = 0; i < num_in; i++) {
auto& prevout = PickValue(fuzzed_data_provider, outpoints);
- tx_mut.vin.emplace_back(prevout);
- // pop the picked outpoint if duplicate input is not allowed
- if (!duplicate_input) {
- std::swap(prevout, outpoints.back());
- outpoints.pop_back();
- }
+ // try making transactions unique by setting a random nSequence, but allow duplicate transactions if they happen
+ tx_mut.vin.emplace_back(prevout, CScript{}, fuzzed_data_provider.ConsumeIntegralInRange<uint32_t>(0, CTxIn::SEQUENCE_FINAL));
}
// output amount will not affect txorphanage
for (uint32_t i = 0; i < num_out; i++) {
tx_mut.vout.emplace_back(CAmount{0}, CScript{});
}
- // restore previously popped outpoints
- for (auto& in : tx_mut.vin) {
- outpoints.push_back(in.prevout);
- }
auto new_tx = MakeTransactionRef(tx_mut);
- // add newly constructed transaction to outpoints
+ // add newly constructed outpoints to the coin pool
for (uint32_t i = 0; i < num_out; i++) {
- outpoints.emplace_back(new_tx->GetHash(), i);
+ outpoints.emplace(new_tx->GetHash(), i);
}
return new_tx;
}();
@@ -112,13 +104,12 @@ FUZZ_TARGET(txorphan, .init = initialize_orphanage)
{
CTransactionRef ref = orphanage.GetTxToReconsider(peer_id);
if (ref) {
- bool have_tx = orphanage.HaveTx(GenTxid::Txid(ref->GetHash())) || orphanage.HaveTx(GenTxid::Wtxid(ref->GetWitnessHash()));
- Assert(have_tx);
+ Assert(orphanage.HaveTx(ref->GetWitnessHash()));
}
}
},
[&] {
- bool have_tx = orphanage.HaveTx(GenTxid::Txid(tx->GetHash())) || orphanage.HaveTx(GenTxid::Wtxid(tx->GetWitnessHash()));
+ bool have_tx = orphanage.HaveTx(tx->GetWitnessHash());
// AddTx should return false if tx is too big or already have it
// tx weight is unknown, we only check when tx is already in orphanage
{
@@ -126,7 +117,7 @@ FUZZ_TARGET(txorphan, .init = initialize_orphanage)
// have_tx == true -> add_tx == false
Assert(!have_tx || !add_tx);
}
- have_tx = orphanage.HaveTx(GenTxid::Txid(tx->GetHash())) || orphanage.HaveTx(GenTxid::Wtxid(tx->GetWitnessHash()));
+ have_tx = orphanage.HaveTx(tx->GetWitnessHash());
{
bool add_tx = orphanage.AddTx(tx, peer_id);
// if have_tx is still false, it must be too big
@@ -135,15 +126,15 @@ FUZZ_TARGET(txorphan, .init = initialize_orphanage)
}
},
[&] {
- bool have_tx = orphanage.HaveTx(GenTxid::Txid(tx->GetHash())) || orphanage.HaveTx(GenTxid::Wtxid(tx->GetWitnessHash()));
+ bool have_tx = orphanage.HaveTx(tx->GetWitnessHash());
// EraseTx should return 0 if m_orphans doesn't have the tx
{
- Assert(have_tx == orphanage.EraseTx(tx->GetHash()));
+ Assert(have_tx == orphanage.EraseTx(tx->GetWitnessHash()));
}
- have_tx = orphanage.HaveTx(GenTxid::Txid(tx->GetHash())) || orphanage.HaveTx(GenTxid::Wtxid(tx->GetWitnessHash()));
+ have_tx = orphanage.HaveTx(tx->GetWitnessHash());
// have_tx should be false and EraseTx should fail
{
- Assert(!have_tx && !orphanage.EraseTx(tx->GetHash()));
+ Assert(!have_tx && !orphanage.EraseTx(tx->GetWitnessHash()));
}
},
[&] {