ethereum.forks.prague.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:
25
    """
26
    Checks if the top element is less than the next top element. Pushes the
27
    result back on the stack.
28
29
    Parameters
30
    ----------
31
    evm :
32
        The current EVM frame.
33
34
    """
35
    # STACK
36
    left = pop(evm.stack)
37
    right = pop(evm.stack)
38
39
    # GAS
40
    charge_gas(evm, GasCosts.OPCODE_LT)
41
42
    # OPERATION
43
    result = U256(left < right)
44
45
    push(evm.stack, result)
46
47
    # PROGRAM COUNTER
48
    evm.pc += Uint(1)

signed_less_than

Signed less-than comparison.

Parameters

evm : The current EVM frame.

def signed_less_than(evm: Evm) -> None:
52
    """
53
    Signed less-than comparison.
54
55
    Parameters
56
    ----------
57
    evm :
58
        The current EVM frame.
59
60
    """
61
    # STACK
62
    left = pop(evm.stack).to_signed()
63
    right = pop(evm.stack).to_signed()
64
65
    # GAS
66
    charge_gas(evm, GasCosts.OPCODE_SLT)
67
68
    # OPERATION
69
    result = U256(left < right)
70
71
    push(evm.stack, result)
72
73
    # PROGRAM COUNTER
74
    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:
78
    """
79
    Checks if the top element is greater than the next top element. Pushes
80
    the result back on the stack.
81
82
    Parameters
83
    ----------
84
    evm :
85
        The current EVM frame.
86
87
    """
88
    # STACK
89
    left = pop(evm.stack)
90
    right = pop(evm.stack)
91
92
    # GAS
93
    charge_gas(evm, GasCosts.OPCODE_GT)
94
95
    # OPERATION
96
    result = U256(left > right)
97
98
    push(evm.stack, result)
99
100
    # PROGRAM COUNTER
101
    evm.pc += Uint(1)

signed_greater_than

Signed greater-than comparison.

Parameters

evm : The current EVM frame.

def signed_greater_than(evm: Evm) -> None:
105
    """
106
    Signed greater-than comparison.
107
108
    Parameters
109
    ----------
110
    evm :
111
        The current EVM frame.
112
113
    """
114
    # STACK
115
    left = pop(evm.stack).to_signed()
116
    right = pop(evm.stack).to_signed()
117
118
    # GAS
119
    charge_gas(evm, GasCosts.OPCODE_SGT)
120
121
    # OPERATION
122
    result = U256(left > right)
123
124
    push(evm.stack, result)
125
126
    # PROGRAM COUNTER
127
    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:
131
    """
132
    Checks if the top element is equal to the next top element. Pushes
133
    the result back on the stack.
134
135
    Parameters
136
    ----------
137
    evm :
138
        The current EVM frame.
139
140
    """
141
    # STACK
142
    left = pop(evm.stack)
143
    right = pop(evm.stack)
144
145
    # GAS
146
    charge_gas(evm, GasCosts.OPCODE_EQ)
147
148
    # OPERATION
149
    result = U256(left == right)
150
151
    push(evm.stack, result)
152
153
    # PROGRAM COUNTER
154
    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:
158
    """
159
    Checks if the top element is equal to 0. Pushes the result back on the
160
    stack.
161
162
    Parameters
163
    ----------
164
    evm :
165
        The current EVM frame.
166
167
    """
168
    # STACK
169
    x = pop(evm.stack)
170
171
    # GAS
172
    charge_gas(evm, GasCosts.OPCODE_ISZERO)
173
174
    # OPERATION
175
    result = U256(x == 0)
176
177
    push(evm.stack, result)
178
179
    # PROGRAM COUNTER
180
    evm.pc += Uint(1)