ethereum.forks.bpo2.vm.instructions.control_flowethereum.forks.bpo3.vm.instructions.control_flow

Ethereum Virtual Machine (EVM) Control Flow Instructions.

.. contents:: Table of Contents :backlinks: none :local:

Introduction

Implementations of the EVM control flow instructions.

stop

Stop further execution of EVM code.

Parameters

evm : The current EVM frame.

def stop(evm: Evm) -> None:
23
    <snip>
32
    # STACK
33
    pass
34
35
    # GAS
36
    pass
37
38
    # OPERATION
39
    evm.running = False
40
41
    # PROGRAM COUNTER
42
    evm.pc += Uint(1)

jump

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:
46
    <snip>
56
    # STACK
57
    jump_dest = Uint(pop(evm.stack))
58
59
    # GAS
60
    charge_gas(evm, GasCosts.OPCODE_JUMP)
61
62
    # OPERATION
63
    if jump_dest not in evm.valid_jump_destinations:
64
        raise InvalidJumpDestError
65
66
    # PROGRAM COUNTER
67
    evm.pc = Uint(jump_dest)

jumpi

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:
71
    <snip>
82
    # STACK
83
    jump_dest = Uint(pop(evm.stack))
84
    conditional_value = pop(evm.stack)
85
86
    # GAS
87
    charge_gas(evm, GasCosts.OPCODE_JUMPI)
88
89
    # OPERATION
90
    if conditional_value == 0:
91
        destination = evm.pc + Uint(1)
92
    elif jump_dest not in evm.valid_jump_destinations:
93
        raise InvalidJumpDestError
94
    else:
95
        destination = jump_dest
96
97
    # PROGRAM COUNTER
98
    evm.pc = destination

pc

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:
102
    <snip>
112
    # STACK
113
    pass
114
115
    # GAS
116
    charge_gas(evm, GasCosts.OPCODE_PC)
117
118
    # OPERATION
119
    push(evm.stack, U256(evm.pc))
120
121
    # PROGRAM COUNTER
122
    evm.pc += Uint(1)

gas_left

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:
126
    <snip>
136
    # STACK
137
    pass
138
139
    # GAS
140
    charge_gas(evm, GasCosts.OPCODE_GAS)
141
142
    # OPERATION
143
    push(evm.stack, U256(evm.gas_left))
144
145
    # PROGRAM COUNTER
146
    evm.pc += Uint(1)

jumpdest

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:
150
    <snip>
161
    # STACK
162
    pass
163
164
    # GAS
165
    charge_gas(evm, GasCosts.OPCODE_JUMPDEST)
166
167
    # OPERATION
168
    pass
169
170
    # PROGRAM COUNTER
171
    evm.pc += Uint(1)