btcsuite / btcutil

Provides bitcoin-specific convenience functions and types
477 stars 410 forks source link

hdkeychain: BIP32 maximum depth is 255 #95

Closed afk11 closed 7 years ago

afk11 commented 7 years ago

BIP32 keys serialize the depth as a uint8 over the wire. I noticed uint16 was being used and that the depth was being taken modulo 256 during serialization.

This seems like a bug, as the behaviour is not described in the BIP, and also introduces incompatibilities which can be hard to make sense of. For example, the parent fingerprint should be 0x00000000 for a key of depth zero, whereas with the existing code if depth=256, then the serialization will specify 0 depth but still set a parent fingerprint.

afk11 commented 7 years ago

Apparently coverage went down.. Unsure precisely why, but let me know if it's an issue.

afk11 commented 7 years ago

Hey all, thanks for the feedback, pushed some commits now to address these, will squash once tests pass.