@@ -21,6 +21,8 @@ This details the exact format of on-chain transactions, which both sides need to
2121 * [Fees](#fees)
2222 * [Fee Calculation](#fee-calculation)
2323 * [Fee Payment](#fee-payment)
24+ * [Dust Limits](#dust-limits)
25+ * [Commitment Transaction Construction](#commitment-transaction-construction)
2426 * [ Keys] ( #keys )
2527 * [ Key Derivation] ( #key-derivation )
2628 * [ ` localpubkey ` , ` remotepubkey ` , ` local_htlcpubkey ` , ` remote_htlcpubkey ` , ` local_delayedpubkey ` , and ` remote_delayedpubkey ` Derivation] ( #localpubkey-remotepubkey-local_htlcpubkey-remote_htlcpubkey-local_delayedpubkey-and-remote_delayedpubkey-derivation )
@@ -484,6 +486,112 @@ A node:
484486 - if the resulting fee rate is too low:
485487 - MAY fail the channel.
486488
489+ ## Dust Limits
490+
491+ The ` dust_limit_satoshis ` parameter is used to configure the threshold below
492+ which nodes will not produce on-chain transaction outputs.
493+
494+ There is no consensus rule in Bitcoin that makes outputs below dust thresholds
495+ invalid or unspendable, but policy rules in popular implementations will prevent
496+ relaying transactions that contain such outputs.
497+
498+ Bitcoin Core defines the following dust thresholds:
499+
500+ - pay to pubkey hash (p2pkh): 546 satoshis
501+ - pay to script hash (p2sh): 540 satoshis
502+ - pay to witness pubkey hash (p2wpkh): 294 satoshis
503+ - pay to witness script hash (p2wsh): 330 satoshis
504+ - unknown segwit versions: 354 satoshis
505+
506+ The rationale of this calculation (implemented [ here] ( https://github.com/bitcoin/bitcoin/blob/0.21/src/policy/policy.cpp ) )
507+ is explained in the following sections.
508+
509+ In all these sections, the calculations are done with a feerate of 3000 sat/kB
510+ as per Bitcoin Core's implementation.
511+
512+ ### Pay to pubkey hash (p2pkh)
513+
514+ A p2pkh output is 34 bytes:
515+
516+ - 8 bytes for the output amount
517+ - 1 byte for the script length
518+ - 25 bytes for the script (` OP_DUP ` ` OP_HASH160 ` ` 20 ` 20-bytes ` OP_EQUALVERIFY ` ` OP_CHECKSIG ` )
519+
520+ A p2pkh input is at least 148 bytes:
521+
522+ - 36 bytes for the previous output (32 bytes hash + 4 bytes index)
523+ - 1 byte for the script sig length
524+ - 4 bytes for the sequence
525+ - 107 bytes for the script sig:
526+ - 1 byte for the items count
527+ - 1 byte for the signature length
528+ - 71 bytes for the signature
529+ - 1 byte for the public key length
530+ - 33 bytes for the public key
531+
532+ The p2pkh dust threshold is then ` (34 + 148) * 3000 / 1000 = 546 satoshis `
533+
534+ ### Pay to script hash (p2sh)
535+
536+ A p2sh output is 32 bytes:
537+
538+ - 8 bytes for the output amount
539+ - 1 byte for the script length
540+ - 23 bytes for the script (` OP_HASH160 ` ` 20 ` 20-bytes ` OP_EQUAL ` )
541+
542+ A p2sh input doesn't have a fixed size, since it depends on the underlying
543+ script, so we use 148 bytes as a lower bound.
544+
545+ The p2sh dust threshold is then ` (32 + 148) * 3000 / 1000 = 540 satoshis `
546+
547+ ### Pay to witness pubkey hash (p2wpkh)
548+
549+ A p2wpkh output is 31 bytes:
550+
551+ - 8 bytes for the output amount
552+ - 1 byte for the script length
553+ - 22 bytes for the script (` OP_0 ` ` 20 ` 20-bytes)
554+
555+ A p2wpkh input is at least 67 bytes (depending on the signature length):
556+
557+ - 36 bytes for the previous output (32 bytes hash + 4 bytes index)
558+ - 1 byte for the script sig length
559+ - 4 bytes for the sequence
560+ - 26 bytes for the witness (with the 75% segwit discount applied):
561+ - 1 byte for the items count
562+ - 1 byte for the signature length
563+ - 71 bytes for the signature
564+ - 1 byte for the public key length
565+ - 33 bytes for the public key
566+
567+ The p2wpkh dust threshold is then ` (31 + 67) * 3000 / 1000 = 294 satoshis `
568+
569+ ### Pay to witness script hash (p2wsh)
570+
571+ A p2wsh output is 43 bytes:
572+
573+ - 8 bytes for the output amount
574+ - 1 byte for the script length
575+ - 34 bytes for the script (` OP_0 ` ` 32 ` 32-bytes)
576+
577+ A p2wsh input doesn't have a fixed size, since it depends on the underlying
578+ script, so we use 67 bytes as a lower bound.
579+
580+ The p2wsh dust threshold is then ` (43 + 67) * 3000 / 1000 = 330 satoshis `
581+
582+ ### Unknown segwit versions
583+
584+ Unknown segwit outputs are at most 51 bytes:
585+
586+ - 8 bytes for the output amount
587+ - 1 byte for the script length
588+ - 42 bytes for the script (` OP_1 ` through ` OP_16 ` inclusive, followed by a single push of 2 to 40 bytes)
589+
590+ The input doesn't have a fixed size, since it depends on the underlying
591+ script, so we use 67 bytes as a lower bound.
592+
593+ The unknown segwit version dust threshold is then ` (51 + 67) * 3000 / 1000 = 354 satoshis `
594+
487595## Commitment Transaction Construction
488596
489597This section ties the previous sections together to detail the
0 commit comments