Ethereum Virtual Machine (EVM) Comparison Instructions
Table of Contents
Introduction
Implementations of the EVM Comparison instructions.
Module Contents
Functions
Checks if the top element is less than the next top element. Pushes the |
|
Signed less-than comparison. |
|
Checks if the top element is greater than the next top element. Pushes |
|
Signed greater-than comparison. |
|
Checks if the top element is equal to the next top element. Pushes |
|
Checks if the top element is equal to 0. Pushes the result back on the |
Module Details
less_than
- less_than(evm: ethereum.constantinople.vm.Evm) → None
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:
# STACK
left = pop(evm.stack)
right = pop(evm.stack)
# GAS
charge_gas(evm, GAS_VERY_LOW)
# OPERATION
result = U256(left < right)
push(evm.stack, result)
# PROGRAM COUNTER
evm.pc += 1
signed_less_than
- signed_less_than(evm: ethereum.constantinople.vm.Evm) → None
Signed less-than comparison.
- Parameters
evm – The current EVM frame.
def signed_less_than(evm: Evm) -> None:
# STACK
left = pop(evm.stack).to_signed()
right = pop(evm.stack).to_signed()
# GAS
charge_gas(evm, GAS_VERY_LOW)
# OPERATION
result = U256(left < right)
push(evm.stack, result)
# PROGRAM COUNTER
evm.pc += 1
greater_than
- greater_than(evm: ethereum.constantinople.vm.Evm) → None
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:
# STACK
left = pop(evm.stack)
right = pop(evm.stack)
# GAS
charge_gas(evm, GAS_VERY_LOW)
# OPERATION
result = U256(left > right)
push(evm.stack, result)
# PROGRAM COUNTER
evm.pc += 1
signed_greater_than
- signed_greater_than(evm: ethereum.constantinople.vm.Evm) → None
Signed greater-than comparison.
- Parameters
evm – The current EVM frame.
def signed_greater_than(evm: Evm) -> None:
# STACK
left = pop(evm.stack).to_signed()
right = pop(evm.stack).to_signed()
# GAS
charge_gas(evm, GAS_VERY_LOW)
# OPERATION
result = U256(left > right)
push(evm.stack, result)
# PROGRAM COUNTER
evm.pc += 1
equal
- equal(evm: ethereum.constantinople.vm.Evm) → None
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:
# STACK
left = pop(evm.stack)
right = pop(evm.stack)
# GAS
charge_gas(evm, GAS_VERY_LOW)
# OPERATION
result = U256(left == right)
push(evm.stack, result)
# PROGRAM COUNTER
evm.pc += 1
is_zero
- is_zero(evm: ethereum.constantinople.vm.Evm) → None
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:
# STACK
x = pop(evm.stack)
# GAS
charge_gas(evm, GAS_VERY_LOW)
# OPERATION
result = U256(x == 0)
push(evm.stack, result)
# PROGRAM COUNTER
evm.pc += 1