Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save nymius/15a3e6e8681c0e15aee7f71445f1370e to your computer and use it in GitHub Desktop.

Select an option

Save nymius/15a3e6e8681c0e15aee7f71445f1370e to your computer and use it in GitHub Desktop.
Some question which arose while reading the sixth chapter of Mastering Bitcoin, Third Edition, with the answers I found for them.
  • Why bother to have two fields (marker and flag) to signal a segwit transaction if a single one would have been enough to allow transaction versioning (like flag field) and its solely presence will be enough to make it different from non segwit transactions (like marker field)?

    From this bitcoin stackexchange answer and this bitcoin wiki article I interpretate segwit transactions are recognized by post-segwit nodes for their pattern 0x00 0x01 in the marker and flag fields plus the witness field, rather than the marker field presence, as I originally thought. For post-segwit nodes the marker and flag would be interpretated as a zero vin count (#TxIn) and vout count of one (#TxOut) respectively, being rejected by them as Pieter Wuille answered.

  • Why bother making segwit outputs look as "anyone-can-spend" for pre-segwit nodes if the marker plus the flag fields already make them invalid from their perspective?

    I was not considering carefully the difference between inputs and outputs. The "anyone-can-spend" policy is conceptually only appliable to outputs. The marker and flag transaction fields only appear when we talk about segwit transactions.

  • So, what is a segwit transaction?

    Again, from the same bitcoin article above and asuming a broadcastable transaction in the bitcoin blockchain, a segwit transaction would be any transaction including at least one input with an outpoint referencing a segwit output. Then, a single input - single output transaction spending a non-segwit output and creating a segwit output won't be considered a segwit transaction, and shouldn't have a marker nor a flag field.

  • To finish answering Why bother making segwit outputs look as "anyone-can-spend" for pre-segwit nodes if the marker + flag fields already make them invalid from their perspective?

    Both mechanism are used for different things related to the segwit changes to the protocol. The "anyone-can-spend" policy is applicable to pre-segwit nodes parsing non-segwit transaction which create segwit outputs. A broadcastable transaction including one or more segwit outputs would be validated by a pre-segwit node, processing those outputs as "anyone-can-spend" and the remaining possible non-segwit ones normally. The marker + flag invalidation mechanism is applicable by pre-segwit nodes which receive segwit transactions (as defined above).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment