refactor(crypto): drop btcd/btcutil dependency, inline BIP32 derivation#723
Merged
Conversation
The only btcsuite usage was hdkeychain in ethereumKeyFromMnemonic. Replace it with a minimal in-house implementation (util/crypto/bip32.go) on top of decred/secp256k1, which was already in the dependency graph via libp2p. The reimplementation reproduces hdkeychain DeriveNonStandard bit-for-bit, including the btcsuite issue #172 quirk (unpadded short keys in hardened derivation), so existing Ethereum identities derive identically. Verified by differential fuzzing against the old library: 40k random derivations, 10k forced short-key derivations, 500 end-to-end mnemonic derivations — all byte-identical. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
requilence
approved these changes
Jul 6, 2026
Coverage provided by https://github.com/seriousben/go-patch-cover-action |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Removes
github.com/btcsuite/btcdandgithub.com/btcsuite/btcutilentirely (replaces #567).The only usage was
hdkeychaininethereumKeyFromMnemonic(Ethereum key derivation for Any Naming Service). This PR replaces it with a ~100-line implementation inutil/crypto/bip32.gobuilt on stdlib HMAC-SHA512 anddecred/dcrd/dcrec/secp256k1/v4, which was already in the dependency graph via libp2p (it just moves from indirect to direct).Compatibility — derived keys must stay bit-for-bit identical, since user Ethereum identities depend on them. The old code used
DeriveNonStandard, which carries the btcsuite issue #172 quirk (intermediate private keys shorter than 32 bytes are used unpadded in hardened derivation, affecting ~1/256 of derivation steps). The reimplementation reproduces this exactly. Verified by differential fuzzing against the old library:TestMnemonic_ethereumKeyFromMnemonic) pass unchangedWhy: the btcd module is a huge dependency that keeps triggering security/license red flags (e.g. the dependabot bump in #567 fails to even build, because
btcecmoved to a separate module in btcd ≥ 0.23).🤖 Generated with Claude Code