<p>Before the redeem script is executed, the stack looks like this (from top to bottom): <code>TRUE, Data3, Data2, Data1, Sig</code>. The <code>TRUE</code> on top of the stack comes from <code>OP_EQUAL</code>.</p>

<p>Now the redeem script runs and you drop the top three elements from the stack and then add <code>PubKey</code>, leaving you with <code>PubKey, Data1, Sig</code>. When <code>OP_CHECKSIG</code> runs now it uses <code>Data1</code> as Signature instead of <code>Sig</code> which makes it fail. At the end the stack is <code>FALSE, Sig</code>. The top element of the stack is <code>FALSE</code> which makes the transaction fail.</p>

CC BY-SA 4.0
2018-08-27T19:45:11.813Z
Thank you for your answer. Based on this, if I change `OP_DROP` on `OP_2DROP` this should resolve my problem but not.
Andr1i
CC BY-SA 4.0
2018-08-27T19:51:10.167Z
Did you make a completly new transaction? Because if you change `OP_DROP` to `OP_2DROP` the hash of the redeem script will be different and thus `OP_EQUAL` will return `FALSE` if you reuse your old `scriptPubKey` with the updated redeem script.
Bobface
CC BY-SA 4.0
2018-08-27T20:22:13.590Z
Yes, I updated it, but after I read your comment =). Also, I updated the post with new raw transaction.
Andr1i
CC BY-SA 4.0
2018-08-27T21:41:22.933Z
I found one more mistake in my raw transaction. There was `OP_PUSHDATA<PubKey>` together with `OP_CHECKSIG`. You helped to resolve my issue but I have new. When I'm sending that raw I get error `mandatory-script-verify-flag-failed (Signature is found in scriptCode)`. Maybe you know what's wrong?
Andr1i
CC BY-SA 4.0
2018-08-28T08:43:10.673Z
Sorry I also don't know what that means :( I suggest you make a new question with the new problem, maybe someone else knows whats wrong.
Bobface
CC BY-SA 4.0
2018-08-27T18:12:25.120Z
2018-08-27T19:35:17.200Z
2018-08-27T19:35:17.200Z
Bobface
<p>I'm trying to send transaction with script:</p>

<p><strong>ScriptSig</strong>: <code>OP_PUSHDATA&lt;Sig&gt; OP_PUSHDATA&lt;Data1&gt; OP_PUSHDATA&lt;Data2&gt; OP_PUSHDATA&lt;Data3&gt;</code> <code>OP_PUSHDATA&lt;RedeemScript&gt;</code></p>

<p>Since the data is less than 75 bytes in the raw transaction performed direct pushes.</p>

<p>RedeemScript: <code>2OP_DROP OP_2DROP OP_PUSHDATA&lt;PubKey&gt; OP_CHECKSIG</code></p>

<p>RedeemScriptHash160 of <code>6d6d2202ada9884dbd1e8bd90968ba66256f017cd77d83595027f7929ae3537f98c92d4aac</code>=<code>738292fc46dd7af803bd56035d0988af96a31681</code></p>

<p><strong>ScriptPubKey</strong>: <code>OP_HASH160 &lt;redeemScriptHash&gt; OP_EQUAL</code></p>

<p>But I get error when sending raw transaction:</p>

<blockquote>
  <p>code=-26, message=16: mandatory-script-verify-flag-failed (Script
  evaluated without error but finished with a false/empty top stack
  element)</p>
</blockquote>

<p>Could someone help to understand what is wrong with that script?
This this my transaction:</p>

<pre><code>020000000001012f15356f4dfb7f48a91a72f5ff1071f72cb5fe4acc29e98ff5ae17a008a01dba000000007C160014ac09dd336a6fc10034fc44dcb706855668921ce7141f8b0800ffc1765400038d78055c545df3ff5d4a141f8b0800ffc1765400038d78055c545df3ff5d4a141f8b0800ffc1765400038d78055c545df3ff5d4a246d6d2202ada9884dbd1e8bd90968ba66246f017cd77d83595027f7929ae3537f98c92d4aacffffffff01c005d9010000000017a914738292fc46dd7af803bd56035d0988af96a3168187024830450221009108d4e65a34fb50cd3283b6386a679f0dfc2b5fe97e3b3c3f6b8320814b3a2902204631daf2bb93605c9e079750092f304966b69fe28ce7701f4bc677714bca23af012102ada9884dbd1e8bd90968ba66256f017cd77d83595027f7929ae3537f98c92d4a00000000

{
  "result": {
    "txid": "441cf52028ee0acc8b4076681c7fd46dad03501be62c6b0050ca59090fa52973",
    "hash": "dad2b4c56556b74d87243149ca3384ce04584d3bd8d21d80e291c4f9eed7e3f8",
    "version": 2,
    "size": 317,
    "vsize": 235,
    "locktime": 0,
    "vin": [
      {
        "txid": "ba1da008a017aef58fe929cc4afeb52cf77110fff5721aa9487ffb4d6f35152f",
        "vout": 0,
        "scriptSig": {
          "asm": "0014ac09dd336a6fc10034fc44dcb706855668921ce7 1f8b0800ffc1765400038d78055c545df3ff5d4a 1f8b0800ffc1765400038d78055c545df3ff5d4a 1f8b0800ffc1765400038d78055c545df3ff5d4a 6d6d2202ada9884dbd1e8bd90968ba66246f017cd77d83595027f7929ae3537f98c92d4a OP_CHECKSIG",
          "hex": "160014ac09dd336a6fc10034fc44dcb706855668921ce7141f8b0800ffc1765400038d78055c545df3ff5d4a141f8b0800ffc1765400038d78055c545df3ff5d4a141f8b0800ffc1765400038d78055c545df3ff5d4a246d6d2202ada9884dbd1e8bd90968ba66246f017cd77d83595027f7929ae3537f98c92d4aac"
        },
        "txinwitness": [
          "30450221009108d4e65a34fb50cd3283b6386a679f0dfc2b5fe97e3b3c3f6b8320814b3a2902204631daf2bb93605c9e079750092f304966b69fe28ce7701f4bc677714bca23af01",
          "02ada9884dbd1e8bd90968ba66256f017cd77d83595027f7929ae3537f98c92d4a"
        ],
        "sequence": 4294967295
      }
    ],
    "vout": [
      {
        "value": 0.31,
        "n": 0,
        "scriptPubKey": {
          "asm": "OP_HASH160 738292fc46dd7af803bd56035d0988af96a31681 OP_EQUAL",
          "hex": "a914738292fc46dd7af803bd56035d0988af96a3168187",
          "reqSigs": 1,
          "type": "scripthash",
          "addresses": [
            "2N3mz7o8v3YT4arXdQ5p8So6q3FUGjhUpEE"
          ]
        }
      }
    ]
  },
  "error": null,
  "id": "curltext"
}
</code></pre>

<transactions><raw-transaction><p2sh>
Sending P2SH transaction with non-standard script
Andr1i
# Sending P2SH transaction with non-standard script

(Asked by: username_0 on 2018-08-27)

I'm trying to send transaction with script:
ScriptSig: OP_PUSHDATA OP_PUSHDATA OP_PUSHDATA OP_PUSHDATA OP_PUSHDATA
Since the data is less than 75 bytes in the raw transaction performed direct pushes.
RedeemScript: 2OP_DROP OP_2DROP OP_PUSHDATA OP_CHECKSIG
RedeemScriptHash160 of 6d6d2202ada9884dbd1e8bd90968ba66256f017cd77d83595027f7929ae3537f98c92d4aac=738292fc46dd7af803bd56035d0988af96a31681
ScriptPubKey: OP_HASH160  OP_EQUAL
But I get error when sending raw transaction:

code=-26, message=16: mandatory-script-verify-flag-failed (Script
  evaluated without error but finished with a false/empty top stack
  element)

Could someone help to understand what is wrong with that script?
This this my transaction:
020000000001012f15356f4dfb7f48a91a72f5ff1071f72cb5fe4acc29e98ff5ae17a008a01dba000000007C160014ac09dd336a6fc10034fc44dcb706855668921ce7141f8b0800ffc1765400038d78055c545df3ff5d4a141f8b0800ffc1765400038d78055c545df3ff5d4a141f8b0800ffc1765400038d78055c545df3ff5d4a246d6d2202ada9884dbd1e8bd90968ba66246f017cd77d83595027f7929ae3537f98c92d4aacffffffff01c005d9010000000017a914738292fc46dd7af803bd56035d0988af96a3168187024830450221009108d4e65a34fb50cd3283b6386a679f0dfc2b5fe97e3b3c3f6b8320814b3a2902204631daf2bb93605c9e079750092f304966b69fe28ce7701f4bc677714bca23af012102ada9884dbd1e8bd90968ba66256f017cd77d83595027f7929ae3537f98c92d4a00000000

{
  "result": {
    "txid": "441cf52028ee0acc8b4076681c7fd46dad03501be62c6b0050ca59090fa52973",
    "hash": "dad2b4c56556b74d87243149ca3384ce04584d3bd8d21d80e291c4f9eed7e3f8",
    "version": 2,
    "size": 317,
    "vsize": 235,
    "locktime": 0,
    "vin": [
      {
        "txid": "ba1da008a017aef58fe929cc4afeb52cf77110fff5721aa9487ffb4d6f35152f",
        "vout": 0,
        "scriptSig": {
          "asm": "0014ac09dd336a6fc10034fc44dcb706855668921ce7 1f8b0800ffc1765400038d78055c545df3ff5d4a 1f8b0800ffc1765400038d78055c545df3ff5d4a 1f8b0800ffc1765400038d78055c545df3ff5d4a 6d6d2202ada9884dbd1e8bd90968ba66246f017cd77d83595027f7929ae3537f98c92d4a OP_CHECKSIG",
          "hex": "160014ac09dd336a6fc10034fc44dcb706855668921ce7141f8b0800ffc1765400038d78055c545df3ff5d4a141f8b0800ffc1765400038d78055c545df3ff5d4a141f8b0800ffc1765400038d78055c545df3ff5d4a246d6d2202ada9884dbd1e8bd90968ba66246f017cd77d83595027f7929ae3537f98c92d4aac"
        },
        "txinwitness": [
          "30450221009108d4e65a34fb50cd3283b6386a679f0dfc2b5fe97e3b3c3f6b8320814b3a2902204631daf2bb93605c9e079750092f304966b69fe28ce7701f4bc677714bca23af01",
          "02ada9884dbd1e8bd90968ba66256f017cd77d83595027f7929ae3537f98c92d4a"
        ],
        "sequence": 4294967295
      }
    ],
    "vout": [
      {
        "value": 0.31,
        "n": 0,
        "scriptPubKey": {
          "asm": "OP_HASH160 738292fc46dd7af803bd56035d0988af96a31681 OP_EQUAL",
          "hex": "a914738292fc46dd7af803bd56035d0988af96a3168187",
          "reqSigs": 1,
          "type": "scripthash",
          "addresses": [
            "2N3mz7o8v3YT4arXdQ5p8So6q3FUGjhUpEE"
          ]
        }
      }
    ]
  },
  "error": null,
  "id": "curltext"
}

**Tags:** transactions, raw-transaction, p2sh


---

## 1 answers

### Answer by username_1 on 2018-08-27. Score: 1 | Accepted answer

Before the redeem script is executed, the stack looks like this (from top to bottom): `TRUE, Data3, Data2, Data1, Sig`. The `TRUE` on top of the stack comes from `OP_EQUAL`.

Now the redeem script runs and you drop the top three elements from the stack and then add `PubKey`, leaving you with `PubKey, Data1, Sig`. When `OP_CHECKSIG` runs now it uses `Data1` as Signature instead of `Sig` which makes it fail. At the end the stack is `FALSE, Sig`. The top element of the stack is `FALSE` which makes the transaction fail.

> **Comments:**
> **username_0**: Thank you for your answer. Based on this, if I change `OP_DROP` on `OP_2DROP` this should resolve my problem but not.  
> **username_1**: Did you make a completly new transaction? Because if you change `OP_DROP` to `OP_2DROP` the hash of the redeem script will be different and thus `OP_EQUAL` will return `FALSE` if you reuse your old `scriptPubKey` with the updated redeem script.  
> **username_0**: Yes, I updated it, but after I read your comment =). Also, I updated the post with new raw transaction.  
> **username_0**: I found one more mistake in my raw transaction. There was `OP_PUSHDATA<PubKey>` together with `OP_CHECKSIG`. You helped to resolve my issue but I have new. When I'm sending that raw I get error `mandatory-script-verify-flag-failed (Signature is found in scriptCode)`. Maybe you know what's wrong?  
> **username_1**: Sorry I also don't know what that means :( I suggest you make a new question with the new problem, maybe someone else knows whats wrong.  

---

