ethereum.forks.paris.vm.instructions.comparisonethereum.forks.shanghai.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
    <snip>
32
    # STACK
33
    left = pop(evm.stack)
34
    right = pop(evm.stack)
35
36
    # GAS
37
    charge_gas(evm, GasCosts.OPCODE_LT)
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
    <snip>
58
    # STACK
59
    left = pop(evm.stack).to_signed()
60
    right = pop(evm.stack).to_signed()
61
62
    # GAS
63
    charge_gas(evm, GasCosts.OPCODE_SLT)
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
    <snip>
85
    # STACK
86
    left = pop(evm.stack)
87
    right = pop(evm.stack)
88
89
    # GAS
90
    charge_gas(evm, GasCosts.OPCODE_GT)
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
    <snip>
111
    # STACK
112
    left = pop(evm.stack).to_signed()
113
    right = pop(evm.stack).to_signed()
114
115
    # GAS
116
    charge_gas(evm, GasCosts.OPCODE_SGT)
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
    <snip>
138
    # STACK
139
    left = pop(evm.stack)
140
    right = pop(evm.stack)
141
142
    # GAS
143
    charge_gas(evm, GasCosts.OPCODE_EQ)
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
    <snip>
165
    # STACK
166
    x = pop(evm.stack)
167
168
    # GAS
169
    charge_gas(evm, GasCosts.OPCODE_ISZERO)
170
171
    # OPERATION
172
    result = U256(x == 0)
173
174
    push(evm.stack, result)
175
176
    # PROGRAM COUNTER
177
    evm.pc += Uint(1)