ethereum.tangerine_whistle.vm.instructions.comparisonethereum.spurious_dragon.vm.instructions.comparison
Ethereum Virtual Machine (EVM) Comparison Instructions ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. contents:: Table of Contents :backlinks: none :local:
Introduction
Implementations of the EVM Comparison instructions.
less_than
Checks if the top element is less than the next top element. Pushes the result back on the stack.
Parameters
evm : The current EVM frame.
def less_than(evm: Evm) -> None:
23 | """ |
---|---|
24 | Checks if the top element is less than the next top element. Pushes the |
25 | result back on the stack. |
26 |
|
27 | Parameters |
28 | ---------- |
29 | evm : |
30 | The current EVM frame. |
31 |
|
32 | """ |
33 | # STACK |
34 | left = pop(evm.stack) |
35 | right = pop(evm.stack) |
36 | |
37 | # GAS |
38 | charge_gas(evm, GAS_VERY_LOW) |
39 | |
40 | # OPERATION |
41 | result = U256(left < right) |
42 | |
43 | push(evm.stack, result) |
44 | |
45 | # PROGRAM COUNTER |
46 | evm.pc += Uint(1) |
signed_less_than
Signed less-than comparison.
Parameters
evm : The current EVM frame.
def signed_less_than(evm: Evm) -> None:
50 | """ |
---|---|
51 | Signed less-than comparison. |
52 |
|
53 | Parameters |
54 | ---------- |
55 | evm : |
56 | The current EVM frame. |
57 |
|
58 | """ |
59 | # STACK |
60 | left = pop(evm.stack).to_signed() |
61 | right = pop(evm.stack).to_signed() |
62 | |
63 | # GAS |
64 | charge_gas(evm, GAS_VERY_LOW) |
65 | |
66 | # OPERATION |
67 | result = U256(left < right) |
68 | |
69 | push(evm.stack, result) |
70 | |
71 | # PROGRAM COUNTER |
72 | evm.pc += Uint(1) |
greater_than
Checks if the top element is greater than the next top element. Pushes the result back on the stack.
Parameters
evm : The current EVM frame.
def greater_than(evm: Evm) -> None:
76 | """ |
---|---|
77 | Checks if the top element is greater than the next top element. Pushes |
78 | the result back on the stack. |
79 |
|
80 | Parameters |
81 | ---------- |
82 | evm : |
83 | The current EVM frame. |
84 |
|
85 | """ |
86 | # STACK |
87 | left = pop(evm.stack) |
88 | right = pop(evm.stack) |
89 | |
90 | # GAS |
91 | charge_gas(evm, GAS_VERY_LOW) |
92 | |
93 | # OPERATION |
94 | result = U256(left > right) |
95 | |
96 | push(evm.stack, result) |
97 | |
98 | # PROGRAM COUNTER |
99 | evm.pc += Uint(1) |
signed_greater_than
Signed greater-than comparison.
Parameters
evm : The current EVM frame.
def signed_greater_than(evm: Evm) -> None:
103 | """ |
---|---|
104 | Signed greater-than comparison. |
105 |
|
106 | Parameters |
107 | ---------- |
108 | evm : |
109 | The current EVM frame. |
110 |
|
111 | """ |
112 | # STACK |
113 | left = pop(evm.stack).to_signed() |
114 | right = pop(evm.stack).to_signed() |
115 | |
116 | # GAS |
117 | charge_gas(evm, GAS_VERY_LOW) |
118 | |
119 | # OPERATION |
120 | result = U256(left > right) |
121 | |
122 | push(evm.stack, result) |
123 | |
124 | # PROGRAM COUNTER |
125 | evm.pc += Uint(1) |
equal
Checks if the top element is equal to the next top element. Pushes the result back on the stack.
Parameters
evm : The current EVM frame.
def equal(evm: Evm) -> None:
129 | """ |
---|---|
130 | Checks if the top element is equal to the next top element. Pushes |
131 | the result back on the stack. |
132 |
|
133 | Parameters |
134 | ---------- |
135 | evm : |
136 | The current EVM frame. |
137 |
|
138 | """ |
139 | # STACK |
140 | left = pop(evm.stack) |
141 | right = pop(evm.stack) |
142 | |
143 | # GAS |
144 | charge_gas(evm, GAS_VERY_LOW) |
145 | |
146 | # OPERATION |
147 | result = U256(left == right) |
148 | |
149 | push(evm.stack, result) |
150 | |
151 | # PROGRAM COUNTER |
152 | evm.pc += Uint(1) |
is_zero
Checks if the top element is equal to 0. Pushes the result back on the stack.
Parameters
evm : The current EVM frame.
def is_zero(evm: Evm) -> None:
156 | """ |
---|---|
157 | Checks if the top element is equal to 0. Pushes the result back on the |
158 | stack. |
159 |
|
160 | Parameters |
161 | ---------- |
162 | evm : |
163 | The current EVM frame. |
164 |
|
165 | """ |
166 | # STACK |
167 | x = pop(evm.stack) |
168 | |
169 | # GAS |
170 | charge_gas(evm, GAS_VERY_LOW) |
171 | |
172 | # OPERATION |
173 | result = U256(x == 0) |
174 | |
175 | push(evm.stack, result) |
176 | |
177 | # PROGRAM COUNTER |
178 | evm.pc += Uint(1) |