feat: add BitcoinJ to extkey deserialization target#396
Conversation
erickcestari
left a comment
There was a problem hiding this comment.
Thanks!
BitcoinJ will only zero the child number when it receives a root key (depth = 0). However, in those cases, we can extract the child number from the base58 string ourselves, so we can avoid the fuzzer crashing due to false positives.
|
BitcoinJ appears to have the same issue as NBitcoin: it misses test vector 5, and fails on some of them. Nice work! Do you want to open a PR/issue reporting it? |
|
I can create an Issue now, but I won't get to the PC until Wednesday. You can create the PR and link the Issue if you want. As for the comments, I will incorporate them next week. |
dc9442d to
fbc0dd8
Compare
|
@kuliq23 Let me know when this PR is ready for review. Thanks! |
Ready, thanks for all the comments. |
It's fine to apply those manually. I actually prefer this way. |
erickcestari
left a comment
There was a problem hiding this comment.
It's working, but I found one edge case in the way it sends input from C++ code to Java. It removes everything from the NUL byte onwards, resulting in BitcoinJ receiving only part of the input, which will cause the fuzzer to crash later when BitcoinJ parses it and accept as valid.
It's better to send a byte array to the JVM, which interprets the bytes as a string. This makes the decodeBase58 in BitcoinJ receive the same string/bytes as other implementations.
example of input that would make the fuzzer crash:
xxd -p crash-a4c9dea519d7fafdbcd5f6b0b067d8084c354cc4
7470756245677762737772566637677234724457396e39624e5554377544
37536f6a366a385879745a3771537742416932613934444a796868655672
425558386550325a6d644c775875517350694c41656334344b76534d7232
516f676955477a6b355772717858466a687a356f51000000000000000000
000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000
6007ae6 to
c04d373
Compare
Very good catch, thank you!! EDIT: It seems like I updated submodules by accident, will fix this... After these changes, just out of curiosity, I tried comparing only NBitcoin and BitcoinJ - BitcoinJ does NOT like when keybytes are try e.g. these keys: |
erickcestari
left a comment
There was a problem hiding this comment.
You have accidentally downgraded the eclair and 'core lightning submodules.
Interesting. They have a comment that explains the rationale. So, we should probably skip those cases. |
868ac40 to
10fe52b
Compare
bitcoinj skip when privkeybytes == (0 || 1)
10fe52b to
6ce3b41
Compare
Fixed the submodules and added a skip for those cases. I suppose checks fail due to previously discussed issue with not-defined CXX in the CI runner. |
Yep, I will hardcode the CXX flags to prevent this error from happening again. |
erickcestari
left a comment
There was a problem hiding this comment.
Thanks! Nice work!
ACK 6ce3b41
Due to how deserialization works in BitcoinJ, (parent key is needed to get a valid childnumber)
child=00000000;is always present in the final output. This makes fuzzing fail.see the "zeroed" child e.g. here:
or here
Due to the nature of fuzzing itself, it is impossible to provide a valid parent key for every generated extkey.
I see 3 options we could go about this:
Leave out BitcoinJ from this target all together
Make an exception in output comparison when BitcoinJ is used
Theoretically, a parent child duo could be generated using deriveChildKey but I find it out of the scope of this target, or?
Let me know your thoughts.