<p>I'm trying to sign a raw transaction with private key on bitcoin core on regtest.
When I'm trying to sign the transaction I'm receiving this error: Witness program hash mismatch. When I debugged my bitcoin-core transaction I noticed the stack size is zero.</p>
<p>I verified my private keys are correct.</p>
<p>My decode transaction:</p>
<pre><code>{
  &quot;txid&quot;: &quot;4454f34656a89f0ac4a2097fab289f4a8b38cb301e98b600362c135e2c18d10a&quot;,
  &quot;hash&quot;: &quot;4454f34656a89f0ac4a2097fab289f4a8b38cb301e98b600362c135e2c18d10a&quot;,
  &quot;version&quot;: 2,
  &quot;size&quot;: 157,
  &quot;vsize&quot;: 157,
  &quot;weight&quot;: 628,
  &quot;locktime&quot;: 0,
  &quot;vin&quot;: [
    {
      &quot;txid&quot;: &quot;53be831aad07b549ec91666674d28da5761f74f4a832e9fe93675c6449db7a24&quot;,
      &quot;vout&quot;: 0,
      &quot;scriptSig&quot;: {
        &quot;asm&quot;: &quot;&quot;,
        &quot;hex&quot;: &quot;&quot;
      },
      &quot;sequence&quot;: 4294967295
    }
  ],
  &quot;vout&quot;: [
    {
      &quot;value&quot;: 99.79997001,
      &quot;n&quot;: 0,
      &quot;scriptPubKey&quot;: {
        &quot;asm&quot;: &quot;0 f508fe341dfe0fbbeb7a38b41e7d2681d2376697&quot;,
        &quot;desc&quot;: &quot;addr(tpr1q75y0udqalc8mh6m68z6pulfxs8frwe5hxslc32)#xxr7capg&quot;,
        &quot;hex&quot;: &quot;0014f508fe341dfe0fbbeb7a38b41e7d2681d2376697&quot;,
        &quot;address&quot;: &quot;tpr1q75y0udqalc8mh6m68z6pulfxs8frwe5hxslc32&quot;,
        &quot;type&quot;: &quot;witness_v0_keyhash&quot;
      }
    },
    {
      &quot;value&quot;: 0.00000000,
      &quot;n&quot;: 1,
      &quot;scriptPubKey&quot;: {
        &quot;asm&quot;: &quot;OP_RETURN b48dfcd241e5894a8a5b8cef6782734481ee180ed3fd9d164e58307527e8f07082b12c5ba8baa3f05c66966334aea0eecbcb8f2bc5d14bfbddc332c1e39ca8c8&quot;,
        &quot;desc&quot;: &quot;raw(6a40b48dfcd241e5894a8a5b8cef6782734481ee180ed3fd9d164e58307527e8f07082b12c5ba8baa3f05c66966334aea0eecbcb8f2bc5d14bfbddc332c1e39ca8c8)#en45fqnk&quot;,
        &quot;hex&quot;: &quot;6a40b48dfcd241e5894a8a5b8cef6782734481ee180ed3fd9d164e58307527e8f07082b12c5ba8baa3f05c66966334aea0eecbcb8f2bc5d14bfbddc332c1e39ca8c8&quot;,
        &quot;type&quot;: &quot;nulldata&quot;
      }
    }
  ]
}
</code></pre>
<h3>EDIT</h3>
<p>The decoded input transaction is transaction relies on two different outputs</p>
<pre><code>{
  &quot;txid&quot;: &quot;53be831aad07b549ec91666674d28da5761f74f4a832e9fe93675c6449db7a24&quot;,
  &quot;hash&quot;: &quot;f50d764b8f662e7c12d794d9ac2a87775de35982544571bc6be83ed12eb818cf&quot;,
  &quot;version&quot;: 2,
  &quot;size&quot;: 370,
  &quot;vsize&quot;: 208,
  &quot;weight&quot;: 832,
  &quot;locktime&quot;: 0,
  &quot;vin&quot;: [
    {
      &quot;txid&quot;: &quot;540a6ce5413d602c8830589bcbfd70fe1f31f4229488c12f5dbd746a4b1bff07&quot;,
      &quot;vout&quot;: 0,
      &quot;scriptSig&quot;: {
        &quot;asm&quot;: &quot;&quot;,
        &quot;hex&quot;: &quot;&quot;
      },
      &quot;txinwitness&quot;: [
        &quot;304402204ee1d2b35adfe522517905f8eb3bee9cf91c15c0139673d52ba637aff7f9790d022055930d64c0a5d62f40e8d8fd200898341b7141bef708f8ae9182c1adbe489f6301&quot;,
        &quot;02e0b590ccf577215eee2aa121d573fb26b83bd2c397d0446fd27ae3436c83803c&quot;
      ],
      &quot;sequence&quot;: 4294967295
    },
    {
      &quot;txid&quot;: &quot;e615c045166fb19cf485fb34d246931d3a1acda0d7510efc7bf6d6eee05ad807&quot;,
      &quot;vout&quot;: 0,
      &quot;scriptSig&quot;: {
        &quot;asm&quot;: &quot;&quot;,
        &quot;hex&quot;: &quot;&quot;
      },
      &quot;txinwitness&quot;: [
        &quot;304402200788197af3f73245a5e783c325b5ef397a47bcf19ea2b02b48c74c066bcaab5902207199f905b20bde2b8c1b7b359a4e1bdf6ea1c6a9eed6cb8698b04b6df5bfb05f01&quot;,
        &quot;02e0b590ccf577215eee2aa121d573fb26b83bd2c397d0446fd27ae3436c83803c&quot;
      ],
      &quot;sequence&quot;: 4294967295
    }
  ],
  &quot;vout&quot;: [
    {
      &quot;value&quot;: 99.79999001,
      &quot;n&quot;: 0,
      &quot;scriptPubKey&quot;: {
        &quot;asm&quot;: &quot;0 cd658ab850ca1f743496a16d58762fe7a2c39758&quot;,
        &quot;desc&quot;: &quot;addr(tpr1qe4jc4wzseg0hgdyk59k4sa30u73v896clelyyw)#eags8sr8&quot;,
        &quot;hex&quot;: &quot;0014cd658ab850ca1f743496a16d58762fe7a2c39758&quot;,
        &quot;address&quot;: &quot;tpr1qe4jc4wzseg0hgdyk59k4sa30u73v896clelyyw&quot;,
        &quot;type&quot;: &quot;witness_v0_keyhash&quot;
      }
    },
    {
      &quot;value&quot;: 0.20000000,
      &quot;n&quot;: 1,
      &quot;scriptPubKey&quot;: {
        &quot;asm&quot;: &quot;0 5f67b467ab1e01e0c803f26b36ade593f1ae6f2f&quot;,
        &quot;desc&quot;: &quot;addr(tpr1qtanmgeatrcq7pjqr7f4ndt09j0c6ume0yph3xl)#fnunjym6&quot;,
        &quot;hex&quot;: &quot;00145f67b467ab1e01e0c803f26b36ade593f1ae6f2f&quot;,
        &quot;address&quot;: &quot;tpr1qtanmgeatrcq7pjqr7f4ndt09j0c6ume0yph3xl&quot;,
        &quot;type&quot;: &quot;witness_v0_keyhash&quot;
      }
    }
  ]
}
</code></pre>

CC BY-SA 4.0
2024-08-12T12:58:46.137Z
so first what kind of address did you use here when you built your transaction? WPKH(segwit native) or Taproot?
Jack Tsia
CC BY-SA 4.0
2024-08-12T13:06:19.050Z
Could you please also provide the transaction that created the TXO you are spending?
Murch
CC BY-SA 4.0
2024-08-12T13:11:10.797Z
The addresses are native segwit
liorko
CC BY-SA 4.0
2024-08-12T14:20:12.560Z
@Murch I edited my question
liorko
CC BY-SA 4.0
2024-08-12T14:56:19.077Z
It’s kinda hard to tell what’s going on when you remove the fields that we would be looking at to understand what’s going on. You said this is Regtest, so it’s a private testnet on your own computer, any particular reason why you are removing part of the output?
Murch
CC BY-SA 4.0
2024-08-12T15:45:26.250Z
@Murch I created a unique prefix for my addresses in order not to be confused with the mainnet bitcoin addresses. I re-edit the question.
liorko
CC BY-SA 4.0
2024-08-12T17:38:44.790Z
How did you implement the prefix? Did you change the witness version in the output script?
Murch
CC BY-SA 4.0
2024-08-13T06:12:07.647Z
@Murch I changed the `bech32_hrp` prefix and recompiled bitcoin core. When I have a transaction with one input and two outputs I managed to sign the transaction.
liorko
<bitcoin-core><signrawtransaction>
Witness program hash mismatch stack size is zero
liorko
# Witness program hash mismatch stack size is zero

(Asked by: username_0 on 2024-08-12)

I'm trying to sign a raw transaction with private key on bitcoin core on regtest.
When I'm trying to sign the transaction I'm receiving this error: Witness program hash mismatch. When I debugged my bitcoin-core transaction I noticed the stack size is zero.

I verified my private keys are correct.

My decode transaction:

```
{
  "txid": "4454f34656a89f0ac4a2097fab289f4a8b38cb301e98b600362c135e2c18d10a",
  "hash": "4454f34656a89f0ac4a2097fab289f4a8b38cb301e98b600362c135e2c18d10a",
  "version": 2,
  "size": 157,
  "vsize": 157,
  "weight": 628,
  "locktime": 0,
  "vin": [
    {
      "txid": "53be831aad07b549ec91666674d28da5761f74f4a832e9fe93675c6449db7a24",
      "vout": 0,
      "scriptSig": {
        "asm": "",
        "hex": ""
      },
      "sequence": 4294967295
    }
  ],
  "vout": [
    {
      "value": 99.79997001,
      "n": 0,
      "scriptPubKey": {
        "asm": "0 f508fe341dfe0fbbeb7a38b41e7d2681d2376697",
        "desc": "addr(tpr1q75y0udqalc8mh6m68z6pulfxs8frwe5hxslc32)#xxr7capg",
        "hex": "0014f508fe341dfe0fbbeb7a38b41e7d2681d2376697",
        "address": "tpr1q75y0udqalc8mh6m68z6pulfxs8frwe5hxslc32",
        "type": "witness_v0_keyhash"
      }
    },
    {
      "value": 0.00000000,
      "n": 1,
      "scriptPubKey": {
        "asm": "OP_RETURN b48dfcd241e5894a8a5b8cef6782734481ee180ed3fd9d164e58307527e8f07082b12c5ba8baa3f05c66966334aea0eecbcb8f2bc5d14bfbddc332c1e39ca8c8",
        "desc": "raw(6a40b48dfcd241e5894a8a5b8cef6782734481ee180ed3fd9d164e58307527e8f07082b12c5ba8baa3f05c66966334aea0eecbcb8f2bc5d14bfbddc332c1e39ca8c8)#en45fqnk",
        "hex": "6a40b48dfcd241e5894a8a5b8cef6782734481ee180ed3fd9d164e58307527e8f07082b12c5ba8baa3f05c66966334aea0eecbcb8f2bc5d14bfbddc332c1e39ca8c8",
        "type": "nulldata"
      }
    }
  ]
}

```

### EDIT

The decoded input transaction is transaction relies on two different outputs

```
{
  "txid": "53be831aad07b549ec91666674d28da5761f74f4a832e9fe93675c6449db7a24",
  "hash": "f50d764b8f662e7c12d794d9ac2a87775de35982544571bc6be83ed12eb818cf",
  "version": 2,
  "size": 370,
  "vsize": 208,
  "weight": 832,
  "locktime": 0,
  "vin": [
    {
      "txid": "540a6ce5413d602c8830589bcbfd70fe1f31f4229488c12f5dbd746a4b1bff07",
      "vout": 0,
      "scriptSig": {
        "asm": "",
        "hex": ""
      },
      "txinwitness": [
        "304402204ee1d2b35adfe522517905f8eb3bee9cf91c15c0139673d52ba637aff7f9790d022055930d64c0a5d62f40e8d8fd200898341b7141bef708f8ae9182c1adbe489f6301",
        "02e0b590ccf577215eee2aa121d573fb26b83bd2c397d0446fd27ae3436c83803c"
      ],
      "sequence": 4294967295
    },
    {
      "txid": "e615c045166fb19cf485fb34d246931d3a1acda0d7510efc7bf6d6eee05ad807",
      "vout": 0,
      "scriptSig": {
        "asm": "",
        "hex": ""
      },
      "txinwitness": [
        "304402200788197af3f73245a5e783c325b5ef397a47bcf19ea2b02b48c74c066bcaab5902207199f905b20bde2b8c1b7b359a4e1bdf6ea1c6a9eed6cb8698b04b6df5bfb05f01",
        "02e0b590ccf577215eee2aa121d573fb26b83bd2c397d0446fd27ae3436c83803c"
      ],
      "sequence": 4294967295
    }
  ],
  "vout": [
    {
      "value": 99.79999001,
      "n": 0,
      "scriptPubKey": {
        "asm": "0 cd658ab850ca1f743496a16d58762fe7a2c39758",
        "desc": "addr(tpr1qe4jc4wzseg0hgdyk59k4sa30u73v896clelyyw)#eags8sr8",
        "hex": "0014cd658ab850ca1f743496a16d58762fe7a2c39758",
        "address": "tpr1qe4jc4wzseg0hgdyk59k4sa30u73v896clelyyw",
        "type": "witness_v0_keyhash"
      }
    },
    {
      "value": 0.20000000,
      "n": 1,
      "scriptPubKey": {
        "asm": "0 5f67b467ab1e01e0c803f26b36ade593f1ae6f2f",
        "desc": "addr(tpr1qtanmgeatrcq7pjqr7f4ndt09j0c6ume0yph3xl)#fnunjym6",
        "hex": "00145f67b467ab1e01e0c803f26b36ade593f1ae6f2f",
        "address": "tpr1qtanmgeatrcq7pjqr7f4ndt09j0c6ume0yph3xl",
        "type": "witness_v0_keyhash"
      }
    }
  ]
}

```

**Tags:** bitcoin-core, signrawtransaction

> **Comments:**
> **username_1**: so first what kind of address did you use here when you built your transaction? WPKH(segwit native) or Taproot?  
> **username_2**: Could you please also provide the transaction that created the TXO you are spending?  
> **username_0**: The addresses are native segwit  
> **username_0**: @username_2 I edited my question  
> **username_2**: It’s kinda hard to tell what’s going on when you remove the fields that we would be looking at to understand what’s going on. You said this is Regtest, so it’s a private testnet on your own computer, any particular reason why you are removing part of the output?  
> **username_0**: @username_2 I created a unique prefix for my addresses in order not to be confused with the mainnet bitcoin addresses. I re-edit the question.  
> **username_2**: How did you implement the prefix? Did you change the witness version in the output script?  
> **username_0**: @username_2 I changed the `bech32_hrp` prefix and recompiled bitcoin core. When I have a transaction with one input and two outputs I managed to sign the transaction.  

---

## 0 answers

