Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Omit previous transaction for taproot inputs #18

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions 02-peer-protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,23 @@ This message contains a transaction input.
* [`u32`:`prevtx_vout`]
* [`u32`:`sequence`]

1. `tlv_stream`: `tx_add_input_tlvs`
2. types:
1. type: 0 (`prevtxout`)
Copy link
Author

@t-bast t-bast Jan 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When setting this, we will set prevtx_len to 0 since it is part of the main fields of the message, which feels a bit hackish. An alternative design would be to remove prevtx from the main message fields and make it a TLV, which would make it more similar to prevtxout. I find this cleaner and more future-proof since other types of inputs won't include the whole prevtx (e.g. the previous funding output when using splicing), but it's more backwards-incompatible. But hey, it's now or never that we have the opportunity to make this cleaner, so it's worth studying that option!

2. data:
* [`sha256`:`txid`]
* [`u64`:`amount_satoshis`]
* [`...*byte`:`scriptpubkey`]

#### Requirements

The sending node:
- MUST add all sent inputs to the transaction
- MUST use a unique `serial_id` for each input currently added to the
transaction
- MUST set `sequence` to be less than or equal to 4294967293 (`0xFFFFFFFD`)
- If the input is using segwit version 1 or greater:
- MAY omit `prevtx` and send `prevtxout` instead
- MUST NOT re-transmit inputs it has received from the peer
- if is the *initiator*:
- MUST send even `serial_id`s
Expand All @@ -216,11 +226,12 @@ The receiving node:
- MUST add all received inputs to the transaction
- MUST fail the negotiation if:
- `sequence` is set to `0xFFFFFFFE` or `0xFFFFFFFF`
- the `prevtx` and `prevtx_vout` are identical to a previously added
(and not removed) input's
- `prevtx` is not a valid transaction
- `prevtx` and `prevtxout` are both missing
- `prevtx` is provided and is not a valid transaction
- `prevtx_vout` is greater or equal to the number of outputs on `prevtx`
- the `scriptPubKey` of the `prevtx_vout` output of `prevtx` is not exactly a 1-byte push opcode (for the numeric values `0` to `16`) followed by a data push between 2 and 40 bytes
- the spent outpoint is identical to a previously added (and not removed) input's
- the `scriptpubkey` of the `prevtx_vout` output of `prevtx` is not exactly a 1-byte push opcode (for the numeric values `0` to `16`) followed by a data push between 2 and 40 bytes
- the `scriptpubkey` of `prevtxout` is not exactly a 1-byte push opcode (for the numeric values `1` to `16`) followed by a data push between 2 and 40 bytes
- the `serial_id` is already included in the transaction
- the `serial_id` has the wrong parity
- if has received 4096 `tx_add_input` messages during this negotiation
Expand All @@ -235,6 +246,9 @@ Inputs in the constructed transaction MUST be sorted by `serial_id`.

`prevtx` is the serialized transaction that contains the output
this input spends. Used to verify that the input is non-malleable.
When using segwit version 1 or higher, we only need to provide the
`prevtxout` instead: this is particularly useful when the previous
transaction is too large to be included in a lightning message.

`prevtx_vout` is the index of the output being spent.

Expand Down