OP_NUMNOTEQUAL - Numeric Inequality Test
From TeachMeBitcoin, the free encyclopedia
Reading time: 1 min
11. OP_NUMNOTEQUAL — Numeric Inequality Test
Opcode Reference
Opcode: OP_NUMNOTEQUAL
Hex: 0x9E
Decimal: 158
Input: a b
Output: 1 if a != b, else 0
Overview
OP_NUMNOTEQUAL is the inverse of OP_NUMEQUAL. It pushes 1 if the two top stack elements represent different integers, and 0 if they are equal.
Stack Examples
Input: [5, 5] → OP_NUMNOTEQUAL → [0]
Input: [5, 6] → OP_NUMNOTEQUAL → [1]
Input: [-3, 3] → OP_NUMNOTEQUAL → [1]
Input: [0, 0] → OP_NUMNOTEQUAL → [0]
Bitcoin Core Implementation
case OP_NUMNOTEQUAL:
{
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);
stack.push_back((bn1 != bn2) ? vchTrue : vchFalse);
}
break;
Use Cases
OP_NUMNOTEQUAL is used when you want to enforce that two values must differ. For example, in a script enforcing that a submitted nonce is different from a previously used value (if that prior value is embedded in the locking script):
Locking script: <used_nonce> OP_NUMNOTEQUAL OP_VERIFY
Unlocking script: <new_nonce>
☕ Help support TeachMeBitcoin
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:
Ethereum:
0x578417C51783663D8A6A811B3544E1f779D39A85
Bitcoin:
bc1q77k9e95rn669kpzyjr8ke9w95zhk7pa5s63qzz
Solana:
4ycT2ayqeMucixj3wS8Ay8Tq9NRDYRPKYbj3UGESyQ4J