aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMacroFake <falke.marco@gmail.com>2022-07-18 15:05:37 +0200
committerMacroFake <falke.marco@gmail.com>2022-07-18 15:05:39 +0200
commitc395c8d6bbd0afc836eac4e58c00a816fb967104 (patch)
tree5b99562ac45b87692c6648dc3fe3c3e33f21dee9
parentd806407173926e46421ad807750a06e49afbbdbd (diff)
parent2315830491b2cfa6b6e3e277700238e5ac92a8e0 (diff)
Merge bitcoin/bitcoin#25624: fuzz: Fix assert bug in txorphan target
2315830491b2cfa6b6e3e277700238e5ac92a8e0 fuzz: Fix assert bug in txorphan target (chinggg) Pull request description: Fix https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=48914. It is possible to construct big tx that got rejected in `AddTx`, so we cannot assume tx will be added successfully. We can only guarantee tx will not be added if orphanage already has it. ACKs for top commit: MarcoFalke: lgtm ACK 2315830491b2cfa6b6e3e277700238e5ac92a8e0 Tree-SHA512: e173bc1a932639746de1192ed238e2e2318899f55371febb598facd0e811d8c54997f074f5e761757e1ffd3ae76d8edf9d673f020b2d97d5762ac656f632be81
-rw-r--r--src/test/fuzz/txorphan.cpp16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/test/fuzz/txorphan.cpp b/src/test/fuzz/txorphan.cpp
index d318baa6a2..b18d783259 100644
--- a/src/test/fuzz/txorphan.cpp
+++ b/src/test/fuzz/txorphan.cpp
@@ -3,8 +3,10 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <consensus/amount.h>
-#include <net.h>
+#include <consensus/validation.h>
#include <net_processing.h>
+#include <node/eviction.h>
+#include <policy/policy.h>
#include <primitives/transaction.h>
#include <script/script.h>
#include <sync.h>
@@ -99,16 +101,20 @@ FUZZ_TARGET_INIT(txorphan, initialize_orphanage)
[&] {
bool have_tx = orphanage.HaveTx(GenTxid::Txid(tx->GetHash())) || orphanage.HaveTx(GenTxid::Wtxid(tx->GetHash()));
// 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
{
LOCK(g_cs_orphans);
- Assert(have_tx != orphanage.AddTx(tx, peer_id));
+ bool add_tx = orphanage.AddTx(tx, peer_id);
+ // have_tx == true -> add_tx == false
+ Assert(!have_tx || !add_tx);
}
have_tx = orphanage.HaveTx(GenTxid::Txid(tx->GetHash())) || orphanage.HaveTx(GenTxid::Wtxid(tx->GetHash()));
- // tx should already be added since it will not be too big in the test
- // have_tx should be true and AddTx should fail
{
LOCK(g_cs_orphans);
- Assert(have_tx && !orphanage.AddTx(tx, peer_id));
+ bool add_tx = orphanage.AddTx(tx, peer_id);
+ // if have_tx is still false, it must be too big
+ Assert(!have_tx == GetTransactionWeight(*tx) > MAX_STANDARD_TX_WEIGHT);
+ Assert(!have_tx || !add_tx);
}
},
[&] {