ethereum.paris.vm.instructions.blockethereum.shanghai.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:
If ~ethereum.paris.vm.exceptions.StackUnderflowError~ethereum.shanghai.vm.exceptions.StackUnderflowErrorlen(stack)
is less than 1
.
:py:class:
If ~ethereum.paris.vm.exceptions.OutOfGasError~ethereum.shanghai.vm.exceptions.OutOfGasErrorevm.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` |
34 | :py:class:`~ethereum.shanghai.vm.exceptions.StackUnderflowError` |
35 | If `len(stack)` is less than `1`. |
36 | :py:class:`~ethereum.paris.vm.exceptions.OutOfGasError` |
36 | :py:class:`~ethereum.shanghai.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 | if evm.env.number <= block_number or evm.env.number > max_block_number: |
48 | # Default hash to 0, if the block of interest is not yet on the chain |
49 | # (including the block which has the current executing transaction), |
50 | # or if the block's age is more than 256. |
51 | hash = b"\x00" |
52 | else: |
53 | hash = evm.env.block_hashes[-(evm.env.number - block_number)] |
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.
Raises
:py:class:
If ~ethereum.paris.vm.exceptions.StackOverflowError~ethereum.shanghai.vm.exceptions.StackOverflowErrorlen(stack)
is equal to 1024
.
:py:class:
If ~ethereum.paris.vm.exceptions.OutOfGasError~ethereum.shanghai.vm.exceptions.OutOfGasErrorevm.gas_left
is less than 2
.
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 | Raises |
75 | ------ |
76 | :py:class:`~ethereum.paris.vm.exceptions.StackOverflowError` |
76 | :py:class:`~ethereum.shanghai.vm.exceptions.StackOverflowError` |
77 | If `len(stack)` is equal to `1024`. |
78 | :py:class:`~ethereum.paris.vm.exceptions.OutOfGasError` |
78 | :py:class:`~ethereum.shanghai.vm.exceptions.OutOfGasError` |
79 | If `evm.gas_left` is less than `2`. |
80 | """ |
81 | # STACK |
82 | pass |
83 | |
84 | # GAS |
85 | charge_gas(evm, GAS_BASE) |
86 | |
87 | # OPERATION |
88 | push(evm.stack, U256.from_be_bytes(evm.env.coinbase)) |
89 | |
90 | # PROGRAM COUNTER |
91 | 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:
If ~ethereum.paris.vm.exceptions.StackOverflowError~ethereum.shanghai.vm.exceptions.StackOverflowErrorlen(stack)
is equal to 1024
.
:py:class:
If ~ethereum.paris.vm.exceptions.OutOfGasError~ethereum.shanghai.vm.exceptions.OutOfGasErrorevm.gas_left
is less than 2
.
def timestamp(evm: Evm) -> None:
95 | """ |
---|---|
96 | Push the current block's timestamp onto the stack. Here the timestamp |
97 | being referred is actually the unix timestamp in seconds. |
98 |
|
99 | Here the current block refers to the block in which the currently |
100 | executing transaction/call resides. |
101 |
|
102 | Parameters |
103 | ---------- |
104 | evm : |
105 | The current EVM frame. |
106 |
|
107 | Raises |
108 | ------ |
109 | :py:class:`~ethereum.paris.vm.exceptions.StackOverflowError` |
109 | :py:class:`~ethereum.shanghai.vm.exceptions.StackOverflowError` |
110 | If `len(stack)` is equal to `1024`. |
111 | :py:class:`~ethereum.paris.vm.exceptions.OutOfGasError` |
111 | :py:class:`~ethereum.shanghai.vm.exceptions.OutOfGasError` |
112 | If `evm.gas_left` is less than `2`. |
113 | """ |
114 | # STACK |
115 | pass |
116 | |
117 | # GAS |
118 | charge_gas(evm, GAS_BASE) |
119 | |
120 | # OPERATION |
121 | push(evm.stack, evm.env.time) |
122 | |
123 | # PROGRAM COUNTER |
124 | 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:
If ~ethereum.paris.vm.exceptions.StackOverflowError~ethereum.shanghai.vm.exceptions.StackOverflowErrorlen(stack)
is equal to 1024
.
:py:class:
If ~ethereum.paris.vm.exceptions.OutOfGasError~ethereum.shanghai.vm.exceptions.OutOfGasErrorevm.gas_left
is less than 2
.
def number(evm: Evm) -> None:
128 | """ |
---|---|
129 | Push the current block's number onto the stack. |
130 |
|
131 | Here the current block refers to the block in which the currently |
132 | executing transaction/call resides. |
133 |
|
134 | Parameters |
135 | ---------- |
136 | evm : |
137 | The current EVM frame. |
138 |
|
139 | Raises |
140 | ------ |
141 | :py:class:`~ethereum.paris.vm.exceptions.StackOverflowError` |
141 | :py:class:`~ethereum.shanghai.vm.exceptions.StackOverflowError` |
142 | If `len(stack)` is equal to `1024`. |
143 | :py:class:`~ethereum.paris.vm.exceptions.OutOfGasError` |
143 | :py:class:`~ethereum.shanghai.vm.exceptions.OutOfGasError` |
144 | If `evm.gas_left` is less than `2`. |
145 | """ |
146 | # STACK |
147 | pass |
148 | |
149 | # GAS |
150 | charge_gas(evm, GAS_BASE) |
151 | |
152 | # OPERATION |
153 | push(evm.stack, U256(evm.env.number)) |
154 | |
155 | # PROGRAM COUNTER |
156 | 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:
If ~ethereum.paris.vm.exceptions.StackOverflowError~ethereum.shanghai.vm.exceptions.StackOverflowErrorlen(stack)
is equal to 1024
.
:py:class:
If ~ethereum.paris.vm.exceptions.OutOfGasError~ethereum.shanghai.vm.exceptions.OutOfGasErrorevm.gas_left
is less than 2
.
def prev_randao(evm: Evm) -> None:
160 | """ |
---|---|
161 | Push the `prev_randao` value onto the stack. |
162 |
|
163 | The `prev_randao` value is the random output of the beacon chain's |
164 | randomness oracle for the previous block. |
165 |
|
166 | Parameters |
167 | ---------- |
168 | evm : |
169 | The current EVM frame. |
170 |
|
171 | Raises |
172 | ------ |
173 | :py:class:`~ethereum.paris.vm.exceptions.StackOverflowError` |
173 | :py:class:`~ethereum.shanghai.vm.exceptions.StackOverflowError` |
174 | If `len(stack)` is equal to `1024`. |
175 | :py:class:`~ethereum.paris.vm.exceptions.OutOfGasError` |
175 | :py:class:`~ethereum.shanghai.vm.exceptions.OutOfGasError` |
176 | If `evm.gas_left` is less than `2`. |
177 | """ |
178 | # STACK |
179 | pass |
180 | |
181 | # GAS |
182 | charge_gas(evm, GAS_BASE) |
183 | |
184 | # OPERATION |
185 | push(evm.stack, U256.from_be_bytes(evm.env.prev_randao)) |
186 | |
187 | # PROGRAM COUNTER |
188 | 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:
If ~ethereum.paris.vm.exceptions.StackOverflowError~ethereum.shanghai.vm.exceptions.StackOverflowErrorlen(stack)
is equal to 1024
.
:py:class:
If ~ethereum.paris.vm.exceptions.OutOfGasError~ethereum.shanghai.vm.exceptions.OutOfGasErrorevm.gas_left
is less than 2
.
def gas_limit(evm: Evm) -> None:
192 | """ |
---|---|
193 | Push the current block's gas limit onto the stack. |
194 |
|
195 | Here the current block refers to the block in which the currently |
196 | executing transaction/call resides. |
197 |
|
198 | Parameters |
199 | ---------- |
200 | evm : |
201 | The current EVM frame. |
202 |
|
203 | Raises |
204 | ------ |
205 | :py:class:`~ethereum.paris.vm.exceptions.StackOverflowError` |
205 | :py:class:`~ethereum.shanghai.vm.exceptions.StackOverflowError` |
206 | If `len(stack)` is equal to `1024`. |
207 | :py:class:`~ethereum.paris.vm.exceptions.OutOfGasError` |
207 | :py:class:`~ethereum.shanghai.vm.exceptions.OutOfGasError` |
208 | If `evm.gas_left` is less than `2`. |
209 | """ |
210 | # STACK |
211 | pass |
212 | |
213 | # GAS |
214 | charge_gas(evm, GAS_BASE) |
215 | |
216 | # OPERATION |
217 | push(evm.stack, U256(evm.env.gas_limit)) |
218 | |
219 | # PROGRAM COUNTER |
220 | evm.pc += Uint(1) |
chain_id
Push the chain id onto the stack.
Parameters
evm : The current EVM frame.
Raises
:py:class:
If ~ethereum.paris.vm.exceptions.StackOverflowError~ethereum.shanghai.vm.exceptions.StackOverflowErrorlen(stack)
is equal to 1024
.
:py:class:
If ~ethereum.paris.vm.exceptions.OutOfGasError~ethereum.shanghai.vm.exceptions.OutOfGasErrorevm.gas_left
is less than 2
.
def chain_id(evm: Evm) -> None:
224 | """ |
---|---|
225 | Push the chain id onto the stack. |
226 |
|
227 | Parameters |
228 | ---------- |
229 | evm : |
230 | The current EVM frame. |
231 |
|
232 | Raises |
233 | ------ |
234 | :py:class:`~ethereum.paris.vm.exceptions.StackOverflowError` |
234 | :py:class:`~ethereum.shanghai.vm.exceptions.StackOverflowError` |
235 | If `len(stack)` is equal to `1024`. |
236 | :py:class:`~ethereum.paris.vm.exceptions.OutOfGasError` |
236 | :py:class:`~ethereum.shanghai.vm.exceptions.OutOfGasError` |
237 | If `evm.gas_left` is less than `2`. |
238 | """ |
239 | # STACK |
240 | pass |
241 | |
242 | # GAS |
243 | charge_gas(evm, GAS_BASE) |
244 | |
245 | # OPERATION |
246 | push(evm.stack, U256(evm.env.chain_id)) |
247 | |
248 | # PROGRAM COUNTER |
249 | evm.pc += Uint(1) |