Skip to content

test_identity_return_buffer_modify()

Documentation for tests/homestead/identity_precompile/test_identity.py::test_identity_return_buffer_modify@b47f0253.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/homestead/identity_precompile/test_identity.py::test_identity_return_buffer_modify --fork Amsterdam

Test the modification of the input range to attempt to modify the return buffer.

Source code in tests/homestead/identity_precompile/test_identity.py
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
@pytest.mark.with_all_call_opcodes()
@pytest.mark.valid_from("Byzantium")
def test_identity_return_buffer_modify(
    state_test: StateTestFiller,
    pre: Alloc,
    call_opcode: Op,
) -> None:
    """
    Test the modification of the input range to attempt to modify the return
    buffer.
    """
    env = Environment()
    code = (
        sum(
            Op.MSTORE8(offset=i, value=(i + 1)) for i in range(4)
        )  # memory = [1, 2, 3, 4]
        + call_opcode(
            address=4,
            args_offset=0,
            args_size=4,  # args = [1, 2, 3, 4]
        )  # memory = [1, 2, 3, 4]
        + Op.MSTORE8(offset=0, value=5)  # memory = [5, 2, 3, 4]
        + Op.MSTORE8(offset=4, value=5)  # memory = [5, 2, 3, 4, 5]
        + Op.RETURNDATACOPY(
            dest_offset=0, offset=0, size=Op.RETURNDATASIZE()
        )  # memory correct = [1, 2, 3, 4, 5], corrupt = [5, 2, 3, 4, 5]
        + Op.SSTORE(1, Op.SHA3(offset=0, size=Op.MSIZE))
    )
    contract_address = pre.deploy_contract(
        code=code,
    )
    tx = Transaction(
        sender=pre.fund_eoa(),
        to=contract_address,
        gas_limit=100_000,
    )

    post = {
        contract_address: Account(
            storage={
                1: keccak256(bytes([1, 2, 3, 4, 5]).ljust(32, b"\0")),
            },
        ),
    }

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

Parametrized Test Cases

This test generates 4 parametrized test cases across 12 forks.