Repository navigation
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code Coverage & BenchmarksFor details see: https://corecheck.dev/bitcoin/bitcoin/pulls/33916. ReviewsSee the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste |
|
Coverage report is available at: https://brunoerg.xyz/bitcoin-core-coverage/33916/ |
janb84
left a comment
There was a problem hiding this comment.
ACK 2df9f10755ea7de94ecc9a17e6dd6dc89de0a637
PR adds new fuzzing target. Target wallet_tx_can_be_bumped.
Ran fuzzer for 2 hours without issues,
Codecoverage equals to what is reported.
New Target is NOT deterministic, but I'm also not sure what to change to make it deterministic (if it's even feasible)
This fuzzer increases fuzzing coverage :
| Totals master: | 69.81% (5082/7280) | 41.91% (10784/25729) | 62.64% (57301/91479) | 56.83% (39387/69312) | 56.96% (21311/37411) |
|---|---|---|---|---|---|
| Totals this PR | 70.58% (5142/7285) | 42.32% (10893/25742) | 63.09% (57787/91592) | 57.34% (39758/69343) | 57.28% (21428/37411) |
Big improvement area's:
Details
| master | src/wallet/transaction.cpp | 0.00% (0/6) | 0.00% (0/6) | 0.00% (0/41) | 0.00% (0/20) | 0.00% (0/16) |
|---|---|---|---|---|---|---|
| this PR | src/wallet/transaction.cpp | 33.33% (2/6) | 33.33% (2/6) | 41.46% (17/41) | 30.00% (6/20) | 31.25% (5/16) |
| master | src/wallet/transaction.h | 5.88% (3/51) | 2.42% (3/124) | 8.54% (14/164) | 6.45% (8/124) | 0.00% (0/42) |
|---|---|---|---|---|---|---|
| this PR | src/wallet/transaction.h | 49.02% (25/51) | 29.03% (36/124) | 50.61% (83/164) | 36.29% (45/124) | 4.76% (2/42) |
| master | src/wallet/wallet.cpp | 15.31% (32/209) | 15.17% (32/211) | 8.55% (273/3192) | 7.76% (239/3079) | 6.31% (97/1538) |
|---|---|---|---|---|---|---|
| this PR | src/wallet/wallet.cpp | 24.88% (52/209) | 24.64% (52/211) | 15.32% (489/3192) | 14.58% (449/3079) | 11.96% (184/1538) |
| master | src/wallet/wallet.h | 37.14% (13/35) | 24.14% (14/58) | 36.26% (33/91) | 24.84% (39/157) | 18.37% (9/49) |
|---|---|---|---|---|---|---|
| this PR | src/wallet/wallet.h | 40.00% (14/35) | 29.31% (17/58) | 41.76% (38/91) | 30.57% (48/157) | 20.41% (10/49) |
| master | src/wallet/walletdb.cpp | 15.66% (13/83) | 15.66% (13/83) | 4.77% (67/1404) | 4.38% (28/639) | 4.87% (15/308) |
|---|---|---|---|---|---|---|
| this PR | src/wallet/walletdb.cpp | 19.28% (16/83) | 19.28% (16/83) | 5.48% (77/1404) | 5.16% (33/639) | 5.19% (16/308) |
| master | src/wallet/walletdb.h | 33.33% (4/12) | 28.21% (11/39) | 31.03% (18/58) | 22.58% (7/31) | 10.00% (1/10) |
|---|---|---|---|---|---|---|
| this PR | src/wallet/walletdb.h | 33.33% (4/12) | 35.90% (14/39) | 31.03% (18/58) | 22.58% (7/31) | 10.00% (1/10) |
|
🚧 At least one of the CI tasks failed. HintsTry to run the tests locally, according to the documentation. However, a CI failure may still
Leave a comment here, if you need help tracking down a confusing failure. |
2df9f10 to
52101d8
Compare
|
Force-pushed 2df9f10755ea7de94ecc9a17e6dd6dc89de0a637..52101d8:
|
marcofleon
left a comment
There was a problem hiding this comment.
stack trace
New crash id='634d66ecc60e964ed9bba85b934f9baa7a64e5a3' (project='bitcoin' harness='wallet_tx_can_be_bumped')
Base64: Dv//AAAAAAAAAAEBABEAagAAAAAAAQEBALoAAQEAAAACAP8OAAAAAAAAAP9c+moAAAAAAAEBAQC6AAEBAAAAAgD/DgAAAAAAAAD/XPqhjQABAWnO4OVM4tnfVRhWW7nTooVXibgrN5NPkWxNBpYUnwaLLAAAAAAAAAABACEBEQBdAQAAAAACBAJc/////////wf6obkn+QAECgS5Jlx++QEAAAcANv8AAAD/////////////////////////////Sg==
===== stack trace =====
INFO: Running with entropic power schedule (0xFF, 100).
INFO: Seed: 3031401414
INFO: Loaded 1 modules (450738 inline 8-bit counters): 450738 [0x55a9d32cb070, 0x55a9d3339122),
INFO: Loaded 1 PC tables (450738 PCs): 450738 [0x55a9d3339128,0x55a9d3a19c48),
/workdir/out/libfuzzer_asan/fuzz: Running 1 inputs 1 time(s) each.
Running: /workdir/workspace/solutions/crash-1234378e4f8fc81e7ee93ee27fc4e2b593a2d6c6
=================================================================
==27852==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x7b695871ecbc at pc 0x55a9d2e1fdc0 bp 0x7ffe5e37ef80 sp 0x7ffe5e37ef78
READ of size 4 at 0x7b695871ecbc thread T0 (b-test)
#0 0x55a9d2e1fdbf in CScript::IsPayToScriptHash() const script.cpp
#1 0x55a9d19df908 in Solver(CScript const&, std::vector<std::vector<unsigned char, std::allocator<unsigned char>>, std::allocator<std::vector<unsigned char, std::allocator<unsigned char>>>>&) solver.cpp
#2 0x55a9d16187fc in ExtractDestination(CScript const&, std::variant<CNoDestination, PubKeyDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, PayToAnchor, WitnessUnknown>&) addresstype.cpp
#3 0x55a9d20a7672 in wallet::CWallet::SetSpentKeyState(wallet::WalletBatch&, transaction_identifier<false> const&, unsigned int, bool, std::set<std::variant<CNoDestination, PubKeyDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, PayToAnchor, WitnessUnknown>, std::less<std::variant<CNoDestination, PubKeyDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, PayToAnchor, WitnessUnknown>>, std::allocator<std::variant<CNoDestination, PubKeyDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, PayToAnchor, WitnessUnknown>>>&) wallet.cpp
#4 0x55a9d20a9358 in wallet::CWallet::AddToWallet(std::shared_ptr<CTransaction const>, std::variant<wallet::TxStateConfirmed, wallet::TxStateInMempool, wallet::TxStateBlockConflicted, wallet::TxStateInactive, wallet::TxStateUnrecognized> const&, std::function<bool (wallet::CWalletTx&, bool)> const&, bool) wallet.cpp
#5 0x55a9d156e376 in wallet::(anonymous namespace)::wallet_tx_can_be_bumped_fuzz_target(std::span<unsigned char const, 18446744073709551615ul>) feebumper.cpp
#6 0x55a9d15ceeb7 in LLVMFuzzerTestOneInput fuzz.cpp
#7 0x55a9d0d80b7b in fuzzer::Fuzzer::ExecuteCallback(unsigned char const*, unsigned long) /llvm-project/compiler-rt/lib/fuzzer/FuzzerLoop.cpp:619:13
#8 0x55a9d0d6a822 in fuzzer::RunOneTest(fuzzer::Fuzzer*, char const*, unsigned long) /llvm-project/compiler-rt/lib/fuzzer/FuzzerDriver.cpp:329:6
#9 0x55a9d0d706c0 in fuzzer::FuzzerDriver(int*, char***, int (*)(unsigned char const*, unsigned long)) /llvm-project/compiler-rt/lib/fuzzer/FuzzerDriver.cpp:864:9
#10 0x55a9d0d9d392 in main /llvm-project/compiler-rt/lib/fuzzer/FuzzerMain.cpp:20:10
#11 0x7f2959447ca7 (/lib/x86_64-linux-gnu/libc.so.6+0x29ca7) (BuildId: 58749c528985eab03e6700ebc1469fa50aa41219)
#12 0x7f2959447d64 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29d64) (BuildId: 58749c528985eab03e6700ebc1469fa50aa41219)
#13 0x55a9d0d63810 in _start (/workdir/out/libfuzzer_asan/fuzz+0x1390810)
0x7b695871ecbc is located 1929 bytes after 35-byte region [0x7b695871e510,0x7b695871e533)
allocated by thread T0 (b-test) here:
#0 0x55a9d0ee60bd in operator new(unsigned long) /llvm-project/compiler-rt/lib/asan/asan_new_delete.cpp:109:35
#1 0x55a9d222a415 in std::pair<std::vector<std::byte, zero_after_free_allocator<std::byte>> const, std::vector<std::byte, zero_after_free_allocator<std::byte>>>::pair<std::vector<std::byte, zero_after_free_allocator<std::byte>>&, std::vector<std::byte, zero_after_free_allocator<std::byte>>&>(std::vector<std::byte, zero_after_free_allocator<std::byte>>&, std::vector<std::byte, zero_after_free_allocator<std::byte>>&) util.cpp
#2 0x55a9d222a2af in std::_Rb_tree_node<std::pair<std::vector<std::byte, zero_after_free_allocator<std::byte>> const, std::vector<std::byte, zero_after_free_allocator<std::byte>>>>* std::_Rb_tree<std::vector<std::byte, zero_after_free_allocator<std::byte>>, std::pair<std::vector<std::byte, zero_after_free_allocator<std::byte>> const, std::vector<std::byte, zero_after_free_allocator<std::byte>>>, std::_Select1st<std::pair<std::vector<std::byte, zero_after_free_allocator<std::byte>> const, std::vector<std::byte, zero_after_free_allocator<std::byte>>>>, std::less<void>, std::allocator<std::pair<std::vector<std::byte, zero_after_free_allocator<std::byte>> const, std::vector<std::byte, zero_after_free_allocator<std::byte>>>>>::_M_create_node<std::vector<std::byte, zero_after_free_allocator<std::byte>>&, std::vector<std::byte, zero_after_free_allocator<std::byte>>&>(std::vector<std::byte, zero_after_free_allocator<std::byte>>&, std::vector<std::byte, zero_after_free_allocator<std::byte>>&) util.cpp
#3 0x55a9d2229f44 in std::_Rb_tree_iterator<std::pair<std::vector<std::byte, zero_after_free_allocator<std::byte>> const, std::vector<std::byte, zero_after_free_allocator<std::byte>>>> std::_Rb_tree<std::vector<std::byte, zero_after_free_allocator<std::byte>>, std::pair<std::vector<std::byte, zero_after_free_allocator<std::byte>> const, std::vector<std::byte, zero_after_free_allocator<std::byte>>>, std::_Select1st<std::pair<std::vector<std::byte, zero_after_free_allocator<std::byte>> const, std::vector<std::byte, zero_after_free_allocator<std::byte>>>>, std::less<void>, std::allocator<std::pair<std::vector<std::byte, zero_after_free_allocator<std::byte>> const, std::vector<std::byte, zero_after_free_allocator<std::byte>>>>>::_M_emplace_hint_unique<std::vector<std::byte, zero_after_free_allocator<std::byte>>&, std::vector<std::byte, zero_after_free_allocator<std::byte>>&>(std::_Rb_tree_const_iterator<std::pair<std::vector<std::byte, zero_after_free_allocator<std::byte>> const, std::vector<std::byte, zero_after_free_allocator<std::byte>>>>, std::vector<std::byte, zero_after_free_allocator<std::byte>>&, std::vector<std::byte, zero_after_free_allocator<std::byte>>&) util.cpp
#4 0x55a9d22220aa in std::pair<std::_Rb_tree_iterator<std::pair<std::vector<std::byte, zero_after_free_allocator<std::byte>> const, std::vector<std::byte, zero_after_free_allocator<std::byte>>>>, bool> std::map<std::vector<std::byte, zero_after_free_allocator<std::byte>>, std::vector<std::byte, zero_after_free_allocator<std::byte>>, std::less<void>, std::allocator<std::pair<std::vector<std::byte, zero_after_free_allocator<std::byte>> const, std::vector<std::byte, zero_after_free_allocator<std::byte>>>>>::emplace<std::vector<std::byte, zero_after_free_allocator<std::byte>>&, std::vector<std::byte, zero_after_free_allocator<std::byte>>&>(std::vector<std::byte, zero_after_free_allocator<std::byte>>&, std::vector<std::byte, zero_after_free_allocator<std::byte>>&) util.cpp
#5 0x55a9d222184a in wallet::MockableBatch::WriteKey(DataStream&&, DataStream&&, bool) util.cpp
#6 0x55a9d2191d3d in bool wallet::DatabaseBatch::Write<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, transaction_identifier<false>>, wallet::CWalletTx>(std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, transaction_identifier<false>> const&, wallet::CWalletTx const&, bool) walletdb.cpp
#7 0x55a9d2157224 in wallet::WalletBatch::WriteTx(wallet::CWalletTx const&) walletdb.cpp
#8 0x55a9d20aa090 in wallet::CWallet::AddToWallet(std::shared_ptr<CTransaction const>, std::variant<wallet::TxStateConfirmed, wallet::TxStateInMempool, wallet::TxStateBlockConflicted, wallet::TxStateInactive, wallet::TxStateUnrecognized> const&, std::function<bool (wallet::CWalletTx&, bool)> const&, bool) wallet.cpp
#9 0x55a9d156e376 in wallet::(anonymous namespace)::wallet_tx_can_be_bumped_fuzz_target(std::span<unsigned char const, 18446744073709551615ul>) feebumper.cpp
#10 0x55a9d15ceeb7 in LLVMFuzzerTestOneInput fuzz.cpp
#11 0x55a9d0d80b7b in fuzzer::Fuzzer::ExecuteCallback(unsigned char const*, unsigned long) /llvm-project/compiler-rt/lib/fuzzer/FuzzerLoop.cpp:619:13
#12 0x55a9d0d6a822 in fuzzer::RunOneTest(fuzzer::Fuzzer*, char const*, unsigned long) /llvm-project/compiler-rt/lib/fuzzer/FuzzerDriver.cpp:329:6
#13 0x55a9d0d706c0 in fuzzer::FuzzerDriver(int*, char***, int (*)(unsigned char const*, unsigned long)) /llvm-project/compiler-rt/lib/fuzzer/FuzzerDriver.cpp:864:9
#14 0x55a9d0d9d392 in main /llvm-project/compiler-rt/lib/fuzzer/FuzzerMain.cpp:20:10
#15 0x7f2959447ca7 (/lib/x86_64-linux-gnu/libc.so.6+0x29ca7) (BuildId: 58749c528985eab03e6700ebc1469fa50aa41219)
SUMMARY: AddressSanitizer: heap-buffer-overflow script.cpp in CScript::IsPayToScriptHash() const
Shadow bytes around the buggy address:
0x7b695871ea00: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x7b695871ea80: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x7b695871eb00: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x7b695871eb80: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x7b695871ec00: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
=>0x7b695871ec80: fa fa fa fa fa fa fa[fa]fa fa fa fa fa fa fa fa
0x7b695871ed00: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x7b695871ed80: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x7b695871ee00: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x7b695871ee80: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x7b695871ef00: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
==27852==ABORTINGLeft a comment below, I think that should fix it.
| tx.vout[0].scriptPubKey = GetScriptForDestination(fuzzed_wallet.GetDestination(fuzzed_data_provider)); | ||
| txid_to_spend = tx.GetHash(); | ||
| } | ||
| (void)fuzzed_wallet.wallet->AddToWallet(MakeTransactionRef(tx), tx_state); |
There was a problem hiding this comment.
Add a CheckTransaction before this line too?
There was a problem hiding this comment.
Yes, nice catch. Thanks.
52101d8 to
6db6f75
Compare
|
Force-pushed: Rebased, addressed #33916 (comment), and updated |
|
@janb84 can you take another look here? |
|
Pinging @janb84 and @marcofleon again here, this hasn't gotten review for a few months now and you have both reviewed this pull request before. |
FUZZ=ephemeral_package_eval ./asanfuzzbuild/bin/fuzz
INFO: Running with entropic power schedule (0xFF, 100).
INFO: Seed: 3546397870
INFO: Loaded 1 modules (613640 inline 8-bit counters): 613640 [0x5654cfd5cab0, 0x5654cfdf27b8),
INFO: Loaded 1 PC tables (613640 PCs): 613640 [0x5654cfdf27b8,0x5654d074f838),
INFO: -max_len is not provided; libFuzzer will not generate inputs larger than 4096 bytes
../../../../src/test/fuzz/package_eval.cpp:213:30: runtime error: downcast of address 0x517000045980 which does not point to an object of type 'MockedTxPool'
0x517000045980: note: object is of type 'CTxMemPool'
00 00 00 00 50 24 6c cf 54 56 00 00 00 00 00 00 be be be be 00 00 00 00 00 00 00 00 00 00 00 00
^~~~~~~~~~~~~~~~~~~~~~~
vptr for 'CTxMemPool'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ../../../../src/test/fuzz/package_eval.cpp:213:30 Same thing goes for Also, I'm not sure why CI wouldn't catch this... |
I'm not sure if this is (still) true, i'm testing locally without a mock and I do not see any speed update. Speed, mock vs non-mock; 188s vs 186s over 50000 runs and "descendants need blocks/coins" can't this be solved by two TryAddToMempool calls? |
janb84
left a comment
There was a problem hiding this comment.
I would like to suggest using this feebumper fuzzer:
https://gist.github.com/janb84/2286136b0705b7d10114e7965380da20
It does not need the other changes to mempool code. Running this fuzz target IS interesting, but nothing reachable.
50'000 runs are not enough for benchmarking. Few executions like this is probably not reaching relevant part of the tested code yet, so it's expected to not have any difference on performance. Try running for some hours. |
|
I'm going to close it since I have been completely re-writing this target and other wallet ones. Thanks, @janb84 and @marcofleon. |
This PR adds a fuzz target for the
TransactionCanBeBumpedfunction. This function checks if a transaction can be bumped based on:This target will create scenarios to exercise all these cases. For the scenario (2), it has a mocked
CTxMemPoolthat has a function to update the descendant state on mempool - this way we can speed up the target by avoiding to interacting with the mempool to really create descedants (e.g. creating blocks to trigger it).Also, the
CheckTransactioncalls are to avoid UB onSetSpentKeyState- e.g. by calling it with a transaction without any output.