ethereum.forks.prague.vm.instructions.block

Ethereum Virtual Machine (EVM) Block Instructions.

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

Introduction

Implementations of the EVM block instructions.

block_hash

Push the hash of one of the 256 most recent complete blocks onto the stack. The block number to hash is present at the top of the stack.

Parameters

evm : The current EVM frame.

Raises

:py:class:~ethereum.forks.prague.vm.exceptions.StackUnderflowError If len(stack) is less than 1. :py:class:~ethereum.forks.prague.vm.exceptions.OutOfGasError If evm.gas_left is less than 20.

def block_hash(evm: Evm) -> None:
22
    """
23
    Push the hash of one of the 256 most recent complete blocks onto the
24
    stack. The block number to hash is present at the top of the stack.
25
26
    Parameters
27
    ----------
28
    evm :
29
        The current EVM frame.
30
31
    Raises
32
    ------
33
    :py:class:`~ethereum.forks.prague.vm.exceptions.StackUnderflowError`
34
        If `len(stack)` is less than `1`.
35
    :py:class:`~ethereum.forks.prague.vm.exceptions.OutOfGasError`
36
        If `evm.gas_left` is less than `20`.
37
38
    """
39
    # STACK
40
    block_number = Uint(pop(evm.stack))
41
42
    # GAS
43
    charge_gas(evm, GAS_BLOCK_HASH)
44
45
    # OPERATION
46
    max_block_number = block_number + Uint(256)
47
    current_block_number = evm.message.block_env.number
48
    if (
49
        current_block_number <= block_number
50
        or current_block_number > max_block_number
51
    ):
52
        # Default hash to 0, if the block of interest is not yet on the chain
53
        # (including the block which has the current executing transaction),
54
        # or if the block's age is more than 256.
55
        current_block_hash = b"\x00"
56
    else:
57
        current_block_hash = evm.message.block_env.block_hashes[
58
            -(current_block_number - block_number)
59
        ]
60
61
    push(evm.stack, U256.from_be_bytes(current_block_hash))
62
63
    # PROGRAM COUNTER
64
    evm.pc += Uint(1)

coinbase

Push the current block's beneficiary address (address of the block miner) onto the stack.

Here the current block refers to the block in which the currently executing transaction/call resides.

Parameters

evm : The current EVM frame.

Raises

:py:class:~ethereum.forks.prague.vm.exceptions.StackOverflowError If len(stack) is equal to 1024. :py:class:~ethereum.forks.prague.vm.exceptions.OutOfGasError If evm.gas_left is less than 2.

def coinbase(evm: Evm) -> None:
68
    """
69
    Push the current block's beneficiary address (address of the block miner)
70
    onto the stack.
71
72
    Here the current block refers to the block in which the currently
73
    executing transaction/call resides.
74
75
    Parameters
76
    ----------
77
    evm :
78
        The current EVM frame.
79
80
    Raises
81
    ------
82
    :py:class:`~ethereum.forks.prague.vm.exceptions.StackOverflowError`
83
        If `len(stack)` is equal to `1024`.
84
    :py:class:`~ethereum.forks.prague.vm.exceptions.OutOfGasError`
85
        If `evm.gas_left` is less than `2`.
86
87
    """
88
    # STACK
89
    pass
90
91
    # GAS
92
    charge_gas(evm, GAS_BASE)
93
94
    # OPERATION
95
    push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase))
96
97
    # PROGRAM COUNTER
98
    evm.pc += Uint(1)

timestamp

Push the current block's timestamp onto the stack. Here the timestamp being referred is actually the unix timestamp in seconds.

Here the current block refers to the block in which the currently executing transaction/call resides.

Parameters

evm : The current EVM frame.

Raises

:py:class:~ethereum.forks.prague.vm.exceptions.StackOverflowError If len(stack) is equal to 1024. :py:class:~ethereum.forks.prague.vm.exceptions.OutOfGasError If evm.gas_left is less than 2.

def timestamp(evm: Evm) -> None:
102
    """
103
    Push the current block's timestamp onto the stack. Here the timestamp
104
    being referred is actually the unix timestamp in seconds.
105
106
    Here the current block refers to the block in which the currently
107
    executing transaction/call resides.
108
109
    Parameters
110
    ----------
111
    evm :
112
        The current EVM frame.
113
114
    Raises
115
    ------
116
    :py:class:`~ethereum.forks.prague.vm.exceptions.StackOverflowError`
117
        If `len(stack)` is equal to `1024`.
118
    :py:class:`~ethereum.forks.prague.vm.exceptions.OutOfGasError`
119
        If `evm.gas_left` is less than `2`.
120
121
    """
122
    # STACK
123
    pass
124
125
    # GAS
126
    charge_gas(evm, GAS_BASE)
127
128
    # OPERATION
129
    push(evm.stack, evm.message.block_env.time)
130
131
    # PROGRAM COUNTER
132
    evm.pc += Uint(1)

number

Push the current block's number onto the stack.

Here the current block refers to the block in which the currently executing transaction/call resides.

Parameters

evm : The current EVM frame.

Raises

:py:class:~ethereum.forks.prague.vm.exceptions.StackOverflowError If len(stack) is equal to 1024. :py:class:~ethereum.forks.prague.vm.exceptions.OutOfGasError If evm.gas_left is less than 2.

def number(evm: Evm) -> None:
136
    """
137
    Push the current block's number onto the stack.
138
139
    Here the current block refers to the block in which the currently
140
    executing transaction/call resides.
141
142
    Parameters
143
    ----------
144
    evm :
145
        The current EVM frame.
146
147
    Raises
148
    ------
149
    :py:class:`~ethereum.forks.prague.vm.exceptions.StackOverflowError`
150
        If `len(stack)` is equal to `1024`.
151
    :py:class:`~ethereum.forks.prague.vm.exceptions.OutOfGasError`
152
        If `evm.gas_left` is less than `2`.
153
154
    """
155
    # STACK
156
    pass
157
158
    # GAS
159
    charge_gas(evm, GAS_BASE)
160
161
    # OPERATION
162
    push(evm.stack, U256(evm.message.block_env.number))
163
164
    # PROGRAM COUNTER
165
    evm.pc += Uint(1)

prev_randao

Push the prev_randao value onto the stack.

The prev_randao value is the random output of the beacon chain's randomness oracle for the previous block.

Parameters

evm : The current EVM frame.

Raises

:py:class:~ethereum.forks.prague.vm.exceptions.StackOverflowError If len(stack) is equal to 1024. :py:class:~ethereum.forks.prague.vm.exceptions.OutOfGasError If evm.gas_left is less than 2.

def prev_randao(evm: Evm) -> None:
169
    """
170
    Push the `prev_randao` value onto the stack.
171
172
    The `prev_randao` value is the random output of the beacon chain's
173
    randomness oracle for the previous block.
174
175
    Parameters
176
    ----------
177
    evm :
178
        The current EVM frame.
179
180
    Raises
181
    ------
182
    :py:class:`~ethereum.forks.prague.vm.exceptions.StackOverflowError`
183
        If `len(stack)` is equal to `1024`.
184
    :py:class:`~ethereum.forks.prague.vm.exceptions.OutOfGasError`
185
        If `evm.gas_left` is less than `2`.
186
187
    """
188
    # STACK
189
    pass
190
191
    # GAS
192
    charge_gas(evm, GAS_BASE)
193
194
    # OPERATION
195
    push(evm.stack, U256.from_be_bytes(evm.message.block_env.prev_randao))
196
197
    # PROGRAM COUNTER
198
    evm.pc += Uint(1)

gas_limit

Push the current block's gas limit onto the stack.

Here the current block refers to the block in which the currently executing transaction/call resides.

Parameters

evm : The current EVM frame.

Raises

:py:class:~ethereum.forks.prague.vm.exceptions.StackOverflowError If len(stack) is equal to 1024. :py:class:~ethereum.forks.prague.vm.exceptions.OutOfGasError If evm.gas_left is less than 2.

def gas_limit(evm: Evm) -> None:
202
    """
203
    Push the current block's gas limit onto the stack.
204
205
    Here the current block refers to the block in which the currently
206
    executing transaction/call resides.
207
208
    Parameters
209
    ----------
210
    evm :
211
        The current EVM frame.
212
213
    Raises
214
    ------
215
    :py:class:`~ethereum.forks.prague.vm.exceptions.StackOverflowError`
216
        If `len(stack)` is equal to `1024`.
217
    :py:class:`~ethereum.forks.prague.vm.exceptions.OutOfGasError`
218
        If `evm.gas_left` is less than `2`.
219
220
    """
221
    # STACK
222
    pass
223
224
    # GAS
225
    charge_gas(evm, GAS_BASE)
226
227
    # OPERATION
228
    push(evm.stack, U256(evm.message.block_env.block_gas_limit))
229
230
    # PROGRAM COUNTER
231
    evm.pc += Uint(1)

chain_id

Push the chain id onto the stack.

Parameters

evm : The current EVM frame.

Raises

:py:class:~ethereum.forks.prague.vm.exceptions.StackOverflowError If len(stack) is equal to 1024. :py:class:~ethereum.forks.prague.vm.exceptions.OutOfGasError If evm.gas_left is less than 2.

def chain_id(evm: Evm) -> None:
235
    """
236
    Push the chain id onto the stack.
237
238
    Parameters
239
    ----------
240
    evm :
241
        The current EVM frame.
242
243
    Raises
244
    ------
245
    :py:class:`~ethereum.forks.prague.vm.exceptions.StackOverflowError`
246
        If `len(stack)` is equal to `1024`.
247
    :py:class:`~ethereum.forks.prague.vm.exceptions.OutOfGasError`
248
        If `evm.gas_left` is less than `2`.
249
250
    """
251
    # STACK
252
    pass
253
254
    # GAS
255
    charge_gas(evm, GAS_BASE)
256
257
    # OPERATION
258
    push(evm.stack, U256(evm.message.block_env.chain_id))
259
260
    # PROGRAM COUNTER
261
    evm.pc += Uint(1)