ethereum.gray_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 | if evm.env.number <= block_number or evm.env.number > max_block_number: |
42 | # Default hash to 0, if the block of interest is not yet on the chain |
43 | # (including the block which has the current executing transaction), |
44 | # or if the block's age is more than 256. |
45 | hash = b"\x00" |
46 | else: |
47 | hash = evm.env.block_hashes[-(evm.env.number - block_number)] |
48 | |
49 | push(evm.stack, U256.from_be_bytes(hash)) |
50 | |
51 | # PROGRAM COUNTER |
52 | 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:
56 | """ |
---|---|
57 | Push the current block's beneficiary address (address of the block miner) |
58 | onto the stack. |
59 |
|
60 | Here the current block refers to the block in which the currently |
61 | executing transaction/call resides. |
62 |
|
63 | Parameters |
64 | ---------- |
65 | evm : |
66 | The current EVM frame. |
67 |
|
68 | """ |
69 | # STACK |
70 | pass |
71 | |
72 | # GAS |
73 | charge_gas(evm, GAS_BASE) |
74 | |
75 | # OPERATION |
76 | push(evm.stack, U256.from_be_bytes(evm.env.coinbase)) |
77 | |
78 | # PROGRAM COUNTER |
79 | 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:
83 | """ |
---|---|
84 | Push the current block's timestamp onto the stack. Here the timestamp |
85 | being referred is actually the unix timestamp in seconds. |
86 |
|
87 | Here the current block refers to the block in which the currently |
88 | executing transaction/call resides. |
89 |
|
90 | Parameters |
91 | ---------- |
92 | evm : |
93 | The current EVM frame. |
94 |
|
95 | """ |
96 | # STACK |
97 | pass |
98 | |
99 | # GAS |
100 | charge_gas(evm, GAS_BASE) |
101 | |
102 | # OPERATION |
103 | push(evm.stack, evm.env.time) |
104 | |
105 | # PROGRAM COUNTER |
106 | 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:
110 | """ |
---|---|
111 | Push the current block's number onto the stack. |
112 |
|
113 | Here the current block refers to the block in which the currently |
114 | executing transaction/call resides. |
115 |
|
116 | Parameters |
117 | ---------- |
118 | evm : |
119 | The current EVM frame. |
120 |
|
121 | """ |
122 | # STACK |
123 | pass |
124 | |
125 | # GAS |
126 | charge_gas(evm, GAS_BASE) |
127 | |
128 | # OPERATION |
129 | push(evm.stack, U256(evm.env.number)) |
130 | |
131 | # PROGRAM COUNTER |
132 | 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:
136 | """ |
---|---|
137 | Push the current block's difficulty 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 | """ |
148 | # STACK |
149 | pass |
150 | |
151 | # GAS |
152 | charge_gas(evm, GAS_BASE) |
153 | |
154 | # OPERATION |
155 | push(evm.stack, U256(evm.env.difficulty)) |
156 | |
157 | # PROGRAM COUNTER |
158 | 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:
162 | """ |
---|---|
163 | Push the current block's gas limit onto the stack. |
164 |
|
165 | Here the current block refers to the block in which the currently |
166 | executing transaction/call resides. |
167 |
|
168 | Parameters |
169 | ---------- |
170 | evm : |
171 | The current EVM frame. |
172 |
|
173 | """ |
174 | # STACK |
175 | pass |
176 | |
177 | # GAS |
178 | charge_gas(evm, GAS_BASE) |
179 | |
180 | # OPERATION |
181 | push(evm.stack, U256(evm.env.gas_limit)) |
182 | |
183 | # PROGRAM COUNTER |
184 | 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:
188 | """ |
---|---|
189 | Push the chain id onto the stack. |
190 |
|
191 | Parameters |
192 | ---------- |
193 | evm : |
194 | The current EVM frame. |
195 |
|
196 | """ |
197 | # STACK |
198 | pass |
199 | |
200 | # GAS |
201 | charge_gas(evm, GAS_BASE) |
202 | |
203 | # OPERATION |
204 | push(evm.stack, U256(evm.env.chain_id)) |
205 | |
206 | # PROGRAM COUNTER |
207 | evm.pc += Uint(1) |