Ethereum Virtual Machine (EVM) Block Instructions

Introduction

Implementations of the EVM block instructions.

Module Contents

Functions

block_hash

Push the hash of one of the 256 most recent complete blocks onto the

coinbase

Push the current block’s beneficiary address (address of the block miner)

timestamp

Push the current block’s timestamp onto the stack. Here the timestamp

number

Push the current block’s number onto the stack.

difficulty

Push the current block’s difficulty onto the stack.

gas_limit

Push the current block’s gas limit onto the stack.

chain_id

Push the chain id onto the stack.

Module Details

block_hash

block_hash(evm)

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)

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)

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)

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)

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)

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)

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