Ethereum Virtual Machine (EVM) Comparison Instructions

Introduction

Implementations of the EVM Comparison instructions.

Module Contents

Functions

less_than

Checks if the top element is less than the next top element. Pushes the

signed_less_than

Signed less-than comparison.

greater_than

Checks if the top element is greater than the next top element. Pushes

signed_greater_than

Signed greater-than comparison.

equal

Checks if the top element is equal to the next top element. Pushes

is_zero

Checks if the top element is equal to 0. Pushes the result back on the

Module Details

less_than

less_than(evm: ethereum.byzantium.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.byzantium.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.byzantium.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.byzantium.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.byzantium.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.byzantium.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