ethereum.constantinople.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:
24
    """
25
    Stop further execution of EVM code.
26
27
    Parameters
28
    ----------
29
    evm :
30
        The current EVM frame.
31
    """
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
    """
47
    Alter the program counter to the location specified by the top of the
48
    stack.
49
50
    Parameters
51
    ----------
52
    evm :
53
        The current EVM frame.
54
55
    """
56
    # STACK
57
    jump_dest = Uint(pop(evm.stack))
58
59
    # GAS
60
    charge_gas(evm, GAS_MID)
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
    """
72
    Alter the program counter to the specified location if and only if a
73
    condition is true. If the condition is not true, then the program counter
74
    would increase only by 1.
75
76
    Parameters
77
    ----------
78
    evm :
79
        The current EVM frame.
80
81
    """
82
    # STACK
83
    jump_dest = Uint(pop(evm.stack))
84
    conditional_value = pop(evm.stack)
85
86
    # GAS
87
    charge_gas(evm, GAS_HIGH)
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
    """
103
    Push onto the stack the value of the program counter after reaching the
104
    current instruction and without increasing it for the next instruction.
105
106
    Parameters
107
    ----------
108
    evm :
109
        The current EVM frame.
110
111
    """
112
    # STACK
113
    pass
114
115
    # GAS
116
    charge_gas(evm, GAS_BASE)
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
    """
127
    Push the amount of available gas (including the corresponding reduction
128
    for the cost of this instruction) onto the stack.
129
130
    Parameters
131
    ----------
132
    evm :
133
        The current EVM frame.
134
135
    """
136
    # STACK
137
    pass
138
139
    # GAS
140
    charge_gas(evm, GAS_BASE)
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
    """
151
    Mark a valid destination for jumps. This is a noop, present only
152
    to be used by `JUMP` and `JUMPI` opcodes to verify that their jump is
153
    valid.
154
155
    Parameters
156
    ----------
157
    evm :
158
        The current EVM frame.
159
160
    """
161
    # STACK
162
    pass
163
164
    # GAS
165
    charge_gas(evm, GAS_JUMPDEST)
166
167
    # OPERATION
168
    pass
169
170
    # PROGRAM COUNTER
171
    evm.pc += Uint(1)