diff --git a/contracts/utils/EnumerableSet.sol b/contracts/utils/EnumerableSet.sol index 8917cccaf17..e6f03161224 100644 --- a/contracts/utils/EnumerableSet.sol +++ b/contracts/utils/EnumerableSet.sol @@ -53,21 +53,10 @@ library EnumerableSet { */ function _add(Set storage set, bytes32 value) private returns (bool) { if (!_contains(set, value)) { - - uint256 last; - assembly { - let p := sload(0x40) - mstore(p, set.slot) - let blk := keccak256(p, 0x20) - // push new value - last := sload(set.slot) - sstore(add(blk, last), value) - // update array length - last := add(last, 1) - sstore(set.slot, last) - } - set._indexes[value] = last; - + set._values.push(value); + // The value is stored at length-1, but we add 1 to all indexes + // and use 0 as a sentinel value + set._indexes[value] = set._values.length; return true; } else { return false; @@ -132,7 +121,7 @@ library EnumerableSet { * * - `index` must be strictly less than {length}. */ - function _at(Set storage set, uint256 index) private view returns (bytes32 value) { + function _at(Set storage set, uint256 index) private view returns (bytes32) { require(set._values.length > index, "EnumerableSet: index out of bounds"); return set._values[index]; }