Skip to content

Commit c395c8d

Browse files
author
MacroFake
committed
Merge bitcoin/bitcoin#25624: fuzz: Fix assert bug in txorphan target
2315830 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 2315830 Tree-SHA512: e173bc1a932639746de1192ed238e2e2318899f55371febb598facd0e811d8c54997f074f5e761757e1ffd3ae76d8edf9d673f020b2d97d5762ac656f632be81
2 parents d806407 + 2315830 commit c395c8d

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/test/fuzz/txorphan.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

55
#include <consensus/amount.h>
6-
#include <net.h>
6+
#include <consensus/validation.h>
77
#include <net_processing.h>
8+
#include <node/eviction.h>
9+
#include <policy/policy.h>
810
#include <primitives/transaction.h>
911
#include <script/script.h>
1012
#include <sync.h>
@@ -99,16 +101,20 @@ FUZZ_TARGET_INIT(txorphan, initialize_orphanage)
99101
[&] {
100102
bool have_tx = orphanage.HaveTx(GenTxid::Txid(tx->GetHash())) || orphanage.HaveTx(GenTxid::Wtxid(tx->GetHash()));
101103
// AddTx should return false if tx is too big or already have it
104+
// tx weight is unknown, we only check when tx is already in orphanage
102105
{
103106
LOCK(g_cs_orphans);
104-
Assert(have_tx != orphanage.AddTx(tx, peer_id));
107+
bool add_tx = orphanage.AddTx(tx, peer_id);
108+
// have_tx == true -> add_tx == false
109+
Assert(!have_tx || !add_tx);
105110
}
106111
have_tx = orphanage.HaveTx(GenTxid::Txid(tx->GetHash())) || orphanage.HaveTx(GenTxid::Wtxid(tx->GetHash()));
107-
// tx should already be added since it will not be too big in the test
108-
// have_tx should be true and AddTx should fail
109112
{
110113
LOCK(g_cs_orphans);
111-
Assert(have_tx && !orphanage.AddTx(tx, peer_id));
114+
bool add_tx = orphanage.AddTx(tx, peer_id);
115+
// if have_tx is still false, it must be too big
116+
Assert(!have_tx == GetTransactionWeight(*tx) > MAX_STANDARD_TX_WEIGHT);
117+
Assert(!have_tx || !add_tx);
112118
}
113119
},
114120
[&] {

0 commit comments

Comments
 (0)