Ethereum Virtual Machine (EVM) Control Flow Instructions

Introduction

Implementations of the EVM control flow instructions.

Module Contents

Functions

stop

Stop further execution of EVM code.

jump

Alter the program counter to the location specified by the top of the

jumpi

Alter the program counter to the specified location if and only if a

pc

Push onto the stack the value of the program counter after reaching the

gas_left

Push the amount of available gas (including the corresponding reduction

jumpdest

Mark a valid destination for jumps. This is a noop, present only

Module Details

stop

stop(evm: ethereum.muir_glacier.vm.Evm)None

Stop further execution of EVM code.

Parameters

evm – The current EVM frame.

def stop(evm: Evm) -> None:
    # STACK
    pass

    # GAS
    pass

    # OPERATION
    evm.running = False

    # PROGRAM COUNTER
    evm.pc += 1

jump

jump(evm: ethereum.muir_glacier.vm.Evm)None

Alter the program counter to the location specified by the top of the stack.

Parameters

evm – The current EVM frame.

def jump(evm: Evm) -> None:
    # STACK
    jump_dest = Uint(pop(evm.stack))

    # GAS
    charge_gas(evm, GAS_MID)

    # OPERATION
    if jump_dest not in evm.valid_jump_destinations:
        raise InvalidJumpDestError

    # PROGRAM COUNTER
    evm.pc = Uint(jump_dest)

jumpi

jumpi(evm: ethereum.muir_glacier.vm.Evm)None

Alter the program counter to the specified location if and only if a condition is true. If the condition is not true, then the program counter would increase only by 1.

Parameters

evm – The current EVM frame.

def jumpi(evm: Evm) -> None:
    # STACK
    jump_dest = Uint(pop(evm.stack))
    conditional_value = pop(evm.stack)

    # GAS
    charge_gas(evm, GAS_HIGH)

    # OPERATION
    if conditional_value == 0:
        destination = evm.pc + 1
    elif jump_dest not in evm.valid_jump_destinations:
        raise InvalidJumpDestError
    else:
        destination = jump_dest

    # PROGRAM COUNTER
    evm.pc = Uint(destination)

pc

pc(evm: ethereum.muir_glacier.vm.Evm)None

Push onto the stack the value of the program counter after reaching the current instruction and without increasing it for the next instruction.

Parameters

evm – The current EVM frame.

def pc(evm: Evm) -> None:
    # STACK
    pass

    # GAS
    charge_gas(evm, GAS_BASE)

    # OPERATION
    push(evm.stack, U256(evm.pc))

    # PROGRAM COUNTER
    evm.pc += 1

gas_left

gas_left(evm: ethereum.muir_glacier.vm.Evm)None

Push the amount of available gas (including the corresponding reduction for the cost of this instruction) onto the stack.

Parameters

evm – The current EVM frame.

def gas_left(evm: Evm) -> None:
    # STACK
    pass

    # GAS
    charge_gas(evm, GAS_BASE)

    # OPERATION
    push(evm.stack, U256(evm.gas_left))

    # PROGRAM COUNTER
    evm.pc += 1

jumpdest

jumpdest(evm: ethereum.muir_glacier.vm.Evm)None

Mark a valid destination for jumps. This is a noop, present only to be used by JUMP and JUMPI opcodes to verify that their jump is valid.

Parameters

evm – The current EVM frame.

def jumpdest(evm: Evm) -> None:
    # STACK
    pass

    # GAS
    charge_gas(evm, GAS_JUMPDEST)

    # OPERATION
    pass

    # PROGRAM COUNTER
    evm.pc += 1