ethereum.forks.dao_fork.vm.instructions.control_flowethereum.forks.tangerine_whistle.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:
26
    <snip>
35
    # STACK
36
    pass
37
38
    # GAS
39
    pass
40
41
    # OPERATION
42
    evm.running = False
43
44
    # PROGRAM COUNTER
45
    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:
49
    <snip>
59
    # STACK
60
    jump_dest = Uint(pop(evm.stack))
61
62
    # GAS
63
    charge_gas(evm, GasCosts.OPCODE_JUMP)
64
65
    # OPERATION
66
    if jump_dest not in evm.valid_jump_destinations:
67
        raise InvalidJumpDestError
68
69
    # PROGRAM COUNTER
70
    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:
74
    <snip>
85
    # STACK
86
    jump_dest = Uint(pop(evm.stack))
87
    conditional_value = pop(evm.stack)
88
89
    # GAS
90
    charge_gas(evm, GasCosts.OPCODE_JUMPI)
91
92
    # OPERATION
93
    if conditional_value == 0:
94
        destination = evm.pc + Uint(1)
95
    elif jump_dest not in evm.valid_jump_destinations:
96
        raise InvalidJumpDestError
97
    else:
98
        destination = jump_dest
99
100
    # PROGRAM COUNTER
101
    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:
105
    <snip>
115
    # STACK
116
    pass
117
118
    # GAS
119
    charge_gas(evm, GasCosts.OPCODE_PC)
120
121
    # OPERATION
122
    push(evm.stack, U256(evm.pc))
123
124
    # PROGRAM COUNTER
125
    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:
129
    <snip>
139
    # STACK
140
    pass
141
142
    # GAS
143
    charge_gas(evm, GasCosts.OPCODE_GAS)
144
145
    # OPERATION
146
    push(evm.stack, U256(evm.gas_left))
147
148
    # PROGRAM COUNTER
149
    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:
153
    <snip>
164
    # STACK
165
    pass
166
167
    # GAS
168
    charge_gas(evm, GasCosts.OPCODE_JUMPDEST)
169
170
    # OPERATION
171
    pass
172
173
    # PROGRAM COUNTER
174
    evm.pc += Uint(1)