Skip to content

Commit a8f715c

Browse files
Add OP_GREATERTHAN page
1 parent 4df8321 commit a8f715c

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
@@ -173,7 +173,7 @@ export default {
173173
{ text: "<code>157 | OP_NUMEQUALVERIFY</code>", link: "/opcodes/OP_NUMEQUALVERIFY.md" },
174174
{ text: "<code>158 | OP_NUMNOTEQUAL</code>", link: "/opcodes/OP_NUMNOTEQUAL.md" },
175175
{ text: "<code>159 | OP_LESSTHAN</code>", link: "/opcodes/OP_LESSTHAN.md" },
176-
{ text: "<code>160 | 🚧 OP_GREATERTHAN</code>", link: "/opcodes/OP_GREATERTHAN.md" },
176+
{ 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" },
179179
{ text: "<code>163 | 🚧 OP_MIN</code>", link: "/opcodes/OP_MIN.md" },

opcodes/OP_GREATERTHAN.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_GREATERTHAN
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:** 160
5+
**Byte representation:** `0xa0`
6+
**Short description:** Pop the top two items; push 1 if the second is greater than the top, 0 otherwise.
57
:::
8+
9+
`OP_GREATERTHAN` compares the top two items on the stack as integers. If the second item is greater 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 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_GREATERTHAN` is executed, the script will fail.
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_GREATERTHAN
32+
33+
# Raw script
34+
5352a0
35+
36+
# Stack (before OP_GREATERTHAN)
37+
2 # top
38+
3
39+
40+
# Stack (after OP_GREATERTHAN)
41+
1 # true, as 3 > 2
42+
```
43+
44+
### Example 2: Comparing two zeros
45+
46+
```shell
47+
# ASM script
48+
OP_PUSHBYTES_1 00 OP_0 OP_GREATERTHAN
49+
50+
# Raw script
51+
0100009f
52+
53+
# Stack (before OP_GREATERTHAN)
54+
[] # top (zero)
55+
0 # second (zero)
56+
57+
# Stack (after OP_GREATERTHAN)
58+
[] # false
59+
```

0 commit comments

Comments
 (0)