2019-06-13 15:22:24 +00:00
|
|
|
contract C {
|
2019-09-18 13:38:38 +00:00
|
|
|
uint[] storageArray;
|
|
|
|
function test_zeroed_indicies(uint256 len) public
|
|
|
|
{
|
2019-11-18 13:36:45 +00:00
|
|
|
while(storageArray.length < len)
|
|
|
|
storageArray.push();
|
|
|
|
while(storageArray.length > len)
|
|
|
|
storageArray.pop();
|
2019-06-13 15:22:24 +00:00
|
|
|
|
2019-09-18 13:38:38 +00:00
|
|
|
for (uint i = 0; i < len; i++)
|
|
|
|
storageArray[i] = i + 1;
|
2019-06-13 15:22:24 +00:00
|
|
|
|
2019-09-18 13:38:38 +00:00
|
|
|
if (len > 3)
|
|
|
|
{
|
2019-11-18 13:36:45 +00:00
|
|
|
while(storageArray.length > 0)
|
|
|
|
storageArray.pop();
|
|
|
|
while(storageArray.length < 3)
|
|
|
|
storageArray.push();
|
2019-06-13 15:22:24 +00:00
|
|
|
|
2019-09-18 13:38:38 +00:00
|
|
|
for (uint i = 3; i < len; i++)
|
|
|
|
{
|
|
|
|
assembly {
|
|
|
|
mstore(0, storageArray_slot)
|
|
|
|
let pos := add(keccak256(0, 0x20), i)
|
2019-06-13 15:22:24 +00:00
|
|
|
|
2019-09-18 13:38:38 +00:00
|
|
|
if iszero(eq(sload(pos), 0)) {
|
|
|
|
revert(0, 0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-06-13 15:22:24 +00:00
|
|
|
|
2019-09-18 13:38:38 +00:00
|
|
|
}
|
2019-06-13 15:22:24 +00:00
|
|
|
|
2019-11-18 13:36:45 +00:00
|
|
|
while(storageArray.length > 0)
|
|
|
|
storageArray.pop();
|
|
|
|
while(storageArray.length < len)
|
|
|
|
storageArray.push();
|
2019-06-13 15:22:24 +00:00
|
|
|
|
2019-09-18 13:38:38 +00:00
|
|
|
for (uint i = 0; i < len; i++)
|
|
|
|
{
|
|
|
|
require(storageArray[i] == 0);
|
2019-06-13 15:22:24 +00:00
|
|
|
|
2019-09-18 13:38:38 +00:00
|
|
|
uint256 val = storageArray[i];
|
|
|
|
uint256 check;
|
2019-06-13 15:22:24 +00:00
|
|
|
|
2019-09-18 13:38:38 +00:00
|
|
|
assembly { check := iszero(val) }
|
2019-06-13 15:22:24 +00:00
|
|
|
|
2019-09-18 13:38:38 +00:00
|
|
|
require(check == 1);
|
|
|
|
}
|
|
|
|
}
|
2019-06-13 15:22:24 +00:00
|
|
|
}
|
2019-11-07 20:22:58 +00:00
|
|
|
// ====
|
|
|
|
// compileViaYul: true
|
2019-06-13 15:22:24 +00:00
|
|
|
// ----
|
|
|
|
// test_zeroed_indicies(uint256): 1 ->
|
|
|
|
// test_zeroed_indicies(uint256): 5 ->
|
|
|
|
// test_zeroed_indicies(uint256): 10 ->
|
|
|
|
// test_zeroed_indicies(uint256): 15 ->
|
|
|
|
// test_zeroed_indicies(uint256): 0xFF ->
|