ethereum.forks.dao_fork.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
    """
27
    Stop further execution of EVM code.
28
29
    Parameters
30
    ----------
31
    evm :
32
        The current EVM frame.
33
34
    """
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
    """
50
    Alter the program counter to the location specified by the top of the
51
    stack.
52
53
    Parameters
54
    ----------
55
    evm :
56
        The current EVM frame.
57
58
    """
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
    """
75
    Alter the program counter to the specified location if and only if a
76
    condition is true. If the condition is not true, then the program counter
77
    would increase only by 1.
78
79
    Parameters
80
    ----------
81
    evm :
82
        The current EVM frame.
83
84
    """
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
    """
106
    Push onto the stack the value of the program counter after reaching the
107
    current instruction and without increasing it for the next instruction.
108
109
    Parameters
110
    ----------
111
    evm :
112
        The current EVM frame.
113
114
    """
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
    """
130
    Push the amount of available gas (including the corresponding reduction
131
    for the cost of this instruction) onto the stack.
132
133
    Parameters
134
    ----------
135
    evm :
136
        The current EVM frame.
137
138
    """
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
    """
154
    Mark a valid destination for jumps. This is a noop, present only
155
    to be used by `JUMP` and `JUMPI` opcodes to verify that their jump is
156
    valid.
157
158
    Parameters
159
    ----------
160
    evm :
161
        The current EVM frame.
162
163
    """
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)