From 8f4e2bdc7c2aba5d5a512cc3dab77c11380ce064 Mon Sep 17 00:00:00 2001 From: t-bast Date: Fri, 11 Oct 2024 09:37:46 +0200 Subject: [PATCH] Set output amount to 0 when using `OP_RETURN` Bitcoin Core version 25+ will not broadcast transactions containing `OP_RETURN` outputs if their amount is greater than 0, because this amount would then be unspendable. We thus require that the output amount is set to 0 when using `OP_RETURN`. --- 02-peer-protocol.md | 5 ++++- 03-transactions.md | 11 +++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/02-peer-protocol.md b/02-peer-protocol.md index f3c4f76..8951c4b 100644 --- a/02-peer-protocol.md +++ b/02-peer-protocol.md @@ -1731,7 +1731,10 @@ satoshis, which is possible if `dust_limit_satoshis` is below 546 satoshis). No funds are at risk when that happens, but the channel must be force-closed as the closing transaction will likely never reach miners. -`OP_RETURN` is only standard if followed by PUSH opcodes, and the total script is 83 bytes or less. We are slightly stricter, to only allow a single PUSH, but there are two forms in script: one which pushes up to 75 bytes, and a longer one (OP_PUSHDATA1) which is needed for 76-80 bytes. +`OP_RETURN` is only standard if followed by PUSH opcodes, and the total script +is 83 bytes or less. We are slightly stricter, to only allow a single PUSH, but +there are two forms in script: one which pushes up to 75 bytes, and a longer +one (OP_PUSHDATA1) which is needed for 76-80 bytes. ### Closing Negotiation: `closing_complete` and `closing_sig` diff --git a/03-transactions.md b/03-transactions.md index 2d2802d..c4692b2 100644 --- a/03-transactions.md +++ b/03-transactions.md @@ -407,13 +407,16 @@ The side with lesser funds can opt to omit their own output. * `txin[0]` sequence: `sequence` from `closing_complete` message * `txin[0]` script bytes: 0 * `txin[0]` witness: `0 ` - * txout count: 1 or 2 * The closer output: - * `txout` amount: the final balance for the closer, minus `closing_complete` `fee_satoshis`, rounded down to whole satoshis. + * `txout` amount: + * 0 if the `scriptpubkey` starts with `OP_RETURN` + * otherwise the final balance for the closer, minus `closing_complete.fee_satoshis`, rounded down to whole satoshis * `txout` script: as specified in that closer's `scriptpubkey` in its `shutdown` message * The closee output: - * `txout` amount: the final balance for the closee, rounded down to whole satoshis. + * `txout` amount: + * 0 if the `scriptpubkey` starts with `OP_RETURN` + * otherwise the final balance for the closee, rounded down to whole satoshis * `txout` script: as specified in that closee's `scriptpubkey` in its `shutdown` message ### Requirements @@ -421,7 +424,7 @@ The side with lesser funds can opt to omit their own output. Each node offering a signature: - MUST round each output down to whole satoshis. - MUST subtract the fee given by `fee_satoshis` from the closer output. - + - MUST set the output amount to 0 if the `scriptpubkey` is `OP_RETURN`. ## Fees