You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The btcsuite/btcutil version of ExtendedKeywas modified by making a new Derive method and renaming Child to DeriveNonStandard.
We have been using Decred's hdkeychain, which should be fine as long as we are consistent, but another consideration is that in some cases we are using Decred's hdkeychain internal to asset backends to derive keys for specific paths. For example, in client/asset/eth:
While in this instance we might be able to use ToECDSAUnsafe to skip this check, I think we should consider BIP-32 compliant key derivation, at least when used from inside the specific asset packages where we are trying to be compliant.
On the other hand, I would like to stick with the dcrd/hdkeychain package if possible, so another idea might be to introduce a similar DeriveBIP32Standard method that simply omits the stripping of zero padding:
Where do we use bip-32 compliant key derivation? Just where required for non-Decred packages like the eth account? Also for the app seed -> account keys and wallet seeds paths?
I was a bit confused because it wasn't clear why leading zeros should change the key derivation, but it's (arguably?) a bug outlined at btcsuite/btcutil#172. @chappjc has verified that btcutil is producing the BIP-compliant results, and his proposed changes to dcrd/hdkeychain produce identically valid results. We should use btcutil until dcrd/hdkeychain is ready.
I think using the correct implementation with leading zeros left in all over is optimal, because that was the original intention and no one has used this in dex yet.
Decred's
hdkeychain.(*ExtendedKey).Child
method is known to generate private keys with zero padding removed and thus <32 bytes in length, at a rate of 1/256 hardened key derivations.The btcsuite/btcutil version of
ExtendedKey
was modified by making a newDerive
method and renamingChild
toDeriveNonStandard
.We have been using Decred's hdkeychain, which should be fine as long as we are consistent, but another consideration is that in some cases we are using Decred's hdkeychain internal to asset backends to derive keys for specific paths. For example, in
client/asset/eth
:dcrdex/client/asset/eth/eth.go
Lines 207 to 225 in 6c947e0
And the serialized private key, which may be less than 32 bytes, is used by
go-ethereum/crypto.ToECDSA
to initialize the ETH account's keystore.dcrdex/client/asset/eth/node.go
Lines 257 to 259 in 6c947e0
Because the eth functions have a strict length requirement by default, this fails occasionally as we have seen on CI recently since this missing error check was added less than 2 weeks ago.
While in this instance we might be able to use
ToECDSAUnsafe
to skip this check, I think we should consider BIP-32 compliant key derivation, at least when used from inside the specific asset packages where we are trying to be compliant.On the other hand, I would like to stick with the dcrd/hdkeychain package if possible, so another idea might be to introduce a similar
DeriveBIP32Standard
method that simply omits the stripping of zero padding:https://github.com/decred/dcrd/blob/08528c28b7ef2d3ce59ea9a79579a01ac5d5cded/hdkeychain/extendedkey.go#L320-L327
Decisions:
The text was updated successfully, but these errors were encountered: