<p>You need to encode the number 99 (0x63000000) as a single byte (0x63) because</p>
<ul>
<li>OP_ADD returns the result in the fewest bytes sufficient to store the value and because</li>
<li>OP_EQUAL takes the length of its operands into account. For example it considers 0x63 to be not equal to 0x6300.</li>
</ul>
<p>I played around with a <a href="https://bitcoin-script-debugger.visvirial.com/?input=OP_PUSHDATA1%204%200x01000000%20OP_PUSHDATA1%204%200x01000000%20OP_ADD%20OP_PUSHDATA1%201%200x02%20OP_EQUAL" rel="nofollow noreferrer">script debugger</a> to check the length of the value returned by OP_ADD and the effect of operand lengths on OP_EQUAL.</p>
<hr />
<p>Related</p>
<ul>
<li><a href="https://bitcoin.stackexchange.com/q/115198/13866">Why is there a OP_NUMEQUAL opcode? Does OP_NUMEQUAL offer a subset of the functionality of OP_EQUAL?</a></li>
</ul>

CC BY-SA 4.0
2023-08-14T10:16:38.403Z
2023-08-31T09:35:15.527Z
2023-08-31T09:35:15.527Z
RedGrittyBrick
<p>Finally got it. Turns out I needed to encode the number on the witness stack as a single byte. <code>63</code> instead of <code>63000000</code>.</p>
<p>I don't suppose anyone can explain why that is necessary?</p>

CC BY-SA 4.0
2023-08-14T04:56:03.587Z
2023-08-14T04:56:03.587Z
ursuscamp
<p>I'm experiment with building SegWit transactions manually, and I've written a non-standard simple script just for testing. No signing or anything, just your usual &quot;add two numbers, check equality&quot; script. However, when attempting to broadcast it, I get an error.</p>
<p>I already sent the coins to the script, now I'm just trying to spend from it.</p>
<p>Here is my input:</p>
<pre><code>{
  &quot;txid&quot;: &quot;174692a9b447d62043b90059c83237b0526bc09551aa39839a1d4fafc29252b7&quot;,
  &quot;hash&quot;: &quot;27afb30315f82dd64815ef259b7f4075359d42390f549b9a05132d11cf0d5670&quot;,
  &quot;version&quot;: 2,
  &quot;size&quot;: 205,
  &quot;vsize&quot;: 154,
  &quot;weight&quot;: 616,
  &quot;locktime&quot;: 206,
  &quot;vin&quot;: [
    {
      &quot;txid&quot;: &quot;1e025a8b1af84f4b7f0724b89ed0fc3b0ee6f2e8d1c0b635827edf6f60a0ff9e&quot;,
      &quot;vout&quot;: 0,
      &quot;scriptSig&quot;: {
        &quot;asm&quot;: &quot;&quot;,
        &quot;hex&quot;: &quot;&quot;
      },
      &quot;txinwitness&quot;: [
        &quot;2b8aac44cbfe12c56ddfd1ff2a0021c6f9b4e76b0325b44a647365ae9e695044029f6f7eb409baee56803e80e47a643711703795c955a8bdc5a0abc5761902fe&quot;
      ],
      &quot;sequence&quot;: 4294967293
    }
  ],
  &quot;vout&quot;: [
    {
      &quot;value&quot;: 1.00000000,
      &quot;n&quot;: 0,
      &quot;scriptPubKey&quot;: {
        &quot;asm&quot;: &quot;0 8b88aeecc8810057147ae75bb5fef0b88e74cdd69877a0b0d9119cbc0a13bd18&quot;,
        &quot;desc&quot;: &quot;addr(bcrt1q3wy2amxgsyq9w9r6uadmtlhshz88fnwknpm6pvxezxwtczsnh5vq8ynwca)#88xz032h&quot;,
        &quot;hex&quot;: &quot;00208b88aeecc8810057147ae75bb5fef0b88e74cdd69877a0b0d9119cbc0a13bd18&quot;,
        &quot;address&quot;: &quot;bcrt1q3wy2amxgsyq9w9r6uadmtlhshz88fnwknpm6pvxezxwtczsnh5vq8ynwca&quot;,
        &quot;type&quot;: &quot;witness_v0_scripthash&quot;
      }
    },
    {
      &quot;value&quot;: 46.99952700,
      &quot;n&quot;: 1,
      &quot;scriptPubKey&quot;: {
        &quot;asm&quot;: &quot;1 ab0af65a053979dfd08b9673405900f185b6d45edea4dddd5dec9b7ec2eba5fc&quot;,
        &quot;desc&quot;: &quot;rawtr(ab0af65a053979dfd08b9673405900f185b6d45edea4dddd5dec9b7ec2eba5fc)#utsgce08&quot;,
        &quot;hex&quot;: &quot;5120ab0af65a053979dfd08b9673405900f185b6d45edea4dddd5dec9b7ec2eba5fc&quot;,
        &quot;address&quot;: &quot;bcrt1p4v90vks989ual5ytjee5qkgq7xzmd4z7m6jdmh2aajdhasht5h7qx008qn&quot;,
        &quot;type&quot;: &quot;witness_v1_taproot&quot;
      }
    }
  ]
}
</code></pre>
<p>Vout 0 is the output of interest here.</p>
<p>Here is my decoded transaction when I attempt to spend it:</p>
<pre><code>{
  &quot;txid&quot;: &quot;0110d9fd63ec46c2b47bc589d2f032d10f288912e4d82c88c8aaa1dfed251909&quot;,
  &quot;hash&quot;: &quot;08881deca20dc914f14a03d5caf97bd4b7c717ef9047b1a6f70f5deb44eb8545&quot;,
  &quot;version&quot;: 1,
  &quot;size&quot;: 96,
  &quot;vsize&quot;: 86,
  &quot;weight&quot;: 342,
  &quot;locktime&quot;: 0,
  &quot;vin&quot;: [
    {
      &quot;txid&quot;: &quot;174692a9b447d62043b90059c83237b0526bc09551aa39839a1d4fafc29252b7&quot;,
      &quot;vout&quot;: 0,
      &quot;scriptSig&quot;: {
        &quot;asm&quot;: &quot;&quot;,
        &quot;hex&quot;: &quot;&quot;
      },
      &quot;txinwitness&quot;: [
        &quot;63000000&quot;,
        &quot;5193016487&quot;
      ],
      &quot;sequence&quot;: 0
    }
  ],
  &quot;vout&quot;: [
    {
      &quot;value&quot;: 0.50000000,
      &quot;n&quot;: 0,
      &quot;scriptPubKey&quot;: {
        &quot;asm&quot;: &quot;0 43620bf89a7acd30cc09914e023cdce377e70828&quot;,
        &quot;desc&quot;: &quot;addr(bcrt1qgd3qh7y60txnpnqfj98qy0xuudm7wzpgz5c02y)#thrxqf0c&quot;,
        &quot;hex&quot;: &quot;001443620bf89a7acd30cc09914e023cdce377e70828&quot;,
        &quot;address&quot;: &quot;bcrt1qgd3qh7y60txnpnqfj98qy0xuudm7wzpgz5c02y&quot;,
        &quot;type&quot;: &quot;witness_v0_keyhash&quot;
      }
    }
  ]
}
</code></pre>
<p>The witness script (<code>5193016487</code>) is <code>1 OP_ADD 100 OP_EQUAL</code>. The witness stack also has 99 (<code>63000000</code>).</p>
<p>Why do I get this verify error when I attempt to broadcast it?</p>
<pre><code>error code: -26
error message:
non-mandatory-script-verify-flag (unknown error)
</code></pre>

<script><segregated-witness><development><p2wsh>
Why is this P2WSH spend triggering a verification failure when broadcasting?
ursuscamp
# Why is this P2WSH spend triggering a verification failure when broadcasting?

(Asked by: username_0 on 2023-08-14)

I'm experiment with building SegWit transactions manually, and I've written a non-standard simple script just for testing. No signing or anything, just your usual "add two numbers, check equality" script. However, when attempting to broadcast it, I get an error.

I already sent the coins to the script, now I'm just trying to spend from it.

Here is my input:

```
{
  "txid": "174692a9b447d62043b90059c83237b0526bc09551aa39839a1d4fafc29252b7",
  "hash": "27afb30315f82dd64815ef259b7f4075359d42390f549b9a05132d11cf0d5670",
  "version": 2,
  "size": 205,
  "vsize": 154,
  "weight": 616,
  "locktime": 206,
  "vin": [
    {
      "txid": "1e025a8b1af84f4b7f0724b89ed0fc3b0ee6f2e8d1c0b635827edf6f60a0ff9e",
      "vout": 0,
      "scriptSig": {
        "asm": "",
        "hex": ""
      },
      "txinwitness": [
        "2b8aac44cbfe12c56ddfd1ff2a0021c6f9b4e76b0325b44a647365ae9e695044029f6f7eb409baee56803e80e47a643711703795c955a8bdc5a0abc5761902fe"
      ],
      "sequence": 4294967293
    }
  ],
  "vout": [
    {
      "value": 1.00000000,
      "n": 0,
      "scriptPubKey": {
        "asm": "0 8b88aeecc8810057147ae75bb5fef0b88e74cdd69877a0b0d9119cbc0a13bd18",
        "desc": "addr(bcrt1q3wy2amxgsyq9w9r6uadmtlhshz88fnwknpm6pvxezxwtczsnh5vq8ynwca)#88xz032h",
        "hex": "00208b88aeecc8810057147ae75bb5fef0b88e74cdd69877a0b0d9119cbc0a13bd18",
        "address": "bcrt1q3wy2amxgsyq9w9r6uadmtlhshz88fnwknpm6pvxezxwtczsnh5vq8ynwca",
        "type": "witness_v0_scripthash"
      }
    },
    {
      "value": 46.99952700,
      "n": 1,
      "scriptPubKey": {
        "asm": "1 ab0af65a053979dfd08b9673405900f185b6d45edea4dddd5dec9b7ec2eba5fc",
        "desc": "rawtr(ab0af65a053979dfd08b9673405900f185b6d45edea4dddd5dec9b7ec2eba5fc)#utsgce08",
        "hex": "5120ab0af65a053979dfd08b9673405900f185b6d45edea4dddd5dec9b7ec2eba5fc",
        "address": "bcrt1p4v90vks989ual5ytjee5qkgq7xzmd4z7m6jdmh2aajdhasht5h7qx008qn",
        "type": "witness_v1_taproot"
      }
    }
  ]
}

```

Vout 0 is the output of interest here.

Here is my decoded transaction when I attempt to spend it:

```
{
  "txid": "0110d9fd63ec46c2b47bc589d2f032d10f288912e4d82c88c8aaa1dfed251909",
  "hash": "08881deca20dc914f14a03d5caf97bd4b7c717ef9047b1a6f70f5deb44eb8545",
  "version": 1,
  "size": 96,
  "vsize": 86,
  "weight": 342,
  "locktime": 0,
  "vin": [
    {
      "txid": "174692a9b447d62043b90059c83237b0526bc09551aa39839a1d4fafc29252b7",
      "vout": 0,
      "scriptSig": {
        "asm": "",
        "hex": ""
      },
      "txinwitness": [
        "63000000",
        "5193016487"
      ],
      "sequence": 0
    }
  ],
  "vout": [
    {
      "value": 0.50000000,
      "n": 0,
      "scriptPubKey": {
        "asm": "0 43620bf89a7acd30cc09914e023cdce377e70828",
        "desc": "addr(bcrt1qgd3qh7y60txnpnqfj98qy0xuudm7wzpgz5c02y)#thrxqf0c",
        "hex": "001443620bf89a7acd30cc09914e023cdce377e70828",
        "address": "bcrt1qgd3qh7y60txnpnqfj98qy0xuudm7wzpgz5c02y",
        "type": "witness_v0_keyhash"
      }
    }
  ]
}

```

The witness script (`5193016487`) is `1 OP_ADD 100 OP_EQUAL`. The witness stack also has 99 (`63000000`).

Why do I get this verify error when I attempt to broadcast it?

```
error code: -26
error message:
non-mandatory-script-verify-flag (unknown error)

```

**Tags:** script, segregated-witness, development, p2wsh


---

## 2 answers

### Answer by username_1 on 2023-08-14. Score: 1 | Accepted answer

You need to encode the number 99 (0x63000000) as a single byte (0x63) because

* OP\_ADD returns the result in the fewest bytes sufficient to store the value and because
* OP\_EQUAL takes the length of its operands into account. For example it considers 0x63 to be not equal to 0x6300.

I played around with a [script debugger](https://bitcoin-script-debugger.visvirial.com/?input=OP_PUSHDATA1%204%200x01000000%20OP_PUSHDATA1%204%200x01000000%20OP_ADD%20OP_PUSHDATA1%201%200x02%20OP_EQUAL) to check the length of the value returned by OP\_ADD and the effect of operand lengths on OP\_EQUAL.

---

Related

* [Why is there a OP\_NUMEQUAL opcode? Does OP\_NUMEQUAL offer a subset of the functionality of OP\_EQUAL?](https://bitcoin.stackexchange.com/q/115198/13866)


---

### Answer by username_0 on 2023-08-14. Score: 0

Finally got it. Turns out I needed to encode the number on the witness stack as a single byte. `63` instead of `63000000`.

I don't suppose anyone can explain why that is necessary?


---

