ethereum.gray_glacier.vm.instructions.blockethereum.paris.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.paris.vm.exceptions.StackUnderflowError If len(stack) is less than 1. :py:class:~ethereum.paris.vm.exceptions.OutOfGasError If evm.gas_left is less than 20.

def block_hash(evm: Evm) -> None:
23
    """
24
    Push the hash of one of the 256 most recent complete blocks onto the
25
    stack. The block number to hash is present at the top of the stack.
26
27
    Parameters
28
    ----------
29
    evm :
30
        The current EVM frame.
31
32
    Raises
33
    ------
34
    :py:class:`~ethereum.paris.vm.exceptions.StackUnderflowError`
35
        If `len(stack)` is less than `1`.
36
    :py:class:`~ethereum.paris.vm.exceptions.OutOfGasError`
37
        If `evm.gas_left` is less than `20`.
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
        hash = b"\x00"
56
    else:
57
        hash = evm.message.block_env.block_hashes[
58
            -(current_block_number - block_number)
59
        ]
60
61
    push(evm.stack, U256.from_be_bytes(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.paris.vm.exceptions.StackOverflowError If len(stack) is equal to 1024. :py:class:~ethereum.paris.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.paris.vm.exceptions.StackOverflowError`
83
        If `len(stack)` is equal to `1024`.
84
    :py:class:`~ethereum.paris.vm.exceptions.OutOfGasError`
85
        If `evm.gas_left` is less than `2`.
86
    """
87
    # STACK
88
    pass
89
90
    # GAS
91
    charge_gas(evm, GAS_BASE)
92
93
    # OPERATION
94
    push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase))
95
96
    # PROGRAM COUNTER
97
    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.paris.vm.exceptions.StackOverflowError If len(stack) is equal to 1024. :py:class:~ethereum.paris.vm.exceptions.OutOfGasError If evm.gas_left is less than 2.

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

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

difficulty

Push the current block's difficulty 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.

def difficulty(evm: Evm) -> None:
142
    """
143
    Push the current block's difficulty onto the stack.
144
145
    Here the current block refers to the block in which the currently
146
    executing transaction/call resides.
147
148
    Parameters
149
    ----------
150
    evm :
151
        The current EVM frame.
152
153
    """
154
    # STACK
155
    pass
156
157
    # GAS
158
    charge_gas(evm, GAS_BASE)
159
160
    # OPERATION
161
    push(evm.stack, U256(evm.message.block_env.difficulty))
162
163
    # PROGRAM COUNTER
164
    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.paris.vm.exceptions.StackOverflowError If len(stack) is equal to 1024. :py:class:~ethereum.paris.vm.exceptions.OutOfGasError If evm.gas_left is less than 2.

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

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

chain_id

Push the chain id onto the stack.

Parameters

evm : The current EVM frame.

Raises

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

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