Skip to content

test_blockhash_zero_in_window_control()

Documentation for tests/frontier/opcodes/test_blockhash_state_test_recency.py::test_blockhash_zero_in_window_control@26332146.

Generate fixtures for these test cases for Cancun with:

fill -v tests/frontier/opcodes/test_blockhash_state_test_recency.py::test_blockhash_zero_in_window_control --fork Cancun

In-window control: BLOCKHASH(0) returns the block-0 hash at block 1.

This is the positive counterpart to the out-of-window test. With block 0 inside the recency window (current block == 1) and previousHash set to the state-test convention value keccak256("0"), all clients -- including nethermind -- agree on the result, pinning the window boundary.

Restricted to <= Cancun because EIP-2935 (Prague+) serves BLOCKHASH from the history storage contract, which is not pre-populated in a bare state test. Marked state_test_only: the asserted non-zero hash would not match the real genesis hash of a derived blockchain-test fixture.

Source code in tests/frontier/opcodes/test_blockhash_state_test_recency.py
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
@pytest.mark.valid_from("Frontier")
@pytest.mark.valid_until("Cancun")
@pytest.mark.state_test_only
def test_blockhash_zero_in_window_control(
    state_test: StateTestFiller,
    pre: Alloc,
) -> None:
    """
    In-window control: BLOCKHASH(0) returns the block-0 hash at block 1.

    This is the positive counterpart to the out-of-window test. With block 0
    inside the recency window (current block == 1) and ``previousHash`` set
    to the state-test convention value ``keccak256("0")``, all clients --
    including nethermind -- agree on the result, pinning the window boundary.

    Restricted to <= Cancun because EIP-2935 (Prague+) serves BLOCKHASH from
    the history storage contract, which is not pre-populated in a bare state
    test.
    Marked ``state_test_only``: the asserted non-zero hash would not match the
    real genesis hash of a derived blockchain-test fixture.
    """
    storage = Storage()
    contract = pre.deploy_contract(
        code=Op.SSTORE(
            storage.store_next(KECCAK_OF_BLOCK_0, "blockhash_0_value"),
            Op.BLOCKHASH(0),
        )
    )
    sender = pre.fund_eoa()

    tx = Transaction(
        sender=sender,
        to=contract,
        protected=False,  # legacy tx so it fills on pre-EIP-155 forks too
    )

    state_test(
        env=Environment(
            number=1,
            block_hashes={0: KECCAK_OF_BLOCK_0},
        ),
        pre=pre,
        post={contract: Account(storage=storage)},
        tx=tx,
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 13 forks.