Ethereum Virtual Machine (EVM) Block Instructions
Table of Contents
Introduction
Implementations of the EVM block instructions.
Module Contents
Functions
Push the hash of one of the 256 most recent complete blocks onto the |
|
Push the current block’s beneficiary address (address of the block miner) |
|
Push the current block’s timestamp onto the stack. Here the timestamp |
|
Push the current block’s number onto the stack. |
|
Push the current block’s difficulty onto the stack. |
|
Push the current block’s gas limit onto the stack. |
|
Push the chain id onto the stack. |
Module Details
block_hash
- block_hash(evm: ethereum.istanbul.vm.Evm) → None
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:
# STACK
block_number = pop(evm.stack)
# GAS
charge_gas(evm, GAS_BLOCK_HASH)
# OPERATION
if evm.env.number <= block_number or evm.env.number > block_number + 256:
# Default hash to 0, if the block of interest is not yet on the chain
# (including the block which has the current executing transaction),
# or if the block's age is more than 256.
hash = b"\x00"
else:
hash = evm.env.block_hashes[-(evm.env.number - block_number)]
push(evm.stack, U256.from_be_bytes(hash))
# PROGRAM COUNTER
evm.pc += 1
coinbase
- coinbase(evm: ethereum.istanbul.vm.Evm) → None
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:
# STACK
pass
# GAS
charge_gas(evm, GAS_BASE)
# OPERATION
push(evm.stack, U256.from_be_bytes(evm.env.coinbase))
# PROGRAM COUNTER
evm.pc += 1
timestamp
- timestamp(evm: ethereum.istanbul.vm.Evm) → None
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:
# STACK
pass
# GAS
charge_gas(evm, GAS_BASE)
# OPERATION
push(evm.stack, evm.env.time)
# PROGRAM COUNTER
evm.pc += 1
number
- number(evm: ethereum.istanbul.vm.Evm) → None
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:
# STACK
pass
# GAS
charge_gas(evm, GAS_BASE)
# OPERATION
push(evm.stack, U256(evm.env.number))
# PROGRAM COUNTER
evm.pc += 1
difficulty
- difficulty(evm: ethereum.istanbul.vm.Evm) → None
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:
# STACK
pass
# GAS
charge_gas(evm, GAS_BASE)
# OPERATION
push(evm.stack, U256(evm.env.difficulty))
# PROGRAM COUNTER
evm.pc += 1
gas_limit
- gas_limit(evm: ethereum.istanbul.vm.Evm) → None
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:
# STACK
pass
# GAS
charge_gas(evm, GAS_BASE)
# OPERATION
push(evm.stack, U256(evm.env.gas_limit))
# PROGRAM COUNTER
evm.pc += 1
chain_id
- chain_id(evm: ethereum.istanbul.vm.Evm) → None
Push the chain id onto the stack.
- Parameters
evm – The current EVM frame.
def chain_id(evm: Evm) -> None:
# STACK
pass
# GAS
charge_gas(evm, GAS_BASE)
# OPERATION
push(evm.stack, U256(evm.env.chain_id))
# PROGRAM COUNTER
evm.pc += 1