|
| 1 | +// SPDX-License-Identifier: MIT |
| 2 | +pragma solidity ^0.8.29; |
| 3 | + |
| 4 | +abstract contract Base { |
| 5 | + uint256 public x; |
| 6 | +} |
| 7 | + |
| 8 | +contract CustomLayout layout at 0x1 is Base { |
| 9 | + uint256 public y; |
| 10 | +} |
| 11 | + |
| 12 | +contract CustomLayout_Same_Root_Ok layout at 0x1 is Base { |
| 13 | + uint256 public y; |
| 14 | + uint256 public z; |
| 15 | +} |
| 16 | + |
| 17 | +contract CustomLayout_Same_Root_Decimal_Ok layout at 1 is Base { |
| 18 | + uint256 public y; |
| 19 | + uint256 public z; |
| 20 | +} |
| 21 | + |
| 22 | +contract CustomLayout_Same_Root_ScientificNotation_Ok layout at 1000.0e-3 is Base { |
| 23 | + uint256 public y; |
| 24 | + uint256 public z; |
| 25 | +} |
| 26 | + |
| 27 | +contract CustomLayout_Changed_Root_Bad layout at 0x2 is Base { |
| 28 | + uint256 public y; |
| 29 | + uint256 public z; |
| 30 | +} |
| 31 | + |
| 32 | +contract CustomLayout_Changed_Root_Decimal_Bad layout at 2 is Base { |
| 33 | + uint256 public y; |
| 34 | + uint256 public z; |
| 35 | +} |
| 36 | + |
| 37 | +contract CustomLayout_Changed_Root_ScientificNotation_Bad layout at 2.0e10 is Base { |
| 38 | + uint256 public y; |
| 39 | + uint256 public z; |
| 40 | +} |
| 41 | + |
| 42 | +contract CustomLayout_Changed_To_Default_Bad is Base { |
| 43 | + uint256 public y; |
| 44 | + uint256 public z; |
| 45 | +} |
| 46 | + |
| 47 | +contract CustomLayout_Changed_Root_Ok layout at 0x0 { |
| 48 | + uint256 public insertedBefore; |
| 49 | + uint256 public x; |
| 50 | + uint256 public y; |
| 51 | + uint256 public z; |
| 52 | +} |
| 53 | + |
| 54 | +contract CustomLayout_Changed_To_Default_Ok { |
| 55 | + uint256 public insertedBefore; |
| 56 | + uint256 public x; |
| 57 | + uint256 public y; |
| 58 | + uint256 public z; |
| 59 | +} |
| 60 | + |
| 61 | +contract Namespaced_Default_Layout { |
| 62 | + /// @custom:storage-location erc7201:example.main |
| 63 | + struct MainStorage { |
| 64 | + uint256 x; |
| 65 | + uint256 y; |
| 66 | + } |
| 67 | + |
| 68 | + // keccak256(abi.encode(uint256(keccak256("example.main")) - 1)) & ~bytes32(uint256(0xff)); |
| 69 | + bytes32 private constant MAIN_STORAGE_LOCATION = |
| 70 | + 0x183a6125c38840424c4a85fa12bab2ab606c4b6d0e7cc73c0c06ba5300eab500; |
| 71 | +} |
| 72 | + |
| 73 | +contract CustomLayout_Unsupported_Node_Type layout at 0x2 ** 0x3 { |
| 74 | + uint256 public x; |
| 75 | +} |
| 76 | + |
| 77 | +contract Namespaced_Custom_Layout_Unaffected layout at 0x1 { |
| 78 | + /// @custom:storage-location erc7201:example.main |
| 79 | + struct MainStorage { |
| 80 | + uint256 x; |
| 81 | + uint256 y; |
| 82 | + } |
| 83 | + |
| 84 | + // keccak256(abi.encode(uint256(keccak256("example.main")) - 1)) & ~bytes32(uint256(0xff)); |
| 85 | + bytes32 private constant MAIN_STORAGE_LOCATION = |
| 86 | + 0x183a6125c38840424c4a85fa12bab2ab606c4b6d0e7cc73c0c06ba5300eab500; |
| 87 | +} |
| 88 | + |
| 89 | +contract Namespaced_Custom_Layout_Clash layout at 0x183a6125c38840424c4a85fa12bab2ab606c4b6d0e7cc73c0c06ba5300eab500 { |
| 90 | + /// @custom:storage-location erc7201:example.main |
| 91 | + struct MainStorage { |
| 92 | + uint256 x; |
| 93 | + uint256 y; |
| 94 | + } |
| 95 | + |
| 96 | + uint256 clashesWithNamespace; |
| 97 | + |
| 98 | + // keccak256(abi.encode(uint256(keccak256("example.main")) - 1)) & ~bytes32(uint256(0xff)); |
| 99 | + bytes32 private constant MAIN_STORAGE_LOCATION = |
| 100 | + 0x183a6125c38840424c4a85fa12bab2ab606c4b6d0e7cc73c0c06ba5300eab500; |
| 101 | +} |
| 102 | + |
| 103 | +contract Namespaced_Custom_Layout_Clash_Decimal layout at 10958655983261152271848436692291137275443024275653522991983264966744321209600 { |
| 104 | + /// @custom:storage-location erc7201:example.main |
| 105 | + struct MainStorage { |
| 106 | + uint256 x; |
| 107 | + uint256 y; |
| 108 | + } |
| 109 | + |
| 110 | + uint256 clashesWithNamespace; |
| 111 | + |
| 112 | + // keccak256(abi.encode(uint256(keccak256("example.main")) - 1)) & ~bytes32(uint256(0xff)); |
| 113 | + bytes32 private constant MAIN_STORAGE_LOCATION = |
| 114 | + 0x183a6125c38840424c4a85fa12bab2ab606c4b6d0e7cc73c0c06ba5300eab500; |
| 115 | +} |
| 116 | + |
| 117 | +contract Namespaced_Custom_Layout_Clash_Extra_Colon layout at 0xc7aaba8d22be97cadd7427e7a6841eaffa38e68fd57b8f5417d9acc1a1566e00 { |
| 118 | + /// @custom:storage-location erc7201:example:main |
| 119 | + struct MainStorage { |
| 120 | + uint256 x; |
| 121 | + uint256 y; |
| 122 | + } |
| 123 | + |
| 124 | + uint256 clashesWithNamespace; |
| 125 | + |
| 126 | + // keccak256(abi.encode(uint256(keccak256("example:main")) - 1)) & ~bytes32(uint256(0xff)); |
| 127 | + bytes32 private constant MAIN_STORAGE_LOCATION = |
| 128 | + 0xc7aaba8d22be97cadd7427e7a6841eaffa38e68fd57b8f5417d9acc1a1566e00; |
| 129 | +} |
| 130 | + |
| 131 | +/// No formula id for the namespace (annotation does not comply with ERC-7201), so it is not checked for clash with custom layout |
| 132 | +contract CustomLayout_No_Namespace_Formula layout at 0x183a6125c38840424c4a85fa12bab2ab606c4b6d0e7cc73c0c06ba5300eab500 { |
| 133 | + /// @custom:storage-location example.main |
| 134 | + struct MainStorage { |
| 135 | + uint256 x; |
| 136 | + uint256 y; |
| 137 | + } |
| 138 | + |
| 139 | + uint256 a; |
| 140 | +} |
| 141 | + |
| 142 | +/// No formula id for the namespace (annotation does not comply with ERC-7201), so it is not checked for clash with custom layout |
| 143 | +contract CustomLayout_Unknown_Namespace_Formula layout at 0x183a6125c38840424c4a85fa12bab2ab606c4b6d0e7cc73c0c06ba5300eab500 { |
| 144 | + /// @custom:storage-location erc0000:example.main |
| 145 | + struct MainStorage { |
| 146 | + uint256 x; |
| 147 | + uint256 y; |
| 148 | + } |
| 149 | + |
| 150 | + uint256 a; |
| 151 | +} |
| 152 | + |
| 153 | +abstract contract NamespaceA { |
| 154 | + /// @custom:storage-location erc7201:example.a |
| 155 | + struct AStorage { |
| 156 | + uint256 x; |
| 157 | + } |
| 158 | +} |
| 159 | + |
| 160 | +abstract contract NamespaceB { |
| 161 | + /// @custom:storage-location erc7201:example.b |
| 162 | + struct BStorage { |
| 163 | + uint256 x; |
| 164 | + } |
| 165 | +} |
| 166 | + |
| 167 | +contract CustomLayout_Multiple_Namespaces layout at 0x1 is NamespaceA, NamespaceB { |
| 168 | +} |
| 169 | + |
| 170 | +contract Gap { |
| 171 | + uint256[50] __gap; |
| 172 | + uint256 public x; |
| 173 | +} |
| 174 | + |
| 175 | +contract Gap_Changed_Root_Ok layout at 25 { |
| 176 | + uint256[25] __gap; |
| 177 | + uint256 public x; |
| 178 | +} |
0 commit comments