OP_NUMEQUALVERIFY - Equality Test with Fail
10. OP_NUMEQUALVERIFY — Equality Test with Fail
Opcode Reference
Opcode: OP_NUMEQUALVERIFY
Hex: 0x9D
Decimal: 157
Input: a b
Output: (nothing, but fails script if a != b)
Overview
OP_NUMEQUALVERIFY combines OP_NUMEQUAL and OP_VERIFY in a single opcode. It checks that two numeric values are equal and immediately fails the script if they are not. No result is left on the stack — it either passes silently or terminates execution with failure.
Behavior
If a == b: Script continues, stack is unchanged (both a and b are consumed)
If a != b: Script fails immediately (SCRIPT_ERR_NUMEQUALVERIFY)
Bitcoin Core Implementation
case OP_NUMEQUALVERIFY:
{
if (stack.size() < 2)
return set_error(serror, SCRIPT_ERR_INVALID_STACK_OPERATION);
CScriptNum bn1(stacktop(-2), fRequireMinimal);
CScriptNum bn2(stacktop(-1), fRequireMinimal);
popstack(stack);
popstack(stack);
if (bn1 != bn2)
return set_error(serror, SCRIPT_ERR_NUMEQUALVERIFY);
}
break;
Comparison: OP_NUMEQUAL vs OP_NUMEQUALVERIFY
Using OP_NUMEQUAL:
Stack result: [1] or [0]
You need OP_VERIFY after to fail on mismatch
Two opcodes required
Using OP_NUMEQUALVERIFY:
No stack result: silent pass or immediate fail
One opcode handles both steps
More compact scripts
Use Cases
OP_NUMEQUALVERIFY is ideal as an intermediate assertion in longer scripts where you need to verify an equality condition and then continue with more operations:
Script: <a> <b> OP_ADD <expected_sum> OP_NUMEQUALVERIFY <more_checks...>
This pattern is especially common in P2SH and Tapscript-based contracts with multiple conditions.
TeachMeBitcoin is an ad-free, open-source educational repository curated by a passionate team of Bitcoin researchers and educators for public benefit. If you found our articles helpful, please consider supporting our hosting and ongoing content updates with a clean donation: