<p>Yes, this is the problem.</p>

<p>Pre-segwit there is a standardness rule in Bitcoin Core that requires a single element only on the stack after execution.</p>

<p>In P2WSH, this is part of the consensus rules.</p>

<p>The reason for this is that without such a rule it is trivial to malleate any transaction: just prefix the scriptSig with additional garbage elements, which would never be inspected by the locking script, and thus just passed through.</p>

CC BY-SA 4.0
2019-12-01T00:55:03.700Z
Thank you, makes perfect sense. I take it that my `OP_2 OP_3` scriptPubKey is unspendable unless I mine it myself?
inersha
CC BY-SA 4.0
2019-12-01T00:21:15.040Z
2019-12-01T00:21:15.040Z
Pieter Wuille
<p>Is a script spendable if the top item left on the stack evaluates to "<code>TRUE</code>", and that is the <strong>only item left in the stack</strong>?</p>

<p>In other words, is it okay for multiple items to be left on the stack?</p>

<hr>

<p>For example,</p>

<p>A <code>scriptPubKey</code> + <code>scriptSig</code> is spenable if an <code>OP_1</code> (or anything other than <code>OP_0</code> or nothing) is left on top of the stack after the script has finished executing.</p>

<pre><code>scriptPubKey: OP_DUP OP_HASH160 &lt;pubkeyhash&gt; OP_EQUALVERIFY OP_CHECKSIG
scriptSig:    &lt;signature&gt; &lt;pubkey&gt;
</code></pre>

<p>If the <code>&lt;pubkey&gt;</code> hashes to the <code>&lt;pubkeyhash&gt;</code>, and the <code>&lt;signature&gt;</code> corresponds the <code>&lt;pubkey&gt;</code>, then <code>OP_CHECKSIG</code> will end up leaving the following on the stack:</p>

<pre><code>stack: OP_1
</code></pre>

<p>However, if you had the following <code>scriptPubKey</code> + <code>scriptSig</code>:</p>

<pre><code>scriptPubKey: OP_2 OP_3
scriptSig:    OP_1
</code></pre>

<p>This would leave the following stack:</p>

<pre><code>stack: OP_1 OP_2 OP_3
</code></pre>

<p>Would this evaluate to <code>TRUE</code> and mean the script is spendable?</p>

<p>I'm getting a <code>non-mandatory-script-verify-flag (Extra items left on stack after execution) (code 64)</code> error, and I'm wondering if this is the problem.</p>

<script>
Is a script spendable if multiple items are left on the stack?
inersha
# Is a script spendable if multiple items are left on the stack?

(Asked by: username_0 on 2019-12-01)

Is a script spendable if the top item left on the stack evaluates to "`TRUE`", and that is the **only item left in the stack**?

In other words, is it okay for multiple items to be left on the stack?

---

For example,

A `scriptPubKey` + `scriptSig` is spenable if an `OP_1` (or anything other than `OP_0` or nothing) is left on top of the stack after the script has finished executing.

```
scriptPubKey: OP_DUP OP_HASH160 <pubkeyhash> OP_EQUALVERIFY OP_CHECKSIG
scriptSig:    <signature> <pubkey>

```

If the `<pubkey>` hashes to the `<pubkeyhash>`, and the `<signature>` corresponds the `<pubkey>`, then `OP_CHECKSIG` will end up leaving the following on the stack:

```
stack: OP_1

```

However, if you had the following `scriptPubKey` + `scriptSig`:

```
scriptPubKey: OP_2 OP_3
scriptSig:    OP_1

```

This would leave the following stack:

```
stack: OP_1 OP_2 OP_3

```

Would this evaluate to `TRUE` and mean the script is spendable?

I'm getting a `non-mandatory-script-verify-flag (Extra items left on stack after execution) (code 64)` error, and I'm wondering if this is the problem.

**Tags:** script


---

## 1 answers

### Answer by username_1 on 2019-12-01. Score: 6 | Accepted answer

Yes, this is the problem.

Pre-segwit there is a standardness rule in Bitcoin Core that requires a single element only on the stack after execution.

In P2WSH, this is part of the consensus rules.

The reason for this is that without such a rule it is trivial to malleate any transaction: just prefix the scriptSig with additional garbage elements, which would never be inspected by the locking script, and thus just passed through.

> **Comments:**
> **username_0**: Thank you, makes perfect sense. I take it that my `OP_2 OP_3` scriptPubKey is unspendable unless I mine it myself?  

---

