Skip to content

Commit 39f387e

Browse files
Add OP_GREATERTHANOREQUAL page
1 parent a8f715c commit 39f387e

2 files changed

Lines changed: 58 additions & 4 deletions

File tree

.vitepress/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ export default {
175175
{ 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" },
178-
{ text: "<code>162 | 🚧 OP_GREATERTHANOREQUAL</code>", link: "/opcodes/OP_GREATERTHANOREQUAL.md" },
178+
{ text: "<code>162 | OP_GREATERTHANOREQUAL</code>", link: "/opcodes/OP_GREATERTHANOREQUAL.md" },
179179
{ text: "<code>163 | 🚧 OP_MIN</code>", link: "/opcodes/OP_MIN.md" },
180180
{ text: "<code>164 | 🚧 OP_MAX</code>", link: "/opcodes/OP_MAX.md" },
181181
{ text: "<code>165 | 🚧 OP_WITHIN</code>", link: "/opcodes/OP_WITHIN.md" },

opcodes/OP_GREATERTHANOREQUAL.md

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,59 @@
1-
# Work In Progress
1+
# OP_GREATERTHANOREQUAL
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:** 162
5+
**Byte representation:** `0xa2`
6+
**Short description:** Pop the top two items; push 1 if the second is greater than or equal to the top, 0 otherwise.
57
:::
8+
9+
`OP_GREATERTHANOREQUAL` compares the top two items on the stack as integers. If the second item is greater than or equal to 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+
1. Take the top item (a) and the second item (b) from the stack.
13+
2. Compare the two items:
14+
- If b >= a, push 1 (true) onto the stack.
15+
- Otherwise, push an empty array (false) onto the stack.
16+
3. Remove the original items (a and b) from the stack.
17+
18+
### Notes
19+
20+
- Both items must be valid integers. Bitcoin Script interprets byte arrays up to **4 bytes** as integers.
21+
- An empty array (`[]`) is treated as 0 when compared.
22+
- If there are fewer than two items on the stack when `OP_GREATERTHAN` is executed, the script will fail.
23+
24+
25+
## Examples
26+
27+
### Example 1: Second item is greater than the top item
28+
29+
```shell
30+
# ASM script
31+
OP_3 OP_2 OP_GREATERTHANOREQUAL
32+
33+
# Raw script
34+
5352a1
35+
36+
# Stack (before OP_GREATERTHANOREQUAL)
37+
2 # top
38+
3
39+
40+
# Stack (after OP_GREATERTHANOREQUAL)
41+
1 # true, as 3 >= 2
42+
```
43+
44+
### Example 2: Second item is equal to the top item
45+
46+
```shell
47+
# ASM script
48+
OP_2 OP_2 OP_GREATERTHANOREQUAL
49+
50+
# Raw script
51+
5252a1
52+
53+
# Stack (before OP_GREATERTHANOREQUAL)
54+
2 # top
55+
2
56+
57+
# Stack (after OP_GREATERTHANOREQUAL)
58+
1 # true, as 2 >= 2
59+
```

0 commit comments

Comments
 (0)