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