Walletwasabi: Dust limit when sending

Created on 6 Mar 2020  路  4Comments  路  Source: zkSNACKs/WalletWasabi

If you send 536 sats or less you will get: (which is expected)

dust

https://blockstream.info/testnet/tx/433594727e3ee6c95ec3364cddb08a7c3844bed2fd10946e84e55f76d4ed1ee1

In the above transaction I sent 537 sats, shouldn't this also not work?
Isn't the dust supposed to be 546 sats?

debug priority

All 4 comments

https://bitcoin.stackexchange.com/questions/10986/what-is-meant-by-bitcoin-dust

The definition of dust is client-specific and not a network rule.

P2PKH outputs of 546 satoshis or smaller are being considered dust by Bitcoin Core. For P2WPKH (native segwit) outputs, the default dust limit computes to 294 satoshis

NBitcoin allows us to build transactions in a safe way (using the TransactionBuilder) in order to be sure the built transaction will be accepted by the network. To do that it provides the boolean DustPrevention property (default: true) that when true, checks that the output value is higher than the minimum relay fee (another configurable value)

You cannot build transactions containing outputs with values under the dust threshold while the DustPrevention flag is true. This flag can be set to false however the user could create uneconomical transactions that would be rejected by the network.

As you can see below, the minimum amount that can be sent in an output depends on the size of the script. Here just 3 examples:

| script type | dust threshold |
|-------|-------------|
| p2pkh | 576 |
| p2wpkh | 537 |
| p2sh | 540 |

IMO we should translate the the exception to display the Friendly version (without the InvalidOperationException part) and that's all.


```c#
class Program
{
static void Main(string[] args)
{
// If TransactionBuilder.DustPrevention (default: true) is true then it will remove dust outputs

        var p2pkh = CreateOutput( new Key().PubKey.ScriptPubKey);
        var p2wpkh = CreateOutput( new Key().PubKey.WitHash.ScriptPubKey);
        var p2sh = CreateOutput( new Key().PubKey.ScriptPubKey.Hash.ScriptPubKey);

        var minRelayTxFee = new FeeRate(Money.Satoshis(1000), 1000);

        var dust1 = p2pkh.GetDustThreshold(minRelayTxFee);   // 576
        var dust2 = p2wpkh.GetDustThreshold(minRelayTxFee);  // 537
        var dust3 = p2sh.GetDustThreshold(minRelayTxFee);    // 540

        // You cannot send txout with amounts under the dust threshhold
    }

    private static TxOut CreateOutput(Script scriptPubKey)
    {
        return new TxOut(Money.Coins(1m), scriptPubKey);
    }
}

```

Just a question: why is the dust threshold for p2wpkh equals 537?
From the above stackexchange link in Bicoin Core it is 294.

That's because NBitcoin assumes that the input size is always at least 148 bytes and doesn't take into account that for native segwit transactions the size of the inputs is smaller.

https://github.com/MetacoSA/NBitcoin/blob/ac1d8d2ec7d8ab12131eb6ce93f77ac944bfc738/NBitcoin/Transaction.cs#L646-L652

Was this page helpful?
0 / 5 - 0 ratings