Skip to content

Commit

Permalink
EnumerableSet: Remove Boundary Check in _at (OpenZeppelin#2606)
Browse files Browse the repository at this point in the history
* remove boundary check

* fix tests for EnumerableSet "index out of bound"

* Changelog

Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com>
  • Loading branch information
wjmelements and Amxx authored Apr 20, 2021
1 parent 750a176 commit 165e6f1
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased
* Enumerables: Improve gas cost of removal in `EnumerableSet` and `EnumerableMap`.
* Enumerables: Improve gas cost of lookup in `EnumerableSet` and `EnumerableMap`.

## Unreleased

Expand Down
1 change: 0 additions & 1 deletion contracts/utils/structs/EnumerableSet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ library EnumerableSet {
* - `index` must be strictly less than {length}.
*/
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];
}

Expand Down
2 changes: 1 addition & 1 deletion test/utils/structs/EnumerableSet.behavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function shouldBehaveLikeSet (valueA, valueB, valueC) {

describe('at', function () {
it('reverts when retrieving non-existent elements', async function () {
await expectRevert(this.set.at(0), 'EnumerableSet: index out of bounds');
await expectRevert.unspecified(this.set.at(0));
});
});

Expand Down

0 comments on commit 165e6f1

Please sign in to comment.