|
| 1 | +// SPDX-License-Identifier: AGPL-3.0 |
| 2 | +pragma solidity >=0.8.0 <0.9.0; |
| 3 | + |
| 4 | +contract Storage5Test { |
| 5 | + uint[] arr0; // slot 0: keccak(0) = 0x290DECD9548B62A8D60345A988386FC84BA6BC95484008F6362F93160EF3E563 (ends with 1) |
| 6 | + uint[] arr1; // slot 1: keccak(1) = 0xB10E2D527612073B26EECDFD717E6A320CF44B4AFAC2B0732D9FCBE2B7FA0CF6 (ends with 0) |
| 7 | + uint dummy2; // slot 2 |
| 8 | + uint dummy3; // slot 3 |
| 9 | + uint dummy4; // slot 4 |
| 10 | + uint[] arr5; // slot 5: keccak(5) = 0x036B6384B5ECA791C62761152D0C79BB0604C104A5FB6F4EB0703F3154BB3DB0 (ends with 00) |
| 11 | + |
| 12 | + function setUp() public { |
| 13 | + arr0.push(0); |
| 14 | + arr0.push(0); |
| 15 | + arr0.push(0); |
| 16 | + arr0.push(0); |
| 17 | + arr0.push(0); |
| 18 | + arr0.push(0); |
| 19 | + arr0.push(0); |
| 20 | + arr0.push(0); |
| 21 | + |
| 22 | + arr1.push(1); |
| 23 | + arr1.push(1); |
| 24 | + arr1.push(1); |
| 25 | + arr1.push(1); |
| 26 | + arr1.push(1); |
| 27 | + arr1.push(1); |
| 28 | + arr1.push(1); |
| 29 | + arr1.push(1); |
| 30 | + |
| 31 | + arr5.push(5); |
| 32 | + arr5.push(5); |
| 33 | + arr5.push(5); |
| 34 | + arr5.push(5); |
| 35 | + arr5.push(5); |
| 36 | + arr5.push(5); |
| 37 | + arr5.push(5); |
| 38 | + arr5.push(5); |
| 39 | + } |
| 40 | + |
| 41 | + function check_array_access(uint index) public { |
| 42 | + // The commented ones generate errors due to a failure in decoding |
| 43 | + // storage slots. This happens because the storage slot expression in |
| 44 | + // the form of an addition, `keccak(x) + (index % y)`, is automatically |
| 45 | + // simplified to a concatenation form when the keccak value ends with |
| 46 | + // zero bits and y is a power of two. This simplified form is not |
| 47 | + // currently supported by the decoding logic of halmos. |
| 48 | + |
| 49 | + assert(arr0[index % 1] == 0); // sload(keccak(0) + (index % 1)) |
| 50 | + assert(arr0[index % 2] == 0); // sload(keccak(0) + (index % 2)) |
| 51 | + assert(arr0[index % 3] == 0); // sload(keccak(0) + (index % 3)) |
| 52 | + assert(arr0[index % 4] == 0); // sload(keccak(0) + (index % 4)) |
| 53 | + assert(arr0[index % 5] == 0); // sload(keccak(0) + (index % 5)) |
| 54 | + assert(arr0[index % 6] == 0); // sload(keccak(0) + (index % 6)) |
| 55 | + assert(arr0[index % 7] == 0); // sload(keccak(0) + (index % 7)) |
| 56 | + assert(arr0[index % 8] == 0); // sload(keccak(0) + (index % 8)) |
| 57 | + |
| 58 | + assert(arr1[index % 1] == 1); // sload(keccak(1) + (index % 1)) |
| 59 | +// assert(arr1[index % 2] == 1); // sload(keccak(1) + (index % 2)) => sload( keccak(1)[:31] ++ index[31:] ) |
| 60 | + assert(arr1[index % 3] == 1); // sload(keccak(1) + (index % 3)) |
| 61 | +// assert(arr1[index % 4] == 1); // sload(keccak(1) + (index % 4)) => sload( keccak(1)[:30] ++ index[30:] ) |
| 62 | + assert(arr1[index % 5] == 1); // sload(keccak(1) + (index % 5)) |
| 63 | + assert(arr1[index % 6] == 1); // sload(keccak(1) + (index % 6)) |
| 64 | + assert(arr1[index % 7] == 1); // sload(keccak(1) + (index % 7)) |
| 65 | + assert(arr1[index % 8] == 1); // sload(keccak(1) + (index % 8)) |
| 66 | + |
| 67 | + assert(arr5[index % 1] == 5); // sload(keccak(5) + (index % 1)) |
| 68 | +// assert(arr5[index % 2] == 5); // sload(keccak(5) + (index % 2)) => sload( keccak(5)[:31] ++ index[31:] ) |
| 69 | + assert(arr5[index % 3] == 5); // sload(keccak(5) + (index % 3)) |
| 70 | +// assert(arr5[index % 4] == 5); // sload(keccak(5) + (index % 4)) => sload( keccak(5)[:30] ++ index[30:] ) |
| 71 | + assert(arr5[index % 5] == 5); // sload(keccak(5) + (index % 5)) |
| 72 | + assert(arr5[index % 6] == 5); // sload(keccak(5) + (index % 6)) |
| 73 | + assert(arr5[index % 7] == 5); // sload(keccak(5) + (index % 7)) |
| 74 | +// assert(arr5[index % 8] == 5); // sload(keccak(5) + (index % 8)) => sload( keccak(5)[:29] ++ index[29:] ) |
| 75 | + } |
| 76 | +} |
0 commit comments