ethereum.forks.frontier.vm.instructions.blockethereum.forks.homestead.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
    """
23
    Push the hash of one of the 256 most recent complete blocks onto the
24
    stack. The block number to hash is present at the top of the stack.
25
26
    Parameters
27
    ----------
28
    evm :
29
        The current EVM frame.
30
31
    """
32
    # STACK
33
    block_number = Uint(pop(evm.stack))
34
35
    # GAS
36
    charge_gas(evm, GAS_BLOCK_HASH)
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
    """
62
    Push the current block's beneficiary address (address of the block miner)
63
    onto the stack.
64
65
    Here the current block refers to the block in which the currently
66
    executing transaction/call resides.
67
68
    Parameters
69
    ----------
70
    evm :
71
        The current EVM frame.
72
73
    """
74
    # STACK
75
    pass
76
77
    # GAS
78
    charge_gas(evm, GAS_BASE)
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 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
    """
89
    Push the current block's timestamp onto the stack. Here the timestamp
90
    being referred is actually the unix timestamp in seconds.
91
92
    Here the current block refers to the block in which the currently
93
    executing transaction/call resides.
94
95
    Parameters
96
    ----------
97
    evm :
98
        The current EVM frame.
99
100
    """
101
    # STACK
102
    pass
103
104
    # GAS
105
    charge_gas(evm, GAS_BASE)
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
    """
116
    Push the current block's number onto the stack.
117
118
    Here the current block refers to the block in which the currently
119
    executing transaction/call resides.
120
121
    Parameters
122
    ----------
123
    evm :
124
        The current EVM frame.
125
126
    """
127
    # STACK
128
    pass
129
130
    # GAS
131
    charge_gas(evm, GAS_BASE)
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
    """
142
    Push the current block's difficulty onto the stack.
143
144
    Here the current block refers to the block in which the currently
145
    executing transaction/call resides.
146
147
    Parameters
148
    ----------
149
    evm :
150
        The current EVM frame.
151
152
    """
153
    # STACK
154
    pass
155
156
    # GAS
157
    charge_gas(evm, GAS_BASE)
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
    """
168
    Push the current block's gas limit onto the stack.
169
170
    Here the current block refers to the block in which the currently
171
    executing transaction/call resides.
172
173
    Parameters
174
    ----------
175
    evm :
176
        The current EVM frame.
177
178
    """
179
    # STACK
180
    pass
181
182
    # GAS
183
    charge_gas(evm, GAS_BASE)
184
185
    # OPERATION
186
    push(evm.stack, U256(evm.message.block_env.block_gas_limit))
187
188
    # PROGRAM COUNTER
189
    evm.pc += Uint(1)