Remove m prefix requirement#2451
Conversation
Pull Request Test Coverage Report for Build 7813971326
💛 - Coveralls |
671d98c to
8a79457
Compare
bitcoin/src/bip32.rs
Outdated
There was a problem hiding this comment.
Could you please use write! instead? I know it's less performant but this will mess up formatting so I'd rather not support formatting at all. (I'm not against adding formatting support later but I think it's out of scope of this PR)/
There was a problem hiding this comment.
Still getting used to rust so pardon my ignorance, but this shouldn't be changing anything. Previously, the code was writing m directly to the formatter and then calling fmt::Display::fmt(cn, f)? in a loop. My understanding is fmt::Display::fmt(cn, f) is being called so that the ChildNumber types get printed with the hardened notation.
Since we no longer start the strings with m my change is consuming the first element from the iterator (which is a ChildNumber) and calling fmt::Display::fmt so that the first element is properly displayed with the hardened notation before proceeding with the rest of the elements.
I'm probably misunderstanding your point, but AFAICT this is keeping the behavior for displaying derivation paths the same as before.
There was a problem hiding this comment.
Formatter can have options that are passed from the format string (e.g. {:42} pads the content to 42 chars). By passing formatter directly you keep the format options so if the user writes {:5} Instead of 1/2 your code will output 1/ 2.
My suggestion removes formatting options so they won't work at all which I think is better than having it broken. We can improve it later.
There was a problem hiding this comment.
The old code was also wrong :).
The issue is that if you try to format!("{:20}", path) say, the existing code (and your modification) will apply the :20 to each of the child numbers, instead of applying it to the whole path.
There was a problem hiding this comment.
Gotcha! Thanks for the explanation @Kixunil @apoelstra , will update to use @Kixunil 's suggestion.
|
Any reason not to make the "m/" optional, would save changing all the unit tests and "m/0/1" reads pretty clearly? |
|
@tcharding it was just wrong originally. |
|
Regarding the CI failures, it looks like all of them are due to running an old version of the |
FWIW I think the BIP is pretty confusingly written; you need to find the words "To shorten notation" in the middle of the body in order to realize that the unit tests shouldn't be taken literally? I guess a PR would be welcome. |
8a79457 to
3d5896e
Compare
|
Updated to use |
Kixunil
left a comment
There was a problem hiding this comment.
You need to squash the commits since we require all commits to pass CI.
|
Behold, CI failing with a shitty error that nobody knows where it comes from - this is why I'm pushing for adding information to errors. |
Its shitty yes because it can come from two code paths in the same function, but I believe our current error strategy, if applied to the
It only comes from a single function in the whole codebase, so this is probably a bit hyperbolic :) |
I just removed the "m/" from |
Actually I have no idea which input it failed on
Yes.
I couldn't find the place where |
3d5896e to
6446681
Compare
In BIP0032, m is used as a variable for the root extended key. It is not meant to be used as a constant prefix when serializing paths. Update the DerivationPath parser to no longer require the m prefix. Remove the m prefix from the unit tests and the bip32, ecdsa-psbt, and taproot-psbt examples. close rust-bitcoin#2449
6446681 to
ccbd09d
Compare
Ah, I see.
Looks like I also missed a few "m/"! I removed the remaining "m/"'s from the ecdsa-psbt example and also from the taproot-psbt example. Squashed per @Kixunil 's suggestion, removed the remaining "m/"'s per @tcharding . Thanks for the review! |
| for cn in iter { | ||
| f.write_str("/")?; | ||
| fmt::Display::fmt(cn, f)?; | ||
| write!(f, "{}", cn)?; |
There was a problem hiding this comment.
write!(f, "/{}", cn)?; would've been simpler but not a big deal.
This reverts commit ccbd09d. There were merits to the change in rust-bitcoin#2451, and the bip is somewhat unclear on the matter, however the change breaks our ability to parse output from Bitcoin Core RPC call `getaddressinfo`. For the release to progress we need to revert this change.
Recently in rust-bitcoin#2451 we disallowed bip32 derivation paths with the leading 'm' variable. There is some confusion as to what exactly the bip specifies however Bitcoin Core RPC call `getaddressinfo` returns a derivation path with a leading "m/". This means we need to be able to parse it irrespective of what the bip says. Be more liberal in what we accept as a derivation path, including both with and without the leading 'm/'. Leave the full investigation of the bip to a later date. Change back some of the test strings as makes sense and include test strings to showcase the full current behaviour.
830c1e9 Allow m prefix in derivation paths (Tobin C. Harding) Pull request description: Recently in #2451 we disallowed bip32 derivation paths with the leading 'm' variable. There is some confusion as to what exactly the bip specifies however Bitcoin Core RPC call `getaddressinfo` returns a derivation path with a leading "m/". This means we need to be able to parse it irrespective of what the bip says. Be more liberal in what we accept as a derivation path, including both with and without the leading 'm/'. Leave the full investigation of the bip to a later date. Change back some of the test strings as makes sense and include test strings to showcase the full current behaviour. This PR replaces #2674. ACKs for top commit: apoelstra: ACK 830c1e9 sanket1729: ACK 830c1e9 junderw: ACK 830c1e9 Tree-SHA512: 7a4fccd49cb8cd91a6c8db51d758ae116d9d2e98fead7b87520ca302022b37ddbcf3f85453941c5f336f8e934ad224beba99527dc29ce8368fbb1f25508c1615
Recently in rust-bitcoin#2451 we disallowed bip32 derivation paths with the leading 'm' variable. There is some confusion as to what exactly the bip specifies however Bitcoin Core RPC call `getaddressinfo` returns a derivation path with a leading "m/". This means we need to be able to parse it irrespective of what the bip says. Be more liberal in what we accept as a derivation path, including both with and without the leading 'm/'. Leave the full investigation of the bip to a later date. Change back some of the test strings as makes sense and include test strings to showcase the full current behaviour.
b7f61e2 Allow m prefix in derivation paths (Tobin C. Harding) Pull request description: This PR contains a single patch that was created using `cargo cherry-pick 830c1e9` - i.e., it is a backport of #2677. ---- Recently in #2451 we disallowed bip32 derivation paths with the leading 'm' variable. There is some confusion as to what exactly the bip specifies however Bitcoin Core RPC call `getaddressinfo` returns a derivation path with a leading "m/". This means we need to be able to parse it irrespective of what the bip says. Be more liberal in what we accept as a derivation path, including both with and without the leading 'm/'. Leave the full investigation of the bip to a later date. Change back some of the test strings as makes sense and include test strings to showcase the full current behaviour. ACKs for top commit: apoelstra: ACK b7f61e2 confirmed that diff exactly matches 2451. CI failure is unrelated. Tree-SHA512: 075e8a7d368dd216f947954459f67812b248982b5e022ac158e1022d8adcb7ce603f63951385fb88c397a66305e1cb3a25c89fdf4726bddc1fa1e2d190950f41
Recently in rust-bitcoin#2451 we disallowed bip32 derivation paths with the leading 'm' variable. There is some confusion as to what exactly the bip specifies however Bitcoin Core RPC call `getaddressinfo` returns a derivation path with a leading "m/". This means we need to be able to parse it irrespective of what the bip says. Be more liberal in what we accept as a derivation path, including both with and without the leading 'm/'. Leave the full investigation of the bip to a later date. Change back some of the test strings as makes sense and include test strings to showcase the full current behaviour.
min BIP0032 is a variable, not a constant. Requiring it as a constant here is confusing and can lead to erroneous conclusions if using this library as a means of understanding BIP0032.Fixes #2449