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 = pop(evm.stack)
35
36
    # GAS
37
    charge_gas(evm, GAS_BLOCK_HASH)
38
39
    # OPERATION
40
    if evm.env.number <= block_number or evm.env.number > block_number + 256:
41
        # Default hash to 0, if the block of interest is not yet on the chain
42
        # (including the block which has the current executing transaction),
43
        # or if the block's age is more than 256.
44
        hash = b"\x00"
45
    else:
46
        hash = evm.env.block_hashes[-(evm.env.number - block_number)]
47
48
    push(evm.stack, U256.from_be_bytes(hash))
49
50
    # PROGRAM COUNTER
51
    evm.pc += 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:
55
    """
56
    Push the current block's beneficiary address (address of the block miner)
57
    onto the stack.
58
59
    Here the current block refers to the block in which the currently
60
    executing transaction/call resides.
61
62
    Parameters
63
    ----------
64
    evm :
65
        The current EVM frame.
66
67
    """
68
    # STACK
69
    pass
70
71
    # GAS
72
    charge_gas(evm, GAS_BASE)
73
74
    # OPERATION
75
    push(evm.stack, U256.from_be_bytes(evm.env.coinbase))
76
77
    # PROGRAM COUNTER
78
    evm.pc += 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:
82
    """
83
    Push the current block's timestamp onto the stack. Here the timestamp
84
    being referred is actually the unix timestamp in seconds.
85
86
    Here the current block refers to the block in which the currently
87
    executing transaction/call resides.
88
89
    Parameters
90
    ----------
91
    evm :
92
        The current EVM frame.
93
94
    """
95
    # STACK
96
    pass
97
98
    # GAS
99
    charge_gas(evm, GAS_BASE)
100
101
    # OPERATION
102
    push(evm.stack, evm.env.time)
103
104
    # PROGRAM COUNTER
105
    evm.pc += 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:
109
    """
110
    Push the current block's number onto the stack.
111
112
    Here the current block refers to the block in which the currently
113
    executing transaction/call resides.
114
115
    Parameters
116
    ----------
117
    evm :
118
        The current EVM frame.
119
120
    """
121
    # STACK
122
    pass
123
124
    # GAS
125
    charge_gas(evm, GAS_BASE)
126
127
    # OPERATION
128
    push(evm.stack, U256(evm.env.number))
129
130
    # PROGRAM COUNTER
131
    evm.pc += 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:
135
    """
136
    Push the current block's difficulty onto the stack.
137
138
    Here the current block refers to the block in which the currently
139
    executing transaction/call resides.
140
141
    Parameters
142
    ----------
143
    evm :
144
        The current EVM frame.
145
146
    """
147
    # STACK
148
    pass
149
150
    # GAS
151
    charge_gas(evm, GAS_BASE)
152
153
    # OPERATION
154
    push(evm.stack, U256(evm.env.difficulty))
155
156
    # PROGRAM COUNTER
157
    evm.pc += 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:
161
    """
162
    Push the current block's gas limit onto the stack.
163
164
    Here the current block refers to the block in which the currently
165
    executing transaction/call resides.
166
167
    Parameters
168
    ----------
169
    evm :
170
        The current EVM frame.
171
172
    """
173
    # STACK
174
    pass
175
176
    # GAS
177
    charge_gas(evm, GAS_BASE)
178
179
    # OPERATION
180
    push(evm.stack, U256(evm.env.gas_limit))
181
182
    # PROGRAM COUNTER
183
    evm.pc += 1

chain_id

Push the chain id onto the stack.

Parameters

evm : The current EVM frame.

def chain_id(evm: Evm) -> None:
187
    """
188
    Push the chain id onto the stack.
189
190
    Parameters
191
    ----------
192
    evm :
193
        The current EVM frame.
194
195
    """
196
    # STACK
197
    pass
198
199
    # GAS
200
    charge_gas(evm, GAS_BASE)
201
202
    # OPERATION
203
    push(evm.stack, U256(evm.env.chain_id))
204
205
    # PROGRAM COUNTER
206
    evm.pc += 1