ethereum.london.vm.instructions.blockethereum.arrow_glacier.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.

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
    """
33
    # STACK
34
    block_number = Uint(pop(evm.stack))
35
36
    # GAS
37
    charge_gas(evm, GAS_BLOCK_HASH)
38
39
    # OPERATION
40
    max_block_number = block_number + Uint(256)
41
    current_block_number = evm.message.block_env.number
42
    if (
43
        current_block_number <= block_number
44
        or current_block_number > max_block_number
45
    ):
46
        # Default hash to 0, if the block of interest is not yet on the chain
47
        # (including the block which has the current executing transaction),
48
        # or if the block's age is more than 256.
49
        hash = b"\x00"
50
    else:
51
        hash = evm.message.block_env.block_hashes[
52
            -(current_block_number - block_number)
53
        ]
54
55
    push(evm.stack, U256.from_be_bytes(hash))
56
57
    # PROGRAM COUNTER
58
    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.

def coinbase(evm: Evm) -> None:
62
    """
63
    Push the current block's beneficiary address (address of the block miner)
64
    onto the stack.
65
66
    Here the current block refers to the block in which the currently
67
    executing transaction/call resides.
68
69
    Parameters
70
    ----------
71
    evm :
72
        The current EVM frame.
73
74
    """
75
    # STACK
76
    pass
77
78
    # GAS
79
    charge_gas(evm, GAS_BASE)
80
81
    # OPERATION
82
    push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase))
83
84
    # PROGRAM COUNTER
85
    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.

def timestamp(evm: Evm) -> None:
89
    """
90
    Push the current block's timestamp onto the stack. Here the timestamp
91
    being referred is actually the unix timestamp in seconds.
92
93
    Here the current block refers to the block in which the currently
94
    executing transaction/call resides.
95
96
    Parameters
97
    ----------
98
    evm :
99
        The current EVM frame.
100
101
    """
102
    # STACK
103
    pass
104
105
    # GAS
106
    charge_gas(evm, GAS_BASE)
107
108
    # OPERATION
109
    push(evm.stack, evm.message.block_env.time)
110
111
    # PROGRAM COUNTER
112
    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.

def number(evm: Evm) -> None:
116
    """
117
    Push the current block's number onto the stack.
118
119
    Here the current block refers to the block in which the currently
120
    executing transaction/call resides.
121
122
    Parameters
123
    ----------
124
    evm :
125
        The current EVM frame.
126
127
    """
128
    # STACK
129
    pass
130
131
    # GAS
132
    charge_gas(evm, GAS_BASE)
133
134
    # OPERATION
135
    push(evm.stack, U256(evm.message.block_env.number))
136
137
    # PROGRAM COUNTER
138
    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)

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.

def gas_limit(evm: Evm) -> None:
168
    """
169
    Push the current block's gas limit onto the stack.
170
171
    Here the current block refers to the block in which the currently
172
    executing transaction/call resides.
173
174
    Parameters
175
    ----------
176
    evm :
177
        The current EVM frame.
178
179
    """
180
    # STACK
181
    pass
182
183
    # GAS
184
    charge_gas(evm, GAS_BASE)
185
186
    # OPERATION
187
    push(evm.stack, U256(evm.message.block_env.block_gas_limit))
188
189
    # PROGRAM COUNTER
190
    evm.pc += Uint(1)

chain_id

Push the chain id onto the stack.

Parameters

evm : The current EVM frame.

def chain_id(evm: Evm) -> None:
194
    """
195
    Push the chain id onto the stack.
196
197
    Parameters
198
    ----------
199
    evm :
200
        The current EVM frame.
201
202
    """
203
    # STACK
204
    pass
205
206
    # GAS
207
    charge_gas(evm, GAS_BASE)
208
209
    # OPERATION
210
    push(evm.stack, U256(evm.message.block_env.chain_id))
211
212
    # PROGRAM COUNTER
213
    evm.pc += Uint(1)