refactor: replace hardcoded dust limits with BDK's is_dust()#592
Closed
darioAnongba wants to merge 1 commit intoMetaMask:mainfrom
Closed
refactor: replace hardcoded dust limits with BDK's is_dust()#592darioAnongba wants to merge 1 commit intoMetaMask:mainfrom
darioAnongba wants to merge 1 commit intoMetaMask:mainfrom
Conversation
Remove the getDustLimitSats switch statement that hardcodes dust thresholds per address type (294 for p2wpkh, 546 for p2pkh, etc.) and replace it with BDK's Amount.is_dust(script) method. This delegates dust calculation to bitcoin-core's relay policy logic via BDK, which computes the threshold from the actual script rather than matching on address types. Benefits: - Automatically handles all current and future script types - Matches Bitcoin Core's exact dust relay policy - Removes maintenance burden of keeping hardcoded values in sync Requires @metamask/bitcoindevkit to be upgraded to a version built from bitcoindevkit/bdk-wasm v0.3.0+, which exposes Amount.is_dust() and ScriptBuf.minimal_non_dust().
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Replace the hardcoded
getDustLimitSatsswitch statement invalidation.tswith BDK'sAmount.is_dust(script)method, which computes dust thresholds from the actual script — matching Bitcoin Core's relay policy exactly.Before
After
Benefits
Dependency
This requires
@metamask/bitcoindevkitto be built frombitcoindevkit/bdk-wasmv0.3.0+ (release PR: bitcoindevkit/bdk-wasm#41), which exposes:Amount.is_dust(script)— check if amount is below dust for a scriptScriptBuf.minimal_non_dust()— get the minimum non-dust amount for a scriptScriptBuf.minimal_non_dust_custom(fee_rate)— same with custom dust relay feeThese were added in bitcoindevkit/bdk-wasm#13.
Testing
Existing dust limit tests in
RpcHandler.test.ts(lines 605-642) should continue to pass since the BDK computation produces the same thresholds (294 sats for p2wpkh) as the previously hardcoded values.Note
Medium Risk
Changes send-amount validation behavior by delegating dust checks to BDK’s
Amount.is_dust(script_pubkey), which could alter edge-case acceptance/rejection depending on the underlying BDK version and script type handling.Overview
validateDustLimitnow uses BDK’sAmount.is_dust(account.publicAddress.script_pubkey)to enforce dust limits, removing the hardcoded per-AddressTypedust threshold switch and theAddressTypeimport.This makes dust validation depend on the actual output script (matching Bitcoin Core relay policy) rather than a fixed table of constants.
Written by Cursor Bugbot for commit 8a12eed. This will update automatically on new commits. Configure here.