Repository navigation
Conversation
erickcestari
left a comment
There was a problem hiding this comment.
Thanks for working on it! I don't think we need a custom mutator for BIP-32 paths.
BIP-32 paths are just plain text. LibFuzzer handles them well natively. However, the current approach breaks the coverage feedback loop because GeneratePathFromBytes replaces LibFuzzer's mutations entirely. This prevents LibFuzzer from learning the actual input structure.
By the way, we generally use the custom mutator for cases where we first need to make checksums that would make it almost impossible for the fuzzer to generate a valid one by itself or decode something (like base58), so that we can then mutate the raw bytes. Mutating a base58 string will not help the fuzzer understand the input structure.
Thank you so much, makes sense, ill make sure to check this out:) |
fb68711 to
96ff880
Compare
|
LibFuzzer alone explores the BIP-32 path dimension effectively according to code-coverage metrics, consistently reaching derivation depths above 255. This directly exercises the depth-byte overflow case I want to test. I will extend the same approach to other modules before finalizing the PR. |
Great to hear that. Sorry for misguiding you towards the custom mutators approach. |
|
Due to the inconsistencies in internal representations of BIP-32 paths in different modules, I plan to expand the target to "derive_from_path". This is a less granular but more practical approach, as deriving new keys from a path is the typical use case. Another obstacle is the sanitization of Path string input. Some modules expect an exact format while others accept more general forms. (e.g. "h","H"," ' ") .... Currently, I am planning a custommutator/sanitizer. That would convert the path strings to a form acceptable for most modules. Different layers of this mutator could be "turned on and off" using e.g. env vars to help fuzz different aspects of the paths. Motivation: If we want to test depth-byte overflows, failing on "H" instead of "h" would be inconvenient. (just a WIP for rust and core pushed) |
e326af3 to
e64a59b
Compare
ed2c1b1 to
8ba4ec7
Compare
|
WIP - Still draft PR - working on it |
cf438c5 to
58a2a26
Compare
|
Left only Modules deal with path strings differently, as I mentioned before:
Due to this, this target fails after a few inputs. But we can also observe some interesting results: Do you think we should add this target? |
Hmmm, interesting! Sorry for the late reply. I think an easy way to avoid the fuzzer crashing all the time is to make those more restrictive implementations skip those specific errors in I'll take a closer look later in the PR. Thanks for working on this! |
erickcestari
left a comment
There was a problem hiding this comment.
IndexOutOfRange(IndexOutOfRangeError { index: 3709551615 })
BIP32 path parse failed for 00000003709551615
Module: Rustbitcoin
Result: INVALID
Module: Bitcoin
Result: CORRECT
Bitcoin Core's ParseHDKeypath accepts unhardened path components with values ≥ 2^31 (e.g. 3709551615) without error, silently treating them as hardened keys since bit 31 is already set in the raw integer. This means m/3709551615 and m/1562068223' parse identically. The function should reject unhardened components where the parsed value exceeds 2^31 - 1, as rust-bitcoin does. Might be worth reporting upstream.
Found this by adding some skips to be able to found more meaningful discrepancies.
- skip these inputs in
driver.cppsince we know that core will not be able to parse it:
if (path.find('+') != std::string::npos) {
return;
}
if (path.find('h') != std::string::npos) {
return;
}- skip skip cases where bitcoin core accepts
33/and rust-bitcoin rejects because it expects an integer after the "/" in rustbitcoinlib.rs.
match bitcoin::bip32::DerivationPath::from_str(s) {
Ok(_) => str_to_c_string("CORRECT"),
Err(bitcoin::bip32::ParseChildNumberError::ParseInt(e)) => {
if e.kind() == &std::num::IntErrorKind::Empty {
return std::ptr::null_mut();
}
str_to_c_string("INVALID")
}
Err(_) => str_to_c_string("INVALID"),
}| return "INVALID"; | ||
| } | ||
|
|
||
| return "CORRECT"; |
There was a problem hiding this comment.
We could return a formatted string to see if the implementations produced the same uint32 numbers.
There was a problem hiding this comment.
I agree, the return value is simplified here to showcase just the constraints for accepting 'pathstrings' as valid and because again, each implementation has it's own path_to_str equivalent, if any.
Populating a formatted string from the internal path representation makes sense and I will incorporate it.
You previously suggested skipping the troublesome inputs in |
I would be interested in hearing their take on that - I've mentioned some of the discrepancies in bitcoin/bitcoin#32201 (comment) already. However, after re-reading parts of the spec (emphasis mine):
I think it's just under- or poorly specified in the spec. |
I noticed this behavior earlier and assumed it might be an intentional safeguard. While this basically introduces three ways to denote the same path ( However, this still underlines the under-specificiation of derivation paths as a whole in BIP32.
I'd be happy to to document more edgecases if you can think of any! Thank you both for exploring this! |
Where have you seen
Also, I wonder what the source of truth should be for the hardening indicators. After skimming the BIP32, I can't find it. There are mentions in BIP380. Interestingly, the situation with
From what I have seen, this is due to the index being parsed via a function for parsing (unsigned) integers, e.g., NBitcoin (see some docs). Point being whatever is parseable as an unsigned int could be potentially seen as a valid item in a path for certain languages. |
Mistake(s) fixed, thanks. (Also removed Thank you for all the comments! |
|
@erickcestari I think the approach with skipping in individual
So overall, I’d treat Does this approach make sense to you? Do you think |
Good question! I think we can keep this is as draft for now.
Indeed! It does make more sense to skip it directly in the |
DRAFT PR
This is a WIP on the custom mutator for path parsing.
I am trying to find an equilibrium between tying the path generation to the input bytes (maximalize libFuzzer coverage and utilization) and targeting edgecases (results in repeated paths).
Added the target for RUST_BITCOIN and BITCOIN_CORE so far.