Skip to content

Commit 48bbf59

Browse files
Add OP_LESSTHAN page
1 parent 8307e2e commit 48bbf59

2 files changed

Lines changed: 77 additions & 4 deletions

File tree

.vitepress/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ export default {
172172
{ text: "<code>156 | OP_NUMEQUAL</code>", link: "/opcodes/OP_NUMEQUAL.md" },
173173
{ text: "<code>157 | OP_NUMEQUALVERIFY</code>", link: "/opcodes/OP_NUMEQUALVERIFY.md" },
174174
{ text: "<code>158 | OP_NUMNOTEQUAL</code>", link: "/opcodes/OP_NUMNOTEQUAL.md" },
175-
{ text: "<code>159 | 🚧 OP_LESSTHAN</code>", link: "/opcodes/OP_LESSTHAN.md" },
175+
{ text: "<code>159 | OP_LESSTHAN</code>", link: "/opcodes/OP_LESSTHAN.md" },
176176
{ text: "<code>160 | 🚧 OP_GREATERTHAN</code>", link: "/opcodes/OP_GREATERTHAN.md" },
177177
{ text: "<code>161 | 🚧 OP_LESSTHANOREQUAL</code>", link: "/opcodes/OP_LESSTHANOREQUAL.md" },
178178
{ text: "<code>162 | 🚧 OP_GREATERTHANOREQUAL</code>", link: "/opcodes/OP_GREATERTHANOREQUAL.md" },

opcodes/OP_LESSTHAN.md

Lines changed: 76 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,78 @@
1-
# Work In Progress
1+
# OP_LESSTHAN
22

3-
:::warning
4-
This page has not yet been written. If you have experience with bitcoin Script and would like to contribute, please do! You can open a PR [on the repository for this website](https://github.com/thunderbiscuit/opcode-explained).
3+
:::info
4+
**Opcode number:** 159
5+
**Byte representation:** `0x9f`
6+
**Short description:** Pop the top two items; push 1 if the second is less than the top, 0 otherwise.
57
:::
8+
9+
`OP_LESSTHAN` compares the top two items on the stack as integers. If the second item is less than the top item, it pushes `1` (`true`) onto the stack. If not, it pushes an empty array (`false`). Both items are removed from the stack after the comparison.
10+
11+
### Operation
12+
13+
1. Take the top item (`a`) and the second item (`b`) from the stack.
14+
2. Compare the two items:
15+
- If `b < a`, push `1` (`true`) onto the stack.
16+
- Otherwise, push an empty array (`false`) onto the stack.
17+
3. Remove the original items (`a` and `b`) from the stack.
18+
19+
### Notes
20+
21+
- Both items must be valid integers. Bitcoin Script interprets byte arrays up to **4 bytes** as integers.
22+
- An empty array (`[]`) is treated as `0` when compared.
23+
- If there are fewer than two items on the stack when `OP_LESSTHAN` is executed, the script will fail.
24+
25+
---
26+
27+
## Examples
28+
29+
### Example 1: Second item is less than the top item
30+
31+
```shell
32+
# ASM script
33+
OP_2 OP_3 OP_LESSTHAN
34+
35+
# Raw script
36+
52539f
37+
38+
# Stack (before OP_LESSTHAN)
39+
3 # top
40+
2
41+
42+
# Stack (after OP_LESSTHAN)
43+
1 # true, as 2 < 3
44+
```
45+
46+
### Example 2: Second item is greater than the top item
47+
48+
```shell
49+
# ASM script
50+
OP_3 OP_2 OP_LESSTHAN
51+
52+
# Raw script
53+
53529f
54+
55+
# Stack (before OP_LESSTHAN)
56+
2 # top
57+
3
58+
59+
# Stack (after OP_LESSTHAN)
60+
[] # false, as 3 is not less than 2
61+
```
62+
63+
### Example 3: Comparing two zeros
64+
65+
```shell
66+
# ASM script
67+
OP_0 OP_0 OP_LESSTHAN
68+
69+
# Raw script
70+
00009f
71+
72+
# Stack (before OP_LESSTHAN)
73+
[] # top
74+
[]
75+
76+
# Stack (after OP_LESSTHAN)
77+
[] # false, as 0 is not less than 0
78+
```

0 commit comments

Comments
 (0)