Skip to content

Commit

Permalink
Merge bitcoin#30134: fuzz: add more coverage for ScriptPubKeyMan
Browse files Browse the repository at this point in the history
e3249f2 fuzz: add more coverage for `ScriptPubKeyMan` (brunoerg)

Pull request description:

  This PR adds more coverage for `ScriptPubKeyMan`:

  - Check `GetKey` and `HasPrivKey` after adding descriptor key.
  - Cover `GetEndRange` and `GetKeyPoolSize`.
  - Cover `MarkUnusedAddresses` with the scripts from ScriptPubKeys and `GetMetadata` with the destinations from them.

ACKs for top commit:
  marcofleon:
    Tested ACK e3249f2. I ran the updated harness for ~9 hours on an empty corpus, generated a coverage report, and checked that the new functions mentioned were hit. Coverage of `scriptpubkeyman.cpp` increased.
  murchandamus:
    Tested ACK e3249f2

Tree-SHA512: cfab91f6c8401174842e79209c0e9225c08f011fe9b41d0a58bcec716ae4545eaf803867f899ed7b5fbcefea45711f91894e36df082ba19732dd310cd9e61a79
  • Loading branch information
fanquake committed Jun 3, 2024
2 parents e40df54 + e3249f2 commit c065ae8
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/wallet/test/fuzz/scriptpubkeyman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,15 @@ FUZZ_TARGET(scriptpubkeyman, .init = initialize_spkm)
PKHash{ConsumeUInt160(fuzzed_data_provider)}};
std::string str_sig;
(void)spk_manager->SignMessage(msg, pk_hash, str_sig);
(void)spk_manager->GetMetadata(dest);
}
}
},
[&] {
auto spks{spk_manager->GetScriptPubKeys()};
for (const CScript& spk : spks) {
if (fuzzed_data_provider.ConsumeBool()) {
spk_manager->MarkUnusedAddresses(spk);
}
}
},
Expand All @@ -148,6 +157,10 @@ FUZZ_TARGET(scriptpubkeyman, .init = initialize_spkm)
}
spk_manager->AddDescriptorKey(key, key.GetPubKey());
spk_manager->TopUp();
LOCK(spk_manager->cs_desc_man);
auto particular_key{spk_manager->GetKey(key.GetPubKey().GetID())};
assert(*particular_key == key);
assert(spk_manager->HasPrivKey(key.GetPubKey().GetID()));
},
[&] {
std::string descriptor;
Expand Down Expand Up @@ -194,6 +207,9 @@ FUZZ_TARGET(scriptpubkeyman, .init = initialize_spkm)
}
);
}

(void)spk_manager->GetEndRange();
(void)spk_manager->GetKeyPoolSize();
}

} // namespace
Expand Down

0 comments on commit c065ae8

Please sign in to comment.