Skip to content

Commit fc83fef

Browse files
committed
Fix millisatoshi truncation
As highlighted by @tankyleo, the rules for setting the anchor amount were incorrect, and wouldn't result in a 0-fee transaction if there was millisatoshi rounding. We fix the spec, fix the existing test vectors, and add a new related test vector.
1 parent a786293 commit fc83fef

File tree

2 files changed

+54
-19
lines changed

2 files changed

+54
-19
lines changed

03-transactions.md

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -180,17 +180,18 @@ After 16 blocks, anyone can sweep the anchor with witness:
180180

181181
This output can be spent by anyone to provide incentive to mine the transaction, using child-pays-for-parent.
182182
This output is only added when the commitment transaction is using version 3 (`zero_fee_commitments`) and prevents pinning attacks on the commitment transaction.
183+
183184
It is using the following standard P2A (pay-to-anchor) script:
184185

185186
OP_1 <0x4e73>
186187

187188
The standard dust limit for this type of script is `240 sat`.
188189
However, if the parent transaction doesn't pay any on-chain fees, using values below this dust limit is allowed under the "ephemeral dust" rule.
189190

190-
We set the amount of this `shared_anchor` based on the [trimmed outputs](#trimmed-outputs) of the commitment transaction.
191-
When there are no trimmed outputs, it is set to `0 sat`.
192-
When there are trimmed outputs, their amount is added to this `shared_anchor` until it reaches `240 sats`: the remaining amount (if any) is not added
193-
to any output and thus directly contributes to the transaction's mining fees (which is standard since the `shared_anchor` has reached its dust limit).
191+
If the difference between the commitment transaction input and the sum of all other commitment transaction outputs is smaller than `240 sat`, we set the anchor amount to this value.
192+
This ensures that the commitment transaction doesn't pay any on-chain fees whenever the anchor amount is smaller than `240 sat`.
193+
194+
Otherwise, we set the anchor amount to `240 sat`, and the remaining difference between the commitment transaction input and its outputs directly contributes to the transaction's mining fees (which is standard since the `shared_anchor` has reached its dust limit).
194195

195196
Spending of the output requires the following (empty) witness:
196197

@@ -329,37 +330,28 @@ The commitment transaction:
329330
- if the amount of the commitment transaction `to_local` output would be
330331
less than `dust_limit_satoshis` set by the transaction owner:
331332
- MUST NOT contain that output.
332-
- if `zero_fee_commitments` applies:
333-
- MUST add this amount to the `shared_anchor` output as detailed in
334-
[the `shared_anchor` section](#shared_anchor-output-zero_fee_commitments).
335333
- otherwise:
336334
- MUST be generated as specified in [`to_local` Output](#to_local-output).
337335
- if the amount of the commitment transaction `to_remote` output would be
338336
less than `dust_limit_satoshis` set by the transaction owner:
339337
- MUST NOT contain that output.
340-
- if `zero_fee_commitments` applies:
341-
- MUST add this amount to the `shared_anchor` output as detailed in
342-
[the `shared_anchor` section](#shared_anchor-output-zero_fee_commitments).
343338
- otherwise:
344339
- MUST be generated as specified in [`to_remote` Output](#to_remote-output).
345340
- for every offered HTLC:
346341
- if the HTLC amount minus the HTLC-timeout fee would be less than
347342
`dust_limit_satoshis` set by the transaction owner:
348343
- MUST NOT contain that output.
349-
- if `zero_fee_commitments` applies:
350-
- MUST add this amount to the `shared_anchor` output as detailed in
351-
[the `shared_anchor` section](#shared_anchor-output-zero_fee_commitments).
352344
- otherwise:
353345
- MUST be generated as specified in [Offered HTLC Outputs](#offered-htlc-outputs).
354346
- for every received HTLC:
355347
- if the HTLC amount minus the HTLC-success fee would be less than
356348
`dust_limit_satoshis` set by the transaction owner:
357349
- MUST NOT contain that output.
358-
- if `zero_fee_commitments` applies:
359-
- MUST add this amount to the `shared_anchor` output as detailed in
360-
[the `shared_anchor` section](#shared_anchor-output-zero_fee_commitments).
361350
- otherwise:
362351
- MUST be generated as specified in [Received HTLC Outputs](#received-htlc-outputs).
352+
- if `zero_fee_commitments` applies:
353+
- MUST add a `shared_anchor` output with an amount computed as detailed in
354+
[the `shared_anchor` section](#shared_anchor-output-zero_fee_commitments).
363355

364356
## HTLC-Timeout and HTLC-Success Transactions
365357

bolt03/zero-fee-commitments-test.json

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,49 @@
100100
"03000000000101c3b4fad51418c874498af12060d49477c154845040e3584104ae641c542c013506000000000000000001a861000000000000220020f2d298ffcfd6d899a3abada37bfc6f42ce0b7b66f3e39e903e8419ac97dca75a0500473044022061b73271a1b6b5a1bd8e15c58b08320c72da0a1db19493abbfc6f74b5fa80c2c022030ff309d3413b9661fc8f8f2b5fd14bc733c239cc7ba8b971fd562263e62bf3b8347304402207559852cd036af82658949c28e4922f7351756616f8d04703e8060889b4b484e022050d997e1684826dc61bf0d88d9d08c01b8fcf67958ac7a177c320a1a70305fb001008576a914ef8968bbfe34ad740642784d7b1efaebfd5b23ec8763ac672103d8507a026fb30bcd48ee9c765c7346470d0d397661d43dd2eb601f661ab92a0b7c820120876475527c2103c26117339025855b87deda5e138d438b2098881a5e6f81f72a60310faef473c652ae67a914488ed834d26f1a1dc5e3428e1e1a214f743e6a2488ac68684d0a0e00"
101101
]
102102
},
103+
{
104+
"name": "Commitment transaction with all HTLCs above dust limit and millisatoshi truncation",
105+
"dust_limit_satoshis": 5000,
106+
"to_local_msat": 7949998969,
107+
"to_remote_msat": 1983999030,
108+
"incoming_htlcs": [
109+
{
110+
"id": 7,
111+
"amount_msat": 10000650,
112+
"payment_hash": "23877c9093799487a8d49c7d6aaff7e06b9831c547400605252e7b07f7ae638a",
113+
"cltv_expiry": 920150
114+
},
115+
{
116+
"id": 9,
117+
"amount_msat": 6000320,
118+
"payment_hash": "23877c9093799487a8d49c7d6aaff7e06b9831c547400605252e7b07f7ae638a",
119+
"cltv_expiry": 920150
120+
}
121+
],
122+
"outgoing_htlcs": [
123+
{
124+
"id": 5,
125+
"amount_msat": 25000821,
126+
"payment_hash": "72c9386ba5a9d97b821d855930236d39c48dab5b1c2efe9ada44e2fbadcff983",
127+
"cltv_expiry": 920141
128+
},
129+
{
130+
"id": 8,
131+
"amount_msat": 25000210,
132+
"payment_hash": "10b879729e8ddd44f2cfcf3cad6d62be535ca74e293c5ed4a59bd0dcbdad7ca1",
133+
"cltv_expiry": 920141
134+
}
135+
],
136+
"signed_commit_tx": "03000000000101ae1e3c841378cf9e4c383bfdd033d4b3c6945e0587ff16635a00b347eea2704b0100000000340fef800703000000000000000451024e73701700000000000022002075254560bb02c207015847abfda36d3a1b882e78c3f04b08325aac21c53989dc102700000000000022002075254560bb02c207015847abfda36d3a1b882e78c3f04b08325aac21c53989dca8610000000000002200200963a1f3e47b8d2a35664f70de49d3331b4499da201004868a9104271f0cd93ba8610000000000002200205b138be4da633f087be191275d3ce30828ae32d1630853fcbf66d22ca6fe2636ff451e0000000000160014f2123f1a4b67887f2e5f02eda73e6327010152eaae4e790000000000220020f2d298ffcfd6d899a3abada37bfc6f42ce0b7b66f3e39e903e8419ac97dca75a040047304402207077d60a004f42171b99c66b1b6b1799910d8f2cb72b0ef6d6500cd2f937c28a022016464954f0c05ae083bf559bc603c89f014006c44258d054a06ded667166a1f701483045022100cb78620afa0efd40d480286b59545e2e00379e78f6fb8c31d0d3659880176ed102201218323fbc8e0cd1184c7a164fad4cecb841f3eb75a3fc7d11208acbcb66386501475221027eb9596a68740445fb151ff37d5422e7f65f2c497c90fda63e738eb606c15bd62103bbc16dc8851bece603322f06b3c8da329401b7be7e9fdd3f3090ad19aed0807052aec50fbb20",
137+
"signed_htlc_success_txs": [
138+
"0300000000010122daaec93bca3ee6bee9c78cf7885e538a56d0cbd63e3df086bbac22b4f5455d010000000000000000017017000000000000220020f2d298ffcfd6d899a3abada37bfc6f42ce0b7b66f3e39e903e8419ac97dca75a0500483045022100d53dbf9e7479d48322eda78cd96c0d3d6a53c55c7c0d629a2b11e1b1a02d6b95022031a06dda013ee5a26db181552499816de0a9786c71cbefd1614f8b2e6bcb91318347304402204e4fd2e36058ed515f36cc609e636989fa89bf0b1d0e968fe642fcca7e2ceb1e022055a69e1e9be2799ae57ebae59792c9f50ca3943e6c154b4b3aabce6b080009300120108cd7067c8ed6f3734b7b67ec153cfa83c40755b75c65e414e934099e6993aa8b76a914ef8968bbfe34ad740642784d7b1efaebfd5b23ec8763ac672103d8507a026fb30bcd48ee9c765c7346470d0d397661d43dd2eb601f661ab92a0b7c8201208763a914f4c8e88504a23ed3e390ea80300c834f0eb79a6c88527c2103c26117339025855b87deda5e138d438b2098881a5e6f81f72a60310faef473c652ae677503560a0eb175ac686800000000",
139+
"0300000000010122daaec93bca3ee6bee9c78cf7885e538a56d0cbd63e3df086bbac22b4f5455d020000000000000000011027000000000000220020f2d298ffcfd6d899a3abada37bfc6f42ce0b7b66f3e39e903e8419ac97dca75a050047304402206556f3ae8fb62fd764f1a65fcc238bfc7cd629872c52ba7ee7b91e34aed4f9de022008545d9f5477371f940d8719270cc1b22d04497f53a97bf75dfb6a9ec5e5b49e8347304402205aa6b8143ef46e644157c4f4ad2ff439ae3c2e0cd76c2d3050aa6a1f5a31d33d022072f430949c2996233c5e832c3957f4f9bbf5586af3d62ebf3c0621cf92511b1a0120108cd7067c8ed6f3734b7b67ec153cfa83c40755b75c65e414e934099e6993aa8b76a914ef8968bbfe34ad740642784d7b1efaebfd5b23ec8763ac672103d8507a026fb30bcd48ee9c765c7346470d0d397661d43dd2eb601f661ab92a0b7c8201208763a914f4c8e88504a23ed3e390ea80300c834f0eb79a6c88527c2103c26117339025855b87deda5e138d438b2098881a5e6f81f72a60310faef473c652ae677503560a0eb175ac686800000000"
140+
],
141+
"signed_htlc_timeout_txs": [
142+
"0300000000010122daaec93bca3ee6bee9c78cf7885e538a56d0cbd63e3df086bbac22b4f5455d03000000000000000001a861000000000000220020f2d298ffcfd6d899a3abada37bfc6f42ce0b7b66f3e39e903e8419ac97dca75a05004830450221009d775b6e196693171a41c69337de17bd6c7846dd677d0f9db8595faedb3f621f022060eb980ee28effaa38515b31691ec522fef90db0f6b83c07cf3cf3aebc1302c083483045022100e93e04871634a1eded25a6721bb6005787e92cfea09831f7af99433891d5373202204ec63ff8fd536518eca98e068d05d562d7be9465cb4d72a52a35308a4b3d843001008576a914ef8968bbfe34ad740642784d7b1efaebfd5b23ec8763ac672103d8507a026fb30bcd48ee9c765c7346470d0d397661d43dd2eb601f661ab92a0b7c820120876475527c2103c26117339025855b87deda5e138d438b2098881a5e6f81f72a60310faef473c652ae67a914504170790db95d43716b136806e6a0fdf06e39e488ac68684d0a0e00",
143+
"0300000000010122daaec93bca3ee6bee9c78cf7885e538a56d0cbd63e3df086bbac22b4f5455d04000000000000000001a861000000000000220020f2d298ffcfd6d899a3abada37bfc6f42ce0b7b66f3e39e903e8419ac97dca75a0500483045022100c86ebf7f229be7b621a34a3fac39cfe20ea6b26e078eca782c136e635077b47a02205866ca91ef3eb8bc8dd8190c25d8a70dd101b067cc038d367ef2ee5a67c1beea8347304402203f81e6064b5a57bdc9a8759a0906dd8ee767063878f10133c435198c89c575a2022045d4e28f14aad0be1f03e43b3c6bd994d95b18b7ee979b4166c50659d4c02fa601008576a914ef8968bbfe34ad740642784d7b1efaebfd5b23ec8763ac672103d8507a026fb30bcd48ee9c765c7346470d0d397661d43dd2eb601f661ab92a0b7c820120876475527c2103c26117339025855b87deda5e138d438b2098881a5e6f81f72a60310faef473c652ae67a914488ed834d26f1a1dc5e3428e1e1a214f743e6a2488ac68684d0a0e00"
144+
]
145+
},
103146
{
104147
"name": "Commitment transaction with dust HTLCs below maximum anchor amount",
105148
"dust_limit_satoshis": 1000,
@@ -218,7 +261,7 @@
218261
"cltv_expiry": 920125
219262
}
220263
],
221-
"signed_commit_tx": "03000000000101ae1e3c841378cf9e4c383bfdd033d4b3c6945e0587ff16635a00b347eea2704b0100000000340fef800332000000000000000451024e7362841e0000000000160014f2123f1a4b67887f2e5f02eda73e6327010152eaea117a0000000000220020f2d298ffcfd6d899a3abada37bfc6f42ce0b7b66f3e39e903e8419ac97dca75a04004830450221008bc280fdd03504d216662ed63e3c9e48fbe1d9e7be293ec01822f721646d6c4e022004ea9032d5f13113ad46502d12b9dc64a18d51ee6c8152bee61b73ed51f06ad10147304402203ecdb06caa332381e7a07f0254b4242f4e8d2379a0e873f214782147d7a9cd71022058c2a0e82ceef47a682bd823af2fe110a82c62693b92084d6b194d8e27f7357801475221027eb9596a68740445fb151ff37d5422e7f65f2c497c90fda63e738eb606c15bd62103bbc16dc8851bece603322f06b3c8da329401b7be7e9fdd3f3090ad19aed0807052aec50fbb20",
264+
"signed_commit_tx": "03000000000101ae1e3c841378cf9e4c383bfdd033d4b3c6945e0587ff16635a00b347eea2704b0100000000340fef800334000000000000000451024e7362841e0000000000160014f2123f1a4b67887f2e5f02eda73e6327010152eaea117a0000000000220020f2d298ffcfd6d899a3abada37bfc6f42ce0b7b66f3e39e903e8419ac97dca75a040047304402201368dc415e11647edbfc1faaaccbe4717e5fdb88c4220a0bb19969781c9f757f02203fad3a7578fcfdc428b527b97f918b639ff07941b3b42c44f58b1364fdc57177014730440220338a338e0d477b63d2a7a00baca06c45b74bdd63d02e7d198cd8435180e9317e022014d0b95c9fde3409678417ee1a71d1d4d755f28db66a83eb10bea56de83d628d01475221027eb9596a68740445fb151ff37d5422e7f65f2c497c90fda63e738eb606c15bd62103bbc16dc8851bece603322f06b3c8da329401b7be7e9fdd3f3090ad19aed0807052aec50fbb20",
222265
"signed_htlc_success_txs": [],
223266
"signed_htlc_timeout_txs": []
224267
},
@@ -243,7 +286,7 @@
243286
"cltv_expiry": 920125
244287
}
245288
],
246-
"signed_commit_tx": "03000000000101ae1e3c841378cf9e4c383bfdd033d4b3c6945e0587ff16635a00b347eea2704b0100000000340fef800333000000000000000451024e7362841e0000000000160014f2123f1a4b67887f2e5f02eda73e6327010152eaea117a0000000000220020f2d298ffcfd6d899a3abada37bfc6f42ce0b7b66f3e39e903e8419ac97dca75a0400473044022033e3e272f752dd0f8eeb526f40b5c18dc44a528ba4a1257758baadee2a5e824b02207eeda638931de228f36fa4d07d97441d72f98afc1d0b27c9d22242f7d22e8c92014830450221008c50a570216ef1cc4f9c59a65ce06d4b0b6d2bfa72243116259c1c87a453913c02202808c8add90f5c2a0d3f7ca5c6a00ed6ec40557ea55edf14fafc138a8d05897801475221027eb9596a68740445fb151ff37d5422e7f65f2c497c90fda63e738eb606c15bd62103bbc16dc8851bece603322f06b3c8da329401b7be7e9fdd3f3090ad19aed0807052aec50fbb20",
289+
"signed_commit_tx": "03000000000101ae1e3c841378cf9e4c383bfdd033d4b3c6945e0587ff16635a00b347eea2704b0100000000340fef800334000000000000000451024e7362841e0000000000160014f2123f1a4b67887f2e5f02eda73e6327010152eaea117a0000000000220020f2d298ffcfd6d899a3abada37bfc6f42ce0b7b66f3e39e903e8419ac97dca75a040047304402201368dc415e11647edbfc1faaaccbe4717e5fdb88c4220a0bb19969781c9f757f02203fad3a7578fcfdc428b527b97f918b639ff07941b3b42c44f58b1364fdc57177014730440220338a338e0d477b63d2a7a00baca06c45b74bdd63d02e7d198cd8435180e9317e022014d0b95c9fde3409678417ee1a71d1d4d755f28db66a83eb10bea56de83d628d01475221027eb9596a68740445fb151ff37d5422e7f65f2c497c90fda63e738eb606c15bd62103bbc16dc8851bece603322f06b3c8da329401b7be7e9fdd3f3090ad19aed0807052aec50fbb20",
247290
"signed_htlc_success_txs": [],
248291
"signed_htlc_timeout_txs": []
249292
},
@@ -268,7 +311,7 @@
268311
"cltv_expiry": 920125
269312
}
270313
],
271-
"signed_commit_tx": "03000000000101ae1e3c841378cf9e4c383bfdd033d4b3c6945e0587ff16635a00b347eea2704b0100000000340fef800333000000000000000451024e7362841e0000000000160014f2123f1a4b67887f2e5f02eda73e6327010152eaea117a0000000000220020f2d298ffcfd6d899a3abada37bfc6f42ce0b7b66f3e39e903e8419ac97dca75a0400473044022033e3e272f752dd0f8eeb526f40b5c18dc44a528ba4a1257758baadee2a5e824b02207eeda638931de228f36fa4d07d97441d72f98afc1d0b27c9d22242f7d22e8c92014830450221008c50a570216ef1cc4f9c59a65ce06d4b0b6d2bfa72243116259c1c87a453913c02202808c8add90f5c2a0d3f7ca5c6a00ed6ec40557ea55edf14fafc138a8d05897801475221027eb9596a68740445fb151ff37d5422e7f65f2c497c90fda63e738eb606c15bd62103bbc16dc8851bece603322f06b3c8da329401b7be7e9fdd3f3090ad19aed0807052aec50fbb20",
314+
"signed_commit_tx": "03000000000101ae1e3c841378cf9e4c383bfdd033d4b3c6945e0587ff16635a00b347eea2704b0100000000340fef800334000000000000000451024e7362841e0000000000160014f2123f1a4b67887f2e5f02eda73e6327010152eaea117a0000000000220020f2d298ffcfd6d899a3abada37bfc6f42ce0b7b66f3e39e903e8419ac97dca75a040047304402201368dc415e11647edbfc1faaaccbe4717e5fdb88c4220a0bb19969781c9f757f02203fad3a7578fcfdc428b527b97f918b639ff07941b3b42c44f58b1364fdc57177014730440220338a338e0d477b63d2a7a00baca06c45b74bdd63d02e7d198cd8435180e9317e022014d0b95c9fde3409678417ee1a71d1d4d755f28db66a83eb10bea56de83d628d01475221027eb9596a68740445fb151ff37d5422e7f65f2c497c90fda63e738eb606c15bd62103bbc16dc8851bece603322f06b3c8da329401b7be7e9fdd3f3090ad19aed0807052aec50fbb20",
272315
"signed_htlc_success_txs": [],
273316
"signed_htlc_timeout_txs": []
274317
},

0 commit comments

Comments
 (0)