<ul>
<li>
<ol>
<li>Would it be valid; spendable by a Segwit transaction?</li>
</ol>
</li>
</ul>
<p>It is valid to create such an output, but it would not be considered a segwit output (see BIP141), and thus not spendable using a <em>segwit</em> input.</p>
<p>Instead, the script would be interpreted according to bare script rules instead, which permit spending such an output with empty <code>scriptSig</code> (and empty <code>scriptWitness</code>).</p>
<ul>
<li>
<ol start="2">
<li>Can an arbitrary bytes &quot;label&quot; be put into a Segwit P2WPKH type output by some other means?</li>
</ol>
</li>
</ul>
<p>No. A P2WPKH output contains script that is <em>exactly</em> <code>OP_0 OP_PUSHBYTES_20 &lt;20 byte pubkey hash&gt;</code>.</p>
<p>If you absolutely want to put your labelling inside the output, your only option is to grind the public key until you hit one whose hash conveys your label (which costs <em>256<sup>N</sup></em> tries for an <em>N</em>-byte label), or to appropriate some of the low-order bits of the amount sent.</p>

CC BY-SA 4.0
2024-07-03T12:52:56.857Z
2024-07-03T12:52:56.857Z
Pieter Wuille
<p>If one created a Redeem Script for a transaction output following a P2SH-P2WPKH pattern but with bytes prepended, something like:</p>
<pre><code>OP_PUSHBYTES_8 41206c6162656c2e OP_DROP OP_0 OP_PUSHBYTES_20 &lt;20 byte address&gt;
</code></pre>
<ol>
<li><p>Would it be valid; spendable by a Segwit transaction?</p>
</li>
<li><p>Can an arbitrary bytes &quot;label&quot; be put into a Segwit P2WPKH type output by some other means? One alternative approach would be to use a separate output OP_RETURN with a reference to the output number, but I'm wondering if the label bytes can be in the same output.</p>
</li>
</ol>

<script><segregated-witness><p2sh><p2wpkh><p2sh-p2wpkh>
Is it possible to "label" Segwit spendable output ScriptPubKeys with arbitrary bytes?
Lee
# Is it possible to "label" Segwit spendable output ScriptPubKeys with arbitrary bytes?

(Asked by: username_0 on 2024-07-03)

If one created a Redeem Script for a transaction output following a P2SH-P2WPKH pattern but with bytes prepended, something like:

```
OP_PUSHBYTES_8 41206c6162656c2e OP_DROP OP_0 OP_PUSHBYTES_20 <20 byte address>

```

1. Would it be valid; spendable by a Segwit transaction?
2. Can an arbitrary bytes "label" be put into a Segwit P2WPKH type output by some other means? One alternative approach would be to use a separate output OP\_RETURN with a reference to the output number, but I'm wondering if the label bytes can be in the same output.

**Tags:** script, segregated-witness, p2sh, p2wpkh, p2sh-p2wpkh


---

## 1 answers

### Answer by username_1 on 2024-07-03. Score: 4 | Accepted answer

* 1. Would it be valid; spendable by a Segwit transaction?

It is valid to create such an output, but it would not be considered a segwit output (see BIP141), and thus not spendable using a *segwit* input.

Instead, the script would be interpreted according to bare script rules instead, which permit spending such an output with empty `scriptSig` (and empty `scriptWitness`).

* 2. Can an arbitrary bytes "label" be put into a Segwit P2WPKH type output by some other means?

No. A P2WPKH output contains script that is *exactly* `OP_0 OP_PUSHBYTES_20 <20 byte pubkey hash>`.

If you absolutely want to put your labelling inside the output, your only option is to grind the public key until you hit one whose hash conveys your label (which costs *256N* tries for an *N*-byte label), or to appropriate some of the low-order bits of the amount sent.


---

