ethereum.forks.osaka.vm.instructions.blockethereum.forks.bpo1.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.forks.osaka.vm.exceptions.StackUnderflowError~ethereum.forks.bpo1.vm.exceptions.StackUnderflowErrorlen(stack) is less than 1.
:py:class:
If ~ethereum.forks.osaka.vm.exceptions.OutOfGasError~ethereum.forks.bpo1.vm.exceptions.OutOfGasErrorevm.gas_left is less than 20.
def block_hash(evm: Evm) -> None:
| 22 | <snip> |
|---|---|
| 39 | # STACK |
| 40 | block_number = Uint(pop(evm.stack)) |
| 41 | |
| 42 | # GAS |
| 43 | charge_gas(evm, GasCosts.OPCODE_BLOCKHASH) |
| 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 | current_block_hash = b"\x00" |
| 56 | else: |
| 57 | current_block_hash = evm.message.block_env.block_hashes[ |
| 58 | -(current_block_number - block_number) |
| 59 | ] |
| 60 | |
| 61 | push(evm.stack, U256.from_be_bytes(current_block_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:
If ~ethereum.forks.osaka.vm.exceptions.StackOverflowError~ethereum.forks.bpo1.vm.exceptions.StackOverflowErrorlen(stack) is equal to 1024.
:py:class:
If ~ethereum.forks.osaka.vm.exceptions.OutOfGasError~ethereum.forks.bpo1.vm.exceptions.OutOfGasErrorevm.gas_left is less than 2.
timestamp ¶
Push the current block's timestamp onto the stack. Here the timestamp being referred to 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.forks.osaka.vm.exceptions.StackOverflowError~ethereum.forks.bpo1.vm.exceptions.StackOverflowErrorlen(stack) is equal to 1024.
:py:class:
If ~ethereum.forks.osaka.vm.exceptions.OutOfGasError~ethereum.forks.bpo1.vm.exceptions.OutOfGasErrorevm.gas_left is less than 2.
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.forks.osaka.vm.exceptions.StackOverflowError~ethereum.forks.bpo1.vm.exceptions.StackOverflowErrorlen(stack) is equal to 1024.
:py:class:
If ~ethereum.forks.osaka.vm.exceptions.OutOfGasError~ethereum.forks.bpo1.vm.exceptions.OutOfGasErrorevm.gas_left is less than 2.
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.forks.osaka.vm.exceptions.StackOverflowError~ethereum.forks.bpo1.vm.exceptions.StackOverflowErrorlen(stack) is equal to 1024.
:py:class:
If ~ethereum.forks.osaka.vm.exceptions.OutOfGasError~ethereum.forks.bpo1.vm.exceptions.OutOfGasErrorevm.gas_left is less than 2.
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.forks.osaka.vm.exceptions.StackOverflowError~ethereum.forks.bpo1.vm.exceptions.StackOverflowErrorlen(stack) is equal to 1024.
:py:class:
If ~ethereum.forks.osaka.vm.exceptions.OutOfGasError~ethereum.forks.bpo1.vm.exceptions.OutOfGasErrorevm.gas_left is less than 2.
chain_id ¶
Push the chain id onto the stack.
Parameters
evm : The current EVM frame.
Raises
:py:class:
If ~ethereum.forks.osaka.vm.exceptions.StackOverflowError~ethereum.forks.bpo1.vm.exceptions.StackOverflowErrorlen(stack) is equal to 1024.
:py:class:
If ~ethereum.forks.osaka.vm.exceptions.OutOfGasError~ethereum.forks.bpo1.vm.exceptions.OutOfGasErrorevm.gas_left is less than 2.