Module 03
Comparison
Equality checks, numeric ordering, and range tests. Most real Bitcoin scripts end with a comparison — the final result on the stack is either true or false, and that determines whether the transaction is valid.
What you'll learn
- →Distinguish OP_EQUAL (bytes) from OP_NUMEQUAL (numbers)
- →Use OP_EQUALVERIFY and OP_NUMEQUALVERIFY to assert equality inline
- →Combine OP_NOT, OP_0NOTEQUAL, OP_BOOLAND, OP_BOOLOR for boolean logic
- →Predict when a comparison leaves 0 vs 1 on the stack
01
Equality
OP_EQUAL compares the top two items byte-for-byte and pushes a boolean 1 (true) or 0 (false). OP_EQUALVERIFY does the same but immediately fails the script on inequality — no result is pushed. You'll see OP_EQUALVERIFY constantly in P2PKH.
OP_EQUALByte-for-byte equality. Leaves 1 if equal, 0 if not.
↑ top of stack
nothing here yet
press Step or Run to push an item
OP_EQUAL (false)5 ≠ 6 → leaves 0.
↑ top of stack
nothing here yet
press Step or Run to push an item
OP_NUMEQUALNumeric equality — interprets both items as CScriptNum. For small integers the result matches OP_EQUAL.
↑ top of stack
nothing here yet
press Step or Run to push an item
OP_EQUAL compares raw bytes; OP_NUMEQUAL decodes both as numbers first. They differ when items have different encodings for the same value.OP_EQUALVERIFY in the wild
OP_EQUALVERIFY OP_CHECKSIG. The VERIFY variant lets the script fail immediately on a mismatch rather than leaving a false value to be checked later.02
Ordering
Four opcodes test the relationship between two numbers. In each case, the second item is compared to the top: think of it as "is the second item [less than / greater than] the top?".
OP_LESSTHANIs 3 < 7? Yes → 1. Stack order: [second, top] = [3, 7].
↑ top of stack
nothing here yet
press Step or Run to push an item
OP_GREATERTHANIs 7 > 3? Yes → 1.
↑ top of stack
nothing here yet
press Step or Run to push an item
OP_LESSTHANOREQUALIs 5 ≤ 5? Yes → 1. Equal counts.
↑ top of stack
nothing here yet
press Step or Run to push an item
OP_GREATERTHANOREQUALIs 4 ≥ 5? No → 0.
↑ top of stack
nothing here yet
press Step or Run to push an item
03
Boolean logic
OP_NOT inverts boolean truthiness: 0 becomes 1, everything else becomes 0. OP_0NOTEQUAL converts any non-zero value to 1 and zero to 0 — useful for normalising comparison results.OP_VERIFY is the assertion that makes these checks binding.
OP_NOTNOT(0) = 1.
↑ top of stack
nothing here yet
press Step or Run to push an item
OP_NOTNOT(non-zero) = 0. Any truthy value collapses to 0.
↑ top of stack
nothing here yet
press Step or Run to push an item
OP_0NOTEQUALNon-zero → 1. Normalises any truthy value to exactly 1.
↑ top of stack
nothing here yet
press Step or Run to push an item
Ctrl+Enter to run
↑ top of stack
nothing here yet
press Step or Run to push an item
04
Your turn
Prove equality
Ctrl+Enter to check