2019-06-27 11:36:06 +00:00
|
|
|
contract C {
|
|
|
|
function index(uint256 len) public returns (bool)
|
|
|
|
{
|
|
|
|
uint[] memory array = new uint[](len);
|
|
|
|
|
|
|
|
for (uint256 i = 0; i < len; i++)
|
|
|
|
array[i] = i + 1;
|
|
|
|
|
|
|
|
for (uint256 i = 0; i < len; i++)
|
|
|
|
require(array[i] == i + 1, "Unexpected value in array!");
|
|
|
|
|
|
|
|
return array.length == len;
|
|
|
|
}
|
|
|
|
function accessIndex(uint256 len, int256 idx) public returns (uint256)
|
|
|
|
{
|
|
|
|
uint[] memory array = new uint[](len);
|
|
|
|
|
|
|
|
for (uint256 i = 0; i < len; i++)
|
|
|
|
array[i] = i + 1;
|
|
|
|
|
|
|
|
return array[uint256(idx)];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// ====
|
2020-11-24 23:25:42 +00:00
|
|
|
// compileViaYul: also
|
2019-06-27 11:36:06 +00:00
|
|
|
// ----
|
|
|
|
// index(uint256): 0 -> true
|
|
|
|
// index(uint256): 10 -> true
|
|
|
|
// index(uint256): 20 -> true
|
|
|
|
// index(uint256): 0xFF -> true
|
2021-09-15 15:01:40 +00:00
|
|
|
// gas irOptimized: 138441
|
2021-02-12 12:45:15 +00:00
|
|
|
// gas legacy: 248854
|
2021-03-15 18:29:41 +00:00
|
|
|
// gas legacyOptimized: 152638
|
2020-10-13 11:28:39 +00:00
|
|
|
// accessIndex(uint256,int256): 10, 1 -> 2
|
|
|
|
// accessIndex(uint256,int256): 10, 0 -> 1
|
|
|
|
// accessIndex(uint256,int256): 10, 11 -> FAILURE, hex"4e487b71", 0x32
|
|
|
|
// accessIndex(uint256,int256): 10, 10 -> FAILURE, hex"4e487b71", 0x32
|
|
|
|
// accessIndex(uint256,int256): 10, -1 -> FAILURE, hex"4e487b71", 0x32
|