<p>Like arubi said, you're scriptSig is just <code>0x51</code>:</p>

<pre><code>$ bitcoin-cli decoderawtransaction 020000000174c3e24cbc6f8a0633e55f055e1747127e91f5b6e1157fc059e1b700b777f4db000000000151ffffffff01c0d401000000000023a820dbc1b4c900ffe48d575b5da5c638040125f65db0fe3e24494b76ea986457d9868700000000
{
  "txid": "2e7c6efc9dc6104f132a10d0d64263269d1ece326b4d64cb1061fe5a81b4d53b",
  "hash": "2e7c6efc9dc6104f132a10d0d64263269d1ece326b4d64cb1061fe5a81b4d53b",
  "version": 2,
  "size": 96,
  "vsize": 96,
  "weight": 384,
  "locktime": 0,
  "vin": [
    {
      "txid": "dbf477b700b7e159c07f15e1b6f5917e1247175e055fe533068a6fbc4ce2c374",
      "vout": 0,
      "scriptSig": {
        "asm": "1",
        "hex": "51"
      },
      "sequence": 4294967295
    }
  ],
  "vout": [
    {
      "value": 0.00120000,
      "n": 0,
      "scriptPubKey": {
        "asm": "OP_SHA256 dbc1b4c900ffe48d575b5da5c638040125f65db0fe3e24494b76ea986457d986 OP_EQUAL",
        "hex": "a820dbc1b4c900ffe48d575b5da5c638040125f65db0fe3e24494b76ea986457d98687",
        "type": "nonstandard"
      }
    }
  ]
}
</code></pre>

<p>This means if the <code>scriptPubKey</code> of the input you're spending is:</p>

<pre><code>OP_IF 
    OP_SHA256 4bf5122f344554c53bde2ebb8cd2b7e3d1600ad631c385a5d7cce23c7785459a OP_EQUAL 
OP_ELSE 
    10 OP_CHECKLOCKTIMEVERIFY OP_DROP OP_SHA256 dbc1b4c900ffe48d575b5da5c638040125f65db0fe3e24494b76ea986457d986 OP_EQUAL
OP_ENDIF
</code></pre>

<p>It will execute this branch (since the top stack element is true):</p>

<pre><code>OP_IF 
    OP_SHA256 4bf5122f344554c53bde2ebb8cd2b7e3d1600ad631c385a5d7cce23c7785459a OP_EQUAL 
</code></pre>

<p>You must also provide whatever hashes to the value <code>4bf5122f344554c53bde2ebb8cd2b7e3d1600ad631c385a5d7cce23c7785459a</code> in order for it to return successfully.</p>

CC BY-SA 4.0
2018-12-07T20:29:27.500Z
2018-12-07T21:09:47.997Z
2018-12-07T21:09:47.997Z
JBaczuk
<p>Your transaction only has <code>0x51</code> (just <code>OP_1</code>) in its scriptsig,  the <code>OP_IF</code> consumes the <code>1</code>, and <code>OP_SHA256</code> then operates on an empty stack, causing this error.</p>

CC BY-SA 4.0
2018-12-07T20:12:41.443Z
2018-12-07T20:12:41.443Z
arubi
<p>According to bip65
<a href="https://github.com/bitcoin/bips/blob/master/bip-0065.mediawiki" rel="nofollow noreferrer">https://github.com/bitcoin/bips/blob/master/bip-0065.mediawiki</a></p>

<p>I can use expressions like IF ... ELSE ... ENDIF
Here is example script from this document:</p>

<pre><code>IF
    HASH160 &lt;Hash160(encryption key)&gt; EQUALVERIFY
    &lt;publisher pubkey&gt; CHECKSIG
ELSE
    &lt;expiry time&gt; CHECKLOCKTIMEVERIFY DROP
    &lt;buyer pubkey&gt; CHECKSIG
ENDIF
</code></pre>

<p>But when I trying to spend transaction with the following script:</p>

<pre><code>OP_IF 
    OP_SHA256 4bf5122f344554c53bde2ebb8cd2b7e3d1600ad631c385a5d7cce23c7785459a OP_EQUAL 
OP_ELSE 
    10 OP_CHECKLOCKTIMEVERIFY OP_DROP OP_SHA256 dbc1b4c900ffe48d575b5da5c638040125f65db0fe3e24494b76ea986457d986 OP_EQUAL
OP_ENDIF
</code></pre>

<p><a href="https://tchain.btc.com/dbf477b700b7e159c07f15e1b6f5917e1247175e055fe533068a6fbc4ce2c374" rel="nofollow noreferrer">https://tchain.btc.com/dbf477b700b7e159c07f15e1b6f5917e1247175e055fe533068a6fbc4ce2c374</a></p>

<p>I get error:</p>

<pre><code>bitcoin-cli -testnet sendrawtransaction 020000000174c3e24cbc6f8a0633e55f055e1747127e91f5b6e1157fc059e1b700b777f4db000000000151ffffffff01c0d401000000000023a820dbc1b4c900ffe48d575b5da5c638040125f65db0fe3e24494b76ea986457d9868700000000
error code: -26
error message:
mandatory-script-verify-flag-failed (Operation not valid with the current stack size) (code 16)
</code></pre>

<p>Where is my error ? </p>

<p>P.S. </p>

<blockquote>
  <p>SHA256 from 1 ->
  4bf5122f344554c53bde2ebb8cd2b7e3d1600ad631c385a5d7cce23c7785459a</p>
  
  <p>SHA256 from 2 ->
  dbc1b4c900ffe48d575b5da5c638040125f65db0fe3e24494b76ea986457d986</p>
</blockquote>

<bitcoind><script>
Operation not valid with the current stack size
Andrew
# Operation not valid with the current stack size

(Asked by: username_0 on 2018-12-07)

According to bip65
<https://github.com/bitcoin/bips/blob/master/bip-0065.mediawiki>

I can use expressions like IF ... ELSE ... ENDIF
Here is example script from this document:

```
IF
    HASH160 <Hash160(encryption key)> EQUALVERIFY
    <publisher pubkey> CHECKSIG
ELSE
    <expiry time> CHECKLOCKTIMEVERIFY DROP
    <buyer pubkey> CHECKSIG
ENDIF

```

But when I trying to spend transaction with the following script:

```
OP_IF 
    OP_SHA256 4bf5122f344554c53bde2ebb8cd2b7e3d1600ad631c385a5d7cce23c7785459a OP_EQUAL 
OP_ELSE 
    10 OP_CHECKLOCKTIMEVERIFY OP_DROP OP_SHA256 dbc1b4c900ffe48d575b5da5c638040125f65db0fe3e24494b76ea986457d986 OP_EQUAL
OP_ENDIF

```

<https://tchain.btc.com/dbf477b700b7e159c07f15e1b6f5917e1247175e055fe533068a6fbc4ce2c374>

I get error:

```
bitcoin-cli -testnet sendrawtransaction 020000000174c3e24cbc6f8a0633e55f055e1747127e91f5b6e1157fc059e1b700b777f4db000000000151ffffffff01c0d401000000000023a820dbc1b4c900ffe48d575b5da5c638040125f65db0fe3e24494b76ea986457d9868700000000
error code: -26
error message:
mandatory-script-verify-flag-failed (Operation not valid with the current stack size) (code 16)

```

Where is my error ?

P.S.

> SHA256 from 1 ->
> 4bf5122f344554c53bde2ebb8cd2b7e3d1600ad631c385a5d7cce23c7785459a
>
> SHA256 from 2 ->
> dbc1b4c900ffe48d575b5da5c638040125f65db0fe3e24494b76ea986457d986

**Tags:** bitcoind, script


---

## 2 answers

### Answer by username_2 on 2018-12-07. Score: 6 | Accepted answer

Your transaction only has `0x51` (just `OP_1`) in its scriptsig, the `OP_IF` consumes the `1`, and `OP_SHA256` then operates on an empty stack, causing this error.


---

### Answer by username_1 on 2018-12-07. Score: 4

Like username_2 said, you're scriptSig is just `0x51`:

```
$ bitcoin-cli decoderawtransaction 020000000174c3e24cbc6f8a0633e55f055e1747127e91f5b6e1157fc059e1b700b777f4db000000000151ffffffff01c0d401000000000023a820dbc1b4c900ffe48d575b5da5c638040125f65db0fe3e24494b76ea986457d9868700000000
{
  "txid": "2e7c6efc9dc6104f132a10d0d64263269d1ece326b4d64cb1061fe5a81b4d53b",
  "hash": "2e7c6efc9dc6104f132a10d0d64263269d1ece326b4d64cb1061fe5a81b4d53b",
  "version": 2,
  "size": 96,
  "vsize": 96,
  "weight": 384,
  "locktime": 0,
  "vin": [
    {
      "txid": "dbf477b700b7e159c07f15e1b6f5917e1247175e055fe533068a6fbc4ce2c374",
      "vout": 0,
      "scriptSig": {
        "asm": "1",
        "hex": "51"
      },
      "sequence": 4294967295
    }
  ],
  "vout": [
    {
      "value": 0.00120000,
      "n": 0,
      "scriptPubKey": {
        "asm": "OP_SHA256 dbc1b4c900ffe48d575b5da5c638040125f65db0fe3e24494b76ea986457d986 OP_EQUAL",
        "hex": "a820dbc1b4c900ffe48d575b5da5c638040125f65db0fe3e24494b76ea986457d98687",
        "type": "nonstandard"
      }
    }
  ]
}

```

This means if the `scriptPubKey` of the input you're spending is:

```
OP_IF 
    OP_SHA256 4bf5122f344554c53bde2ebb8cd2b7e3d1600ad631c385a5d7cce23c7785459a OP_EQUAL 
OP_ELSE 
    10 OP_CHECKLOCKTIMEVERIFY OP_DROP OP_SHA256 dbc1b4c900ffe48d575b5da5c638040125f65db0fe3e24494b76ea986457d986 OP_EQUAL
OP_ENDIF

```

It will execute this branch (since the top stack element is true):

```
OP_IF 
    OP_SHA256 4bf5122f344554c53bde2ebb8cd2b7e3d1600ad631c385a5d7cce23c7785459a OP_EQUAL 

```

You must also provide whatever hashes to the value `4bf5122f344554c53bde2ebb8cd2b7e3d1600ad631c385a5d7cce23c7785459a` in order for it to return successfully.


---

