Skip to content

Missing array index OOB check #877

Open
@g-r-a-n-t

Description

@g-r-a-n-t

What is wrong?

See the following code:

// The following tests does not pass due absent runtime check.
// Obviously this couild also be a compile-time check.
//
// contract ArrayIndexOobStatic {
// pub unsafe fn __call__() {
// let mut my_array: Array<u256, 4> = [0, 1, 2, 3]
// evm::sstore(offset: 0, value: my_array[26])
// }
// }
// #test
// unsafe fn test_array_oob_static() {
// let mut ctx: Context = Context()
// let array_index_oob: ArrayIndexOobStatic = ArrayIndexOobStatic.create(ctx, value: 0)
// let expected_revert_data: Array<u8, 36> = [78, 72, 123, 113, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 50]
// // verify that the call reverts
// assert evm::call(
// gas: CALL_GAS,
// addr: address(array_index_oob),
// value: 0,
// input_offset: 0,
// input_len: 0,
// output_offset: FREE_MEM_PTR,
// output_len: 36
// ) == 0
// // check the revert data
// let mut offset: u256 = FREE_MEM_PTR
// for expected_byte in expected_revert_data {
// assert evm::shr(248, evm::mload(offset)) == expected_byte
// offset += 1
// }
// }

How can it be fixed

Add a compile-time check for array indices.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions