<p>The witness script you are using, <code>4c02efef754c14f7983a6806d128c82842594183d119d2a5178f4cac</code> is non-standard (in the sense that it does not represent a script descriptor defined by a standard, not in the sense of relay policy). Bitcoin Core won't be able to provide a satisfying witness for a non-standard Script.</p>
<p>If you want to use more advanced, but still standard, scripts with Bitcoin Core have a look at <a href="https://bitcoin.sipa.be/miniscript/" rel="nofollow noreferrer">Miniscript</a>.</p>

CC BY-SA 4.0
2023-12-03T19:06:28.847Z
I see! So can you only use standard witness unlock scripts? I thought you'd be free to choose your script in a P2WSH transaction?
BitcoinQuestioner
CC BY-SA 4.0
2023-12-06T03:20:42.810Z
@BitcoinQuestioner You can use any script, but that doesn't mean Bitcoin Core knows how satisfy your script. If you use something beyond the supported scripts, you'll need to implement the signing logic yourself. Note however that through miniscript the set of supported scripts has increased a lot (but doesn't include your specific script).
Pieter Wuille
CC BY-SA 4.0
2023-12-06T07:36:16.643Z
I clarified that non-standard in my answer isn't about relay policy.
Antoine Poinsot
CC BY-SA 4.0
2023-12-03T10:49:27.983Z
2023-12-06T07:35:53.543Z
2023-12-06T07:35:53.543Z
Antoine Poinsot
<p>I am trying to spend a P2WSH output. Here are the steps I have taken:</p>
<ol>
<li>I have created a P2WSH output via bitcoin-cli. These are the details of the P2WSH output:</li>
</ol>
<pre><code>Type
V0_P2WSH
scriptPubKey (asm)
OP_0 OP_PUSHBYTES_32 a2b95877500eb4180401640c5649c55ce578584f865e4f1609f9971ca19d6f40
scriptPubKey (hex)
0020a2b95877500eb4180401640c5649c55ce578584f865e4f1609f9971ca19d6f40
Spending tx
Unspent
</code></pre>
<p>You can also view it here: <a href="https://blockstream.info/testnet/tx/3010534df31914f938014d34d0bd402ce1a741a46624b28abcfd2462126331a5?expand" rel="nofollow noreferrer">https://blockstream.info/testnet/tx/3010534df31914f938014d34d0bd402ce1a741a46624b28abcfd2462126331a5?expand</a></p>
<ol start="2">
<li>In order to spend that output, I am first creating a transaction via bitcoin-cli as such:</li>
</ol>
<pre><code>bitcoin-cli createrawtransaction [{\&quot;txid\&quot;:\&quot;3010534df31914f938014d34d0bd402ce1a741a46624b28abcfd2462126331a5\&quot;,\&quot;vout\&quot;:0}] [{\&quot;tb1q77vr56qx6y5vs2zzt9qc85ge62j30r6vaccfxl\&quot;:0.0000007}]
</code></pre>
<p>This outputs the following serialization:</p>
<pre><code>0200000001a53163126224fdbc8ab22466a441a7e12c40bdd0344d0138f91419f34d5310300000000000fdffffff014600000000000000160014f7983a6806d128c82842594183d119d2a5178f4c00000000
</code></pre>
<ol start="3">
<li>I now try to sign the message</li>
</ol>
<pre><code>bitcoin-cli signrawtransactionwithwallet &quot;0200000001a53163126224fdbc8ab22466a441a7e12c40bdd0344d0138f91419f34d5310300000000000fdffffff014600000000000000160014f7983a6806d128c82842594183d119d2a5178f4c00000000&quot; [{\&quot;txid\&quot;:\&quot;3010534df31914f938014d34d0bd402ce1a741a46624b28abcfd2462126331a5\&quot;,\&quot;vout\&quot;:0,\&quot;scriptPubKey\&quot;:\&quot;0020a2b95877500eb4180401640c5649c55ce578584f865e4f1609f9971ca19d6f40\&quot;,\&quot;witnessScript\&quot;:\&quot;4c02efef754c14f7983a6806d128c82842594183d119d2a5178f4cac\&quot;,\&quot;amount\&quot;:0.0000007}]

</code></pre>
<p>This does not work however, as I always get the following error:</p>
<pre><code>{
  &quot;hex&quot;: &quot;0200000001a53163126224fdbc8ab22466a441a7e12c40bdd0344d0138f91419f34d5310300000000000fdffffff014600000000000000160014f7983a6806d128c82842594183d119d2a5178f4c00000000&quot;,
  &quot;complete&quot;: false,
  &quot;errors&quot;: [
    {
      &quot;txid&quot;: &quot;3010534df31914f938014d34d0bd402ce1a741a46624b28abcfd2462126331a5&quot;,
      &quot;vout&quot;: 0,
      &quot;witness&quot;: [
      ],
      &quot;scriptSig&quot;: &quot;&quot;,
      &quot;sequence&quot;: 4294967293,
      &quot;error&quot;: &quot;Witness program was passed an empty witness&quot;
    }
  ]
}
</code></pre>
<p>I do not understand why I receive a <strong>Witness program was passed an empty witness</strong> error, as I am explicitly passing a witness script in the command line. Is there a bug or what am I missing?</p>
<p>The witness script that was hashed is
<code>OP_PUSHDATA1 EFEF OP_DROP OP_PUSHDATA1 f7983a6806d128c82842594183d119d2a5178f4c OP_CHECKSIG</code>
which serializes to
<code>4c02EFEF754c14f7983a6806d128c82842594183d119d2a5178f4cac</code></p>

<bitcoin-core><bitcoind><segregated-witness><p2wsh>
P2WSH Bitcoin Core Witness Script Empty Error
BitcoinQuestioner
# P2WSH Bitcoin Core Witness Script Empty Error

(Asked by: username_0 on 2023-12-03)

I am trying to spend a P2WSH output. Here are the steps I have taken:

1. I have created a P2WSH output via bitcoin-cli. These are the details of the P2WSH output:

```
Type
V0_P2WSH
scriptPubKey (asm)
OP_0 OP_PUSHBYTES_32 a2b95877500eb4180401640c5649c55ce578584f865e4f1609f9971ca19d6f40
scriptPubKey (hex)
0020a2b95877500eb4180401640c5649c55ce578584f865e4f1609f9971ca19d6f40
Spending tx
Unspent

```

You can also view it here: <https://blockstream.info/testnet/tx/3010534df31914f938014d34d0bd402ce1a741a46624b28abcfd2462126331a5?expand>

2. In order to spend that output, I am first creating a transaction via bitcoin-cli as such:

```
bitcoin-cli createrawtransaction [{\"txid\":\"3010534df31914f938014d34d0bd402ce1a741a46624b28abcfd2462126331a5\",\"vout\":0}] [{\"tb1q77vr56qx6y5vs2zzt9qc85ge62j30r6vaccfxl\":0.0000007}]

```

This outputs the following serialization:

```
0200000001a53163126224fdbc8ab22466a441a7e12c40bdd0344d0138f91419f34d5310300000000000fdffffff014600000000000000160014f7983a6806d128c82842594183d119d2a5178f4c00000000

```

3. I now try to sign the message

```
bitcoin-cli signrawtransactionwithwallet "0200000001a53163126224fdbc8ab22466a441a7e12c40bdd0344d0138f91419f34d5310300000000000fdffffff014600000000000000160014f7983a6806d128c82842594183d119d2a5178f4c00000000" [{\"txid\":\"3010534df31914f938014d34d0bd402ce1a741a46624b28abcfd2462126331a5\",\"vout\":0,\"scriptPubKey\":\"0020a2b95877500eb4180401640c5649c55ce578584f865e4f1609f9971ca19d6f40\",\"witnessScript\":\"4c02efef754c14f7983a6806d128c82842594183d119d2a5178f4cac\",\"amount\":0.0000007}]

```

This does not work however, as I always get the following error:

```
{
  "hex": "0200000001a53163126224fdbc8ab22466a441a7e12c40bdd0344d0138f91419f34d5310300000000000fdffffff014600000000000000160014f7983a6806d128c82842594183d119d2a5178f4c00000000",
  "complete": false,
  "errors": [
    {
      "txid": "3010534df31914f938014d34d0bd402ce1a741a46624b28abcfd2462126331a5",
      "vout": 0,
      "witness": [
      ],
      "scriptSig": "",
      "sequence": 4294967293,
      "error": "Witness program was passed an empty witness"
    }
  ]
}

```

I do not understand why I receive a **Witness program was passed an empty witness** error, as I am explicitly passing a witness script in the command line. Is there a bug or what am I missing?

The witness script that was hashed is
`OP_PUSHDATA1 EFEF OP_DROP OP_PUSHDATA1 f7983a6806d128c82842594183d119d2a5178f4c OP_CHECKSIG`
which serializes to
`4c02EFEF754c14f7983a6806d128c82842594183d119d2a5178f4cac`

**Tags:** bitcoin-core, bitcoind, segregated-witness, p2wsh


---

## 1 answers

### Answer by username_1 on 2023-12-03. Score: 0

The witness script you are using, `4c02efef754c14f7983a6806d128c82842594183d119d2a5178f4cac` is non-standard (in the sense that it does not represent a script descriptor defined by a standard, not in the sense of relay policy). Bitcoin Core won't be able to provide a satisfying witness for a non-standard Script.

If you want to use more advanced, but still standard, scripts with Bitcoin Core have a look at [Miniscript](https://bitcoin.sipa.be/miniscript/).

> **Comments:**
> **username_0**: I see! So can you only use standard witness unlock scripts? I thought you'd be free to choose your script in a P2WSH transaction?  
> **username_2**: @username_0 You can use any script, but that doesn't mean Bitcoin Core knows how satisfy your script. If you use something beyond the supported scripts, you'll need to implement the signing logic yourself. Note however that through miniscript the set of supported scripts has increased a lot (but doesn't include your specific script).  
> **username_1**: I clarified that non-standard in my answer isn't about relay policy.  

---

