Is a script spendable if multiple items are left on the stack? 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 &lt;pubkeyhash&gt; OP_EQUALVERIFY OP_CHECKSIG
scriptSig:    &lt;signature&gt; &lt;pubkey&gt;


If the &lt;pubkey&gt; hashes to the &lt;pubkeyhash&gt;, and the &lt;signature&gt; corresponds the &lt;pubkey&gt;, 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.
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.