<p><code>CTxOut</code> is a class in Bitcoin Core which represents a transaction's output. It is the output amount and the output script. The sentence in question is specifically stating that the <code>witnessScript</code> should be serialized in the same way that output scripts in <code>CTxOut</code>s are serialized.</p>

CC BY-SA 4.0
2023-10-24T00:37:14.840Z
Looks like I misinterpreted it then. Thanks Andrew!
dassd
CC BY-SA 4.0
2023-10-24T00:39:41.207Z
Just one question, does output script inside CTxOut start with the length of the script or is it just a script?
dassd
CC BY-SA 4.0
2023-10-24T00:41:24.307Z
They are length prefixed.
Ava Chow
CC BY-SA 4.0
2023-10-24T00:33:25.373Z
2023-10-24T00:33:25.373Z
Ava Chow
<p>The term <code>CTxOut</code> is mentioned several times in BIP143 and BIP341. However, I can't understand what it actually represents? I assume it's just the transaction output, but I am not sure and the confusion comes from the following. BIP143 says:</p>
<blockquote>
<ul>
<li>For P2WSH witness program,
<ul>
<li>if the <code>witnessScript</code> does not contain any <code>OP_CODESEPARATOR</code>, the <code>scriptCode</code> is the &gt; <code>witnessScript</code> serialized as scripts inside <code>CTxOut</code>.</li>
</ul>
</li>
</ul>
</blockquote>
<p>I know that the witness script in P2WSH is the same as the redeem script in P2SH. While in P2SH the redeem script is the last push inside scriptSig, the witness script in P2WSH is the last item on the witness stack, that is the last item in witness data. However, in both cases, this (redeem/witness) script in the output is serialized in the form of its hash. Since I know that the <code>scriptCode</code> in P2WSH is the witness script (with its operators and data) and not its hash, <code>CTxOut</code> looks more like the witness data section of the transaction to me than the output of the transaction.</p>
<p>What is the <code>CTxOut</code>? Am I misinterpreting what is written in BIP143?</p>

<p2tr><bip143>
What does CTxOut represent in BIP143 and BIP341?
dassd
# What does CTxOut represent in BIP143 and BIP341?

(Asked by: username_0 on 2023-10-23)

The term `CTxOut` is mentioned several times in BIP143 and BIP341. However, I can't understand what it actually represents? I assume it's just the transaction output, but I am not sure and the confusion comes from the following. BIP143 says:

> * For P2WSH witness program,
>   + if the `witnessScript` does not contain any `OP_CODESEPARATOR`, the `scriptCode` is the > `witnessScript` serialized as scripts inside `CTxOut`.

I know that the witness script in P2WSH is the same as the redeem script in P2SH. While in P2SH the redeem script is the last push inside scriptSig, the witness script in P2WSH is the last item on the witness stack, that is the last item in witness data. However, in both cases, this (redeem/witness) script in the output is serialized in the form of its hash. Since I know that the `scriptCode` in P2WSH is the witness script (with its operators and data) and not its hash, `CTxOut` looks more like the witness data section of the transaction to me than the output of the transaction.

What is the `CTxOut`? Am I misinterpreting what is written in BIP143?

**Tags:** p2tr, bip143


---

## 1 answers

### Answer by username_1 on 2023-10-24. Score: 2 | Accepted answer

`CTxOut` is a class in Bitcoin Core which represents a transaction's output. It is the output amount and the output script. The sentence in question is specifically stating that the `witnessScript` should be serialized in the same way that output scripts in `CTxOut`s are serialized.

> **Comments:**
> **username_0**: Looks like I misinterpreted it then. Thanks Andrew!  
> **username_0**: Just one question, does output script inside CTxOut start with the length of the script or is it just a script?  
> **username_1**: They are length prefixed.  

---

