ethereum.forks.dao_fork.vm.instructions.blockethereum.forks.tangerine_whistle.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:
22
    <snip>
32
    # STACK
33
    block_number = Uint(pop(evm.stack))
34
35
    # GAS
36
    charge_gas(evm, GasCosts.OPCODE_BLOCKHASH)
37
38
    # OPERATION
39
    max_block_number = block_number + Uint(256)
40
    current_block_number = evm.message.block_env.number
41
    if (
42
        current_block_number <= block_number
43
        or current_block_number > max_block_number
44
    ):
45
        # Default hash to 0, if the block of interest is not yet on the chain
46
        # (including the block which has the current executing transaction),
47
        # or if the block's age is more than 256.
48
        current_block_hash = b"\x00"
49
    else:
50
        current_block_hash = evm.message.block_env.block_hashes[
51
            -(current_block_number - block_number)
52
        ]
53
54
    push(evm.stack, U256.from_be_bytes(current_block_hash))
55
56
    # PROGRAM COUNTER
57
    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:
61
    <snip>
74
    # STACK
75
    pass
76
77
    # GAS
78
    charge_gas(evm, GasCosts.OPCODE_COINBASE)
79
80
    # OPERATION
81
    push(evm.stack, U256.from_be_bytes(evm.message.block_env.coinbase))
82
83
    # PROGRAM COUNTER
84
    evm.pc += Uint(1)

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.

def timestamp(evm: Evm) -> None:
88
    <snip>
101
    # STACK
102
    pass
103
104
    # GAS
105
    charge_gas(evm, GasCosts.OPCODE_TIMESTAMP)
106
107
    # OPERATION
108
    push(evm.stack, evm.message.block_env.time)
109
110
    # PROGRAM COUNTER
111
    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:
115
    <snip>
127
    # STACK
128
    pass
129
130
    # GAS
131
    charge_gas(evm, GasCosts.OPCODE_NUMBER)
132
133
    # OPERATION
134
    push(evm.stack, U256(evm.message.block_env.number))
135
136
    # PROGRAM COUNTER
137
    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:
141
    <snip>
153
    # STACK
154
    pass
155
156
    # GAS
157
    charge_gas(evm, GasCosts.OPCODE_DIFFICULTY)
158
159
    # OPERATION
160
    push(evm.stack, U256(evm.message.block_env.difficulty))
161
162
    # PROGRAM COUNTER
163
    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:
167
    <snip>
179
    # STACK
180
    pass
181
182
    # GAS
183
    charge_gas(evm, GasCosts.OPCODE_GASLIMIT)
184
185
    # OPERATION
186
    push(evm.stack, U256(evm.message.block_env.block_gas_limit))
187
188
    # PROGRAM COUNTER
189
    evm.pc += Uint(1)