<p>After a while of debugging, I was able to find the issue. </p>

<p>My previous assumption that I was committing the wrong data to the hash was correct. </p>

<p>The transaction ID that is needed to construct <code>hashPrevouts</code> and <code>outpoint</code> was incorrect. I needed to reverse the bytes of this value for the hash to be correct.</p>

<p>For example:</p>

<ul>
<li><code>b9d615615976600739be12a67f326836e4256d7d1c4fe50163536ad8dd7647c3</code> (a searchable <code>txid</code> on Bitcoin testnet)</li>
</ul>

<p>becomes...</p>

<ul>
<li><code>c34776ddd86a536301e54f1c7d6d25e43668327fa612be39076076596115d6b9</code>. </li>
</ul>

<p>In summary, my advice would be to step through the interpreter and reevaluate your assumptions of all the data that you're committing to the hash for signing.</p>

<p>A little bit of code never hurts,</p>

<p><strong>Typescript</strong>: <code>Buffer.from(transactionId, "hex").reverse().toString("hex");</code></p>

CC BY-SA 4.0
2019-04-09T10:01:27.037Z
2019-04-09T10:01:27.037Z
Malone
<p>Using <a href="https://blockstream.info/testnet/tx/push" rel="nofollow noreferrer">Blockstream's api to broadcast a raw transaction</a> to the Bitcoin testnet, I encountered the following error:</p>

<pre><code>sendrawtransaction RPC error: {"code":-26,"message":"non-mandatory-script-verify-flag (Signature must be zero for failed CHECK(MULTI)SIG operation) (code 64)"}
</code></pre>

<p>I've noticed that many people have ran into a similar issue before. However, all of the proposed solutions didn't fix my issue. I've looked at the <a href="https://github.com/bitcoin/bitcoin/blob/78dae8caccd82cfbfd76557f1fb7d7557c7b5edb/src/script/interpreter.cpp#L941" rel="nofollow noreferrer">Bitcoin source code on Github</a> and determined that the data I am committing to my hash for signing is incorrect.</p>

<p>Below is the hash pre-image that I'm creating for bip143 <code>p2sh(p2wpkh)</code>.</p>

<pre><code>    nVersion:     01000000
    hashPrevouts: 4f3c0f6726ec7f020da2a01598d1741225ea429a34bfdd4c4af2a1c9e45a9bed
    hashSequence: 3bb13029ce7b1f559ef5e747fcac439f1455a2ec7c5f09b72290795e70665044
    outpoint:     b9d615615976600739be12a67f326836e4256d7d1c4fe50163536ad8dd7647c301000000
    scriptCode:   1976a91499f27cf1ecb8c1a4c20bdbcdc7992cdb12c9ee5d88ac
    amount:       6981680000000000
    nSequence:    ffffffff
    hashOutputs:  57dbf9cb180c89fe35000b693ea089e521097e6d3f504cfec1620325fcec0036
    nLockTime:    00000000
    nHashType:    01000000
</code></pre>

CC BY-SA 4.0
2019-04-09T12:29:11.003Z
This issue is related only by the error message, not by the solution https://bitcoin.stackexchange.com/questions/61030/got-64-non-mandatory-script-verify-flag-signature-must-be-zero-for-failed-chec?rq=1
Malone
<segregated-witness><bip143>
Failed CHECK(MULTI)SIG operation - BIP143 hash pre-image
Malone
# Failed CHECK(MULTI)SIG operation - BIP143 hash pre-image

(Asked by: username_0 on 2019-04-09)

Using Blockstream's api to broadcast a raw transaction to the Bitcoin testnet, I encountered the following error:
sendrawtransaction RPC error: {"code":-26,"message":"non-mandatory-script-verify-flag (Signature must be zero for failed CHECK(MULTI)SIG operation) (code 64)"}

I've noticed that many people have ran into a similar issue before. However, all of the proposed solutions didn't fix my issue. I've looked at the Bitcoin source code on Github and determined that the data I am committing to my hash for signing is incorrect.
Below is the hash pre-image that I'm creating for bip143 p2sh(p2wpkh).
    nVersion:     01000000
    hashPrevouts: 4f3c0f6726ec7f020da2a01598d1741225ea429a34bfdd4c4af2a1c9e45a9bed
    hashSequence: 3bb13029ce7b1f559ef5e747fcac439f1455a2ec7c5f09b72290795e70665044
    outpoint:     b9d615615976600739be12a67f326836e4256d7d1c4fe50163536ad8dd7647c301000000
    scriptCode:   1976a91499f27cf1ecb8c1a4c20bdbcdc7992cdb12c9ee5d88ac
    amount:       6981680000000000
    nSequence:    ffffffff
    hashOutputs:  57dbf9cb180c89fe35000b693ea089e521097e6d3f504cfec1620325fcec0036
    nLockTime:    00000000
    nHashType:    01000000

**Tags:** segregated-witness, bip143

> **Comments:**
> **username_0**: This issue is related only by the error message, not by the solution https://bitcoin.stackexchange.com/questions/61030/got-64-non-mandatory-script-verify-flag-signature-must-be-zero-for-failed-chec?rq=1  

---

## 1 answers

### Answer by username_0 on 2019-04-09. Score: 1 | Accepted answer

After a while of debugging, I was able to find the issue.

My previous assumption that I was committing the wrong data to the hash was correct.

The transaction ID that is needed to construct `hashPrevouts` and `outpoint` was incorrect. I needed to reverse the bytes of this value for the hash to be correct.

For example:

* `b9d615615976600739be12a67f326836e4256d7d1c4fe50163536ad8dd7647c3` (a searchable `txid` on Bitcoin testnet)

becomes...

* `c34776ddd86a536301e54f1c7d6d25e43668327fa612be39076076596115d6b9`.

In summary, my advice would be to step through the interpreter and reevaluate your assumptions of all the data that you're committing to the hash for signing.

A little bit of code never hurts,

**Typescript**: `Buffer.from(transactionId, "hex").reverse().toString("hex");`


---

