Segwit transactions can mix segwit and non-segwit inputs:

But how exactly are the non-segwit inputs accounted for, if at all, in the witness of a transaction with both P2PKH and P2WPKH inputs?

Is a new stack item created for all inputs (non segwit included)? If so, does a 0x00 have to be added to the P2PKH input's stack item size field to indicate an input with no witness data (the P2KH input), or is it ignored completely?

Is there an example transaction on the mainnet I could look at? Or, what would the segwit fields be for a transaction that spent the below (pretending they are valid UTXOs and using placeholders for the key checking etc):

Example P2PK: 6f7cf9580f1c2dfb3c4d5d043cdbb128c640e3f20161245aa7372e9666168516

Example P2WPKH dfcec48bb8491856c353306ab5febeb7e99e4d783eedf3de98f3ee0812b92bad

1 Answer 1


From the BIP141 specification:

The witness is a serialization of all witness fields of the transaction. Each txin is associated with a witness field. A witness field starts with a var_int to indicate the number of stack items for the txin. It is followed by stack items, with each item starts with a var_int to indicate the length. Witness data is NOT script.

A non-witness program (defined hereinafter) txin MUST be associated with an empty witness field, represented by a 0x00. If all txins are not witness program, a transaction's wtxid is equal to its txid.

So it seems to me that a 0x00 should be be added for a non-segwit input.

learnmeabitcoin.com has this example of a mixed transaction: 846c308dc8ba79e9fc21985b1c10563d72ddff4a0ffb0e9c01d7db51fb7829ce

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.