Skip to content

Commit 1bd3c8a

Browse files
committed
changing all assembly blocks to use memory-safe
1 parent 36291c5 commit 1bd3c8a

File tree

3 files changed

+20
-20
lines changed

3 files changed

+20
-20
lines changed

src/AssociatedArrayLib.sol

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ library AssociatedArrayLib {
1515
}
1616

1717
function _slot(Array storage s, address account) private pure returns (bytes32 __slot) {
18-
assembly {
18+
assembly ("memory-safe") {
1919
mstore(0x00, account)
2020
mstore(0x20, s.slot)
2121
__slot := keccak256(0x00, 0x40)
@@ -24,7 +24,7 @@ library AssociatedArrayLib {
2424

2525
function _length(Array storage s, address account) private view returns (uint256 __length) {
2626
bytes32 slot = _slot(s, account);
27-
assembly {
27+
assembly ("memory-safe") {
2828
__length := sload(slot)
2929
}
3030
}
@@ -34,7 +34,7 @@ library AssociatedArrayLib {
3434
}
3535

3636
function _get(bytes32 slot, uint256 index) private view returns (bytes32 value) {
37-
assembly {
37+
assembly ("memory-safe") {
3838
//if (index >= _length(s, account)) revert AssociatedArray_OutOfBounds(index);
3939
if iszero(lt(index, sload(slot))) {
4040
mstore(0, 0x8277484f) // `AssociatedArray_OutOfBounds(uint256)`
@@ -48,7 +48,7 @@ library AssociatedArrayLib {
4848
function _getAll(Array storage s, address account) private view returns (bytes32[] memory values) {
4949
bytes32 slot = _slot(s, account);
5050
uint256 __length;
51-
assembly {
51+
assembly ("memory-safe") {
5252
__length := sload(slot)
5353
}
5454
values = new bytes32[](__length);
@@ -63,7 +63,7 @@ library AssociatedArrayLib {
6363
function _contains(Array storage s, address account, bytes32 value) private view returns (bool) {
6464
bytes32 slot = _slot(s, account);
6565
uint256 __length;
66-
assembly {
66+
assembly ("memory-safe") {
6767
__length := sload(slot)
6868
}
6969
for (uint256 i; i < __length; i++) {
@@ -79,7 +79,7 @@ library AssociatedArrayLib {
7979
}
8080

8181
function _set(bytes32 slot, uint256 index, bytes32 value) private {
82-
assembly {
82+
assembly ("memory-safe") {
8383
//if (index >= _length(s, account)) revert AssociatedArray_OutOfBounds(index);
8484
if iszero(lt(index, sload(slot))) {
8585
mstore(0, 0x8277484f) // `AssociatedArray_OutOfBounds(uint256)`
@@ -92,7 +92,7 @@ library AssociatedArrayLib {
9292

9393
function _push(Array storage s, address account, bytes32 value) private {
9494
bytes32 slot = _slot(s, account);
95-
assembly {
95+
assembly ("memory-safe") {
9696
// load length (stored @ slot), add 1 to it => index.
9797
// mul index by 0x20 and add it to orig slot to get the next free slot
9898
let index := add(sload(slot), 1)
@@ -104,20 +104,20 @@ library AssociatedArrayLib {
104104
function _pop(Array storage s, address account) private {
105105
bytes32 slot = _slot(s, account);
106106
uint256 __length;
107-
assembly {
107+
assembly ("memory-safe") {
108108
__length := sload(slot)
109109
}
110110
if (__length == 0) return;
111111
_set(slot, __length - 1, 0);
112-
assembly {
112+
assembly ("memory-safe") {
113113
sstore(slot, sub(__length, 1))
114114
}
115115
}
116116

117117
function _remove(Array storage s, address account, uint256 index) private {
118118
bytes32 slot = _slot(s, account);
119119
uint256 __length;
120-
assembly {
120+
assembly ("memory-safe") {
121121
__length := sload(slot)
122122
if iszero(lt(index, __length)) {
123123
mstore(0, 0x8277484f) // `AssociatedArray_OutOfBounds(uint256)`
@@ -127,7 +127,7 @@ library AssociatedArrayLib {
127127
}
128128
_set(slot, index, _get(s, account, __length - 1));
129129

130-
assembly {
130+
assembly ("memory-safe") {
131131
// clear the last slot
132132
// this is the 'unchecked' version of _set(slot, __length - 1, 0)
133133
// as we use length-1 as index, so the check is excessive.
@@ -197,7 +197,7 @@ library AssociatedArrayLib {
197197
address[] memory addressArray;
198198

199199
/// @solidity memory-safe-assembly
200-
assembly {
200+
assembly ("memory-safe") {
201201
addressArray := bytes32Array
202202
}
203203
return addressArray;
@@ -246,7 +246,7 @@ library AssociatedArrayLib {
246246
uint256[] memory uintArray;
247247

248248
/// @solidity memory-safe-assembly
249-
assembly {
249+
assembly ("memory-safe") {
250250
uintArray := bytes32Array
251251
}
252252
return uintArray;

src/EnumerableMap4337.sol

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ library EnumerableMap {
268268
uint256[] memory result;
269269

270270
/// @solidity memory-safe-assembly
271-
assembly {
271+
assembly ("memory-safe") {
272272
result := store
273273
}
274274

@@ -370,7 +370,7 @@ library EnumerableMap {
370370
uint256[] memory result;
371371

372372
/// @solidity memory-safe-assembly
373-
assembly {
373+
assembly ("memory-safe") {
374374
result := store
375375
}
376376

@@ -472,7 +472,7 @@ library EnumerableMap {
472472
address[] memory result;
473473

474474
/// @solidity memory-safe-assembly
475-
assembly {
475+
assembly ("memory-safe") {
476476
result := store
477477
}
478478

@@ -574,7 +574,7 @@ library EnumerableMap {
574574
bytes32[] memory result;
575575

576576
/// @solidity memory-safe-assembly
577-
assembly {
577+
assembly ("memory-safe") {
578578
result := store
579579
}
580580

src/EnumerableSet4337.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ library EnumerableSet {
206206
bytes32[] memory result;
207207

208208
/// @solidity memory-safe-assembly
209-
assembly {
209+
assembly ("memory-safe") {
210210
result := store
211211
}
212212

@@ -284,7 +284,7 @@ library EnumerableSet {
284284
address[] memory result;
285285

286286
/// @solidity memory-safe-assembly
287-
assembly {
287+
assembly ("memory-safe") {
288288
result := store
289289
}
290290

@@ -362,7 +362,7 @@ library EnumerableSet {
362362
uint256[] memory result;
363363

364364
/// @solidity memory-safe-assembly
365-
assembly {
365+
assembly ("memory-safe") {
366366
result := store
367367
}
368368

0 commit comments

Comments
 (0)