Skip to content

test_clz_stack_not_overflow()

Documentation for tests/osaka/eip7939_count_leading_zeros/test_count_leading_zeros.py::test_clz_stack_not_overflow@88e9fb8f.

Generate fixtures for these test cases for Osaka with:

fill -v tests/osaka/eip7939_count_leading_zeros/test_count_leading_zeros.py::test_clz_stack_not_overflow --fork Osaka

Test CLZ opcode never causes stack overflow.

Source code in tests/osaka/eip7939_count_leading_zeros/test_count_leading_zeros.py
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
@EIPChecklist.Opcode.Test.StackComplexOperations.StackHeights.Odd()
@EIPChecklist.Opcode.Test.StackComplexOperations.StackHeights.Even()
@pytest.mark.valid_from("Osaka")
def test_clz_stack_not_overflow(state_test: StateTestFiller, pre: Alloc, fork: Fork) -> None:
    """Test CLZ opcode never causes stack overflow."""
    max_stack_items = fork.max_stack_height()

    code = Bytecode()
    post = {}

    code += Op.PUSH0 * (max_stack_items - 2)

    for i in range(256):
        code += Op.PUSH1(i) + Op.CLZ(1 << i) + Op.SWAP1 + Op.SSTORE

    code_address = pre.deploy_contract(code=code)

    post[code_address] = Account(storage={i: 255 - i for i in range(256)})

    tx = Transaction(
        to=code_address,
        sender=pre.fund_eoa(),
        gas_limit=6_000_000,
    )

    state_test(pre=pre, post=post, tx=tx)

Parametrized Test Cases

This test case is only parametrized by fork and fixture format.

Test ID (Abbreviated)
...fork_Osaka-state_test
...fork_Osaka-blockchain_test_from_state_test