OP_LESSTHAN - Less Than Comparison
12. OP_LESSTHAN — Less Than Comparison
Opcode Reference
Opcode: OP_LESSTHAN
Hex: 0x9F
Decimal: 159
Input: a b
Output: 1 if a < b, else 0
Overview
OP_LESSTHAN pops two elements and returns 1 if the second-from-top (a) is strictly less than the top element (b). Remember the ordering: a was pushed first, b was pushed second (and sits on top).
Stack Examples
Stack (top→bottom): [b=10, a=5, ...]
OP_LESSTHAN: Is 5 < 10? Yes → [1]
Stack: [b=5, a=10, ...]
OP_LESSTHAN: Is 10 < 5? No → [0]
Stack: [b=5, a=5, ...]
OP_LESSTHAN: Is 5 < 5? No → [0] (strict less-than)
Bitcoin Core Implementation
case OP_LESSTHAN:
{
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_LESSTHAN is commonly used to enforce upper bounds on values in the unlocking script:
Script: <user_value> <max_allowed> OP_LESSTHAN OP_VERIFY
Meaning: user_value must be < max_allowed
In the context of Lightning Network or other off-chain protocols, similar patterns enforce that a submitted timeout or sequence is within an acceptable window.
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: