8

I've been playing with raw transactions and signed transaction and I've noticed that the error "Mandatory script verify flag failed" comes in two variations.

  1. script failed on OP_EQUALVERIFY OP
  2. Script evaluated without error but finished with a false/empty top stack element.

Now, it appears that error number one is given whenever I try to send a transaction with the wrong TXID or index number. The second error can appear when I provide the wrong signature.

But aren't both errors just variant of a failure in executing the OP_EQUALVERIFY? At what step of the evaluation each error is thrown and what can we make out of it?

I'll highly appreciate any pointer you might have. I really struggle here to differentiate the two.

meshcollider
  • 11,695
  • 4
  • 24
  • 52
shultz
  • 181
  • 1
  • 4

2 Answers2

6

But aren't both errors just variant of a failure in executing the OP_EQUALVERIFY? At what step of the evaluation each error is thrown and what can we make out of it?

No, they're different errors. There are two rules that must be satisifed here:

  1. The hash of the public key must match a certain value. (A failure here means you have the wrong key, or no key.)
  2. The signature must be valid for the message and public key. (OP_CHECKSIG does not error immediately. It returns 0, which causes the script to fail.)

There are other script errors, too. See this list: https://github.com/bitcoin/bitcoin/blob/master/src/script/script_error.cpp

Nick ODell
  • 29,184
  • 11
  • 69
  • 129
3

I was facing the same issue while I was creating a raw transaction. I got the message: mandatory-script-verify-flag-failed

(Script failed an OP_EQUALVERIFY operation)

I figure out that the issue behind is that I am signing with an erroneous key which wasn't related to the UTXO. I had to backup the key tied to the UTXO address using dumpprivkey and sign with it.

meshcollider
  • 11,695
  • 4
  • 24
  • 52
Badr Bellaj
  • 1,131
  • 10
  • 17