<p>From the <a href="https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki#specification" rel="nofollow noreferrer">BIP141 specification</a>:</p>
<blockquote>
<p>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.</p>
<p>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.</p>
</blockquote>
<p>So it seems to me that a <code>0x00</code> should be be added for a non-segwit input.</p>
<hr />
<p><a href="https://learnmeabitcoin.com" rel="nofollow noreferrer">learnmeabitcoin.com</a> has this example of a mixed transaction:
<a href="https://learnmeabitcoin.com/explorer/tx/846c308dc8ba79e9fc21985b1c10563d72ddff4a0ffb0e9c01d7db51fb7829ce" rel="nofollow noreferrer"><code>846c308dc8ba79e9fc21985b1c10563d72ddff4a0ffb0e9c01d7db51fb7829ce</code></a></p>

CC BY-SA 4.0
2024-04-17T09:40:51.483Z
2024-04-20T09:30:40.820Z
2024-04-20T09:30:40.820Z
Lee
<p>Segwit transactions can mix segwit and non-segwit inputs:</p>
<ul>
<li><a href="https://bitcoin.stackexchange.com/questions/59557/segwit-transaction-from-mixed-addresses-segwit-and-non-segwit">Segwit transaction from mixed addresses (segwit and non-segwit)</a></li>
<li><a href="https://bitcoin.stackexchange.com/questions/93899/can-i-build-a-raw-segwit-transaction-with-no-segwit-inputs">Can I build a raw segwit transaction with no segwit inputs?</a></li>
</ul>
<p>But <strong>how exactly are the non-segwit inputs accounted for, if at all, in the <a href="https://learnmeabitcoin.com/technical/transaction/#structure-witness" rel="nofollow noreferrer">witness</a> of a transaction with both P2PKH and P2WPKH inputs?</strong></p>
<p>Is a new stack item created for all inputs (non segwit included)? If so, does a <code>0x00</code> 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?</p>
<p>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):</p>
<p>Example P2PK:  <a href="https://learnmeabitcoin.com/explorer/tx/6f7cf9580f1c2dfb3c4d5d043cdbb128c640e3f20161245aa7372e9666168516" rel="nofollow noreferrer"><code>6f7cf9580f1c2dfb3c4d5d043cdbb128c640e3f20161245aa7372e9666168516</code></a></p>
<p>Example P2WPKH <a href="https://dfcec48bb8491856c353306ab5febeb7e99e4d783eedf3de98f3ee0812b92bad" rel="nofollow noreferrer"><code>dfcec48bb8491856c353306ab5febeb7e99e4d783eedf3de98f3ee0812b92bad</code></a></p>

<transactions><segregated-witness><p2pkh><p2wpkh><witness-data>
Exact witness requirements for a segwit transaction with P2PKH and P2WPKH inputs
Lee
# Exact witness requirements for a segwit transaction with P2PKH and P2WPKH inputs

(Asked by: username_0 on 2024-04-17)

Segwit transactions can mix segwit and non-segwit inputs:

* [Segwit transaction from mixed addresses (segwit and non-segwit)](https://bitcoin.stackexchange.com/questions/59557/segwit-transaction-from-mixed-addresses-segwit-and-non-segwit)
* [Can I build a raw segwit transaction with no segwit inputs?](https://bitcoin.stackexchange.com/questions/93899/can-i-build-a-raw-segwit-transaction-with-no-segwit-inputs)

But **how exactly are the non-segwit inputs accounted for, if at all, in the [witness](https://learnmeabitcoin.com/technical/transaction/#structure-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`](https://learnmeabitcoin.com/explorer/tx/6f7cf9580f1c2dfb3c4d5d043cdbb128c640e3f20161245aa7372e9666168516)

Example P2WPKH [`dfcec48bb8491856c353306ab5febeb7e99e4d783eedf3de98f3ee0812b92bad`](https://dfcec48bb8491856c353306ab5febeb7e99e4d783eedf3de98f3ee0812b92bad)

**Tags:** transactions, segregated-witness, p2pkh, p2wpkh, witness-data


---

## 1 answers

### Answer by username_0 on 2024-04-17. Score: 2 | Accepted answer

From the [BIP141 specification](https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki#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](https://learnmeabitcoin.com) has this example of a mixed transaction:
[`846c308dc8ba79e9fc21985b1c10563d72ddff4a0ffb0e9c01d7db51fb7829ce`](https://learnmeabitcoin.com/explorer/tx/846c308dc8ba79e9fc21985b1c10563d72ddff4a0ffb0e9c01d7db51fb7829ce)


---

