<p>This error was caused by the same issue (minimal encoding) as <a href="https://bitcoin.stackexchange.com/questions/111590/problem-with-unlocking-p2wsh">problem with unlocking P2WSH</a>. The <a href="https://bitcoin.stackexchange.com/a/111595/128539">solution</a> Andrew Chow gave me there worked for me here too.</p>

CC BY-SA 4.0
2022-01-04T14:55:29.727Z
2022-01-04T14:55:29.727Z
Antoni
<p>I was the guy, who asked the other question.
In my case the problem was, that the operations left a unclean stack, which is technically ok, since the stack is not empty. But if I am correct its a non-standard transacition and will not be relayed by nodes.</p>
<p>In my case I had to finish with one element, which is not 0. And this was not possible in my script.</p>

CC BY-SA 4.0
2021-12-23T12:02:53.947Z
p2sh is not nonstandard. p2sh (or p2wsh) is the way to wrap nonstandard script in a script hash
Antoni
CC BY-SA 4.0
2021-12-22T22:09:18.823Z
2021-12-22T22:09:18.823Z
unpwn
<p>after learning a lot about script (and playing with them on the testnet) i made a way longer script.</p>
<pre><code>$ btc decodescript 7455886f94935688789352885279935b88946e935b88945187
{
  &quot;asm&quot;: &quot;OP_DEPTH 5 OP_EQUALVERIFY OP_3DUP OP_SUB OP_ADD 6 OP_EQUALVERIFY OP_OVER OP_ADD 2 OP_EQUALVERIFY 2 OP_PICK OP_ADD 11 OP_EQUALVERIFY OP_SUB OP_2DUP OP_ADD 11 OP_EQUALVERIFY OP_SUB 1 OP_EQUAL&quot;,
  ...
  &quot;segwit&quot;: {
    ...
    &quot;address&quot;: &quot;tb1q2c0uglp5tg2dhnr3ejuwppalp9urdfu4cxnl2sc495vlzmjy2ggs2wk7ry&quot;,
    ...
  }
}
</code></pre>
<p>the solution to this script is <code>6</code> <code>9</code> <code>4</code> <code>2</code> <code>0</code>.</p>
<p>however, when redeeming the 1000 sat from the p2wsh address it gives me the error:</p>
<pre><code>$ bitcoin-cli -testnet sendrawtransaction 010000000001019f084303418f25b5a77f36b95f293b052e9d885d98020be3f66fb223939bbbe00000000000ffffffff018c030000000000001600140f4eb1382443259e6d295d8ddf1ade059e4b1f8c0601060109010401020100197455886f94935688789352885279935b88946e935b8894518700000000
error code: -26
error message:
non-mandatory-script-verify-flag (unknown error)
</code></pre>
<p>i searched around a bit on bitcoin se and the only useful thing i could find was a <a href="https://bitcoin.stackexchange.com/questions/111011/non-mandatory-script-verify-flag-unknown-error">post</a> complaining about <code>OP_PICK</code>. Somebody knows how to fix this?</p>
<p>PS: i really don't care about 1000 test sat but just i want to fix this to learn from it :)</p>

<script><raw-transaction><p2sh><p2wsh>
non-mandatory-script-verify-flag (unknown error) with a script that runs ok in btcdeb
Antoni
# non-mandatory-script-verify-flag (unknown error) with a script that runs ok in btcdeb

(Asked by: username_0 on 2021-12-22)

after learning a lot about script (and playing with them on the testnet) i made a way longer script.
$ btc decodescript 7455886f94935688789352885279935b88946e935b88945187
{
  "asm": "OP_DEPTH 5 OP_EQUALVERIFY OP_3DUP OP_SUB OP_ADD 6 OP_EQUALVERIFY OP_OVER OP_ADD 2 OP_EQUALVERIFY 2 OP_PICK OP_ADD 11 OP_EQUALVERIFY OP_SUB OP_2DUP OP_ADD 11 OP_EQUALVERIFY OP_SUB 1 OP_EQUAL",
  ...
  "segwit": {
    ...
    "address": "tb1q2c0uglp5tg2dhnr3ejuwppalp9urdfu4cxnl2sc495vlzmjy2ggs2wk7ry",
    ...
  }
}

the solution to this script is 6 9 4 2 0.
however, when redeeming the 1000 sat from the p2wsh address it gives me the error:
$ bitcoin-cli -testnet sendrawtransaction 010000000001019f084303418f25b5a77f36b95f293b052e9d885d98020be3f66fb223939bbbe00000000000ffffffff018c030000000000001600140f4eb1382443259e6d295d8ddf1ade059e4b1f8c0601060109010401020100197455886f94935688789352885279935b88946e935b8894518700000000
error code: -26
error message:
non-mandatory-script-verify-flag (unknown error)

i searched around a bit on bitcoin se and the only useful thing i could find was a post complaining about OP_PICK. Somebody knows how to fix this?
PS: i really don't care about 1000 test sat but just i want to fix this to learn from it :)

**Tags:** script, raw-transaction, p2sh, p2wsh


---

## 2 answers

### Answer by username_0 on 2022-01-04. Score: 0 | Accepted answer

This error was caused by the same issue (minimal encoding) as [problem with unlocking P2WSH](https://bitcoin.stackexchange.com/questions/111590/problem-with-unlocking-p2wsh). The [solution](https://bitcoin.stackexchange.com/a/111595/128539) Andrew Chow gave me there worked for me here too.


---

### Answer by username_1 on 2021-12-22. Score: 0

I was the guy, who asked the other question.
In my case the problem was, that the operations left a unclean stack, which is technically ok, since the stack is not empty. But if I am correct its a non-standard transacition and will not be relayed by nodes.

In my case I had to finish with one element, which is not 0. And this was not possible in my script.

> **Comments:**
> **username_0**: p2sh is not nonstandard. p2sh (or p2wsh) is the way to wrap nonstandard script in a script hash  

---

