<p>In Bitcoin Core, the <code>scriptWitness</code> property (for the <code>CTxIn</code> class) is serialized from a <code>CTransaction</code> as a <code>std::vector&lt;std::vector&lt;unsigned char&gt; &gt;</code>, so I would imagine the serialized version would look something like:</p>

<p>TxWitness:
</p>

<pre><code>+------------+-------------------------+------------------------+
| Field Size |        Description      |       Data Type        |
+------------+-------------------------+------------------------+
| 0+         | witness_component count | var_int                |
| ?          | witness_components      | witness_component[]    |
+------------+-------------------------+------------------------+
</code></pre>

<p>WitnessComponent:
</p>

<pre><code>+------------+------------------+-----------+
| Field Size |   Description    | Data Type |
+------------+------------------+-----------+
| 0+         | component length | var_int   |
| ?          | component        | uchar[]   |
+------------+------------------+-----------+
</code></pre>

<p>References:</p>

<ul>
<li><a href="https://github.com/bitcoin/bitcoin/blob/master/src/primitives/transaction.h#L67" rel="nofollow noreferrer">https://github.com/bitcoin/bitcoin/blob/master/src/primitives/transaction.h#L67</a></li>
<li><a href="https://github.com/bitcoin/bitcoin/blob/master/src/primitives/transaction.h#L254" rel="nofollow noreferrer">https://github.com/bitcoin/bitcoin/blob/master/src/primitives/transaction.h#L254</a></li>
<li><a href="https://github.com/bitcoin/bitcoin/blob/master/src/script/script.h#L676" rel="nofollow noreferrer">https://github.com/bitcoin/bitcoin/blob/master/src/script/script.h#L676</a></li>
</ul>

CC BY-SA 3.0
2018-01-19T01:43:12.287Z
2018-01-19T01:43:12.287Z
Tony Rizko
<p>I'm reading the <a href="https://en.bitcoin.it/wiki/Protocol_documentation#tx" rel="nofollow noreferrer">Protocol Documentation</a> page for the 'tx' data structure and cannot find a completely clear definition of the 'tx_witness' data structure.</p>

<p>After the 'tx_out' table, there is short comment stating that "The TxWitness structure consists of a var_int count of witness data components, followed by (for each witness data component) a var_int length of the component and the raw component data itself."</p>

<p>Could someone post a table, similar to others on the Protocol Documentation page, defining clearly how a 'tx_witness' data structure should be formed?</p>

<protocol><network><segregated-witness>
Complete definition of 'tx_witness' data structure used in 'tx' data structure
Matthew Stannard
# Complete definition of 'tx_witness' data structure used in 'tx' data structure

(Asked by: username_0 on 2018-01-18)

I'm reading the [Protocol Documentation](https://en.bitcoin.it/wiki/Protocol_documentation#tx) page for the 'tx' data structure and cannot find a completely clear definition of the 'tx\_witness' data structure.

After the 'tx\_out' table, there is short comment stating that "The TxWitness structure consists of a var\_int count of witness data components, followed by (for each witness data component) a var\_int length of the component and the raw component data itself."

Could someone post a table, similar to others on the Protocol Documentation page, defining clearly how a 'tx\_witness' data structure should be formed?

**Tags:** protocol, network, segregated-witness


---

## 1 answers

### Answer by username_1 on 2018-01-19. Score: 2 | Accepted answer

In Bitcoin Core, the `scriptWitness` property (for the `CTxIn` class) is serialized from a `CTransaction` as a `std::vector<std::vector<unsigned char> >`, so I would imagine the serialized version would look something like:

TxWitness:

```
+------------+-------------------------+------------------------+
| Field Size |        Description      |       Data Type        |
+------------+-------------------------+------------------------+
| 0+         | witness_component count | var_int                |
| ?          | witness_components      | witness_component[]    |
+------------+-------------------------+------------------------+

```

WitnessComponent:

```
+------------+------------------+-----------+
| Field Size |   Description    | Data Type |
+------------+------------------+-----------+
| 0+         | component length | var_int   |
| ?          | component        | uchar[]   |
+------------+------------------+-----------+

```

References:

* <https://github.com/bitcoin/bitcoin/blob/master/src/primitives/transaction.h#L67>
* <https://github.com/bitcoin/bitcoin/blob/master/src/primitives/transaction.h#L254>
* <https://github.com/bitcoin/bitcoin/blob/master/src/script/script.h#L676>


---

