diff --git a/contracts/mocks/ERC165/ERC165ReturnBomb.sol b/contracts/mocks/ERC165/ERC165ReturnBomb.sol index 681ad41d4..e53235d2c 100644 --- a/contracts/mocks/ERC165/ERC165ReturnBomb.sol +++ b/contracts/mocks/ERC165/ERC165ReturnBomb.sol @@ -5,7 +5,7 @@ pragma solidity ^0.8.0; import "../../utils/introspection/IERC165.sol"; contract ERC165ReturnBombMock is IERC165 { - function supportsInterface(bytes4 interfaceId) public view override returns (bool) { + function supportsInterface(bytes4 interfaceId) public pure override returns (bool) { if (interfaceId == type(IERC165).interfaceId) { assembly { mstore(0, 1) diff --git a/contracts/token/ERC20/extensions/ERC20Votes.sol b/contracts/token/ERC20/extensions/ERC20Votes.sol index 0ce489927..3446d5534 100644 --- a/contracts/token/ERC20/extensions/ERC20Votes.sol +++ b/contracts/token/ERC20/extensions/ERC20Votes.sol @@ -263,7 +263,7 @@ abstract contract ERC20Votes is IVotes, ERC20Permit { return a - b; } - function _unsafeAccess(Checkpoint[] storage ckpts, uint256 pos) private view returns (Checkpoint storage result) { + function _unsafeAccess(Checkpoint[] storage ckpts, uint256 pos) private pure returns (Checkpoint storage result) { assembly { mstore(0, ckpts.slot) result.slot := add(keccak256(0, 0x20), pos) diff --git a/contracts/utils/Checkpoints.sol b/contracts/utils/Checkpoints.sol index c8a062ae7..81a8b5d5a 100644 --- a/contracts/utils/Checkpoints.sol +++ b/contracts/utils/Checkpoints.sol @@ -34,8 +34,8 @@ library Checkpoints { require(blockNumber < block.number, "Checkpoints: block not yet mined"); uint32 key = SafeCast.toUint32(blockNumber); - uint256 length = self._checkpoints.length; - uint256 pos = _upperBinaryLookup(self._checkpoints, key, 0, length); + uint256 len = self._checkpoints.length; + uint256 pos = _upperBinaryLookup(self._checkpoints, key, 0, len); return pos == 0 ? 0 : _unsafeAccess(self._checkpoints, pos - 1)._value; } @@ -49,13 +49,13 @@ library Checkpoints { require(blockNumber < block.number, "Checkpoints: block not yet mined"); uint32 key = SafeCast.toUint32(blockNumber); - uint256 length = self._checkpoints.length; + uint256 len = self._checkpoints.length; uint256 low = 0; - uint256 high = length; + uint256 high = len; - if (length > 5) { - uint256 mid = length - Math.sqrt(length); + if (len > 5) { + uint256 mid = len - Math.sqrt(len); if (key < _unsafeAccess(self._checkpoints, mid)._blockNumber) { high = mid; } else { @@ -205,7 +205,7 @@ library Checkpoints { return high; } - function _unsafeAccess(Checkpoint[] storage self, uint256 pos) private view returns (Checkpoint storage result) { + function _unsafeAccess(Checkpoint[] storage self, uint256 pos) private pure returns (Checkpoint storage result) { assembly { mstore(0, self.slot) result.slot := add(keccak256(0, 0x20), pos) @@ -238,17 +238,17 @@ library Checkpoints { * @dev Returns the value in the oldest checkpoint with key greater or equal than the search key, or zero if there is none. */ function lowerLookup(Trace224 storage self, uint32 key) internal view returns (uint224) { - uint256 length = self._checkpoints.length; - uint256 pos = _lowerBinaryLookup(self._checkpoints, key, 0, length); - return pos == length ? 0 : _unsafeAccess(self._checkpoints, pos)._value; + uint256 len = self._checkpoints.length; + uint256 pos = _lowerBinaryLookup(self._checkpoints, key, 0, len); + return pos == len ? 0 : _unsafeAccess(self._checkpoints, pos)._value; } /** * @dev Returns the value in the most recent checkpoint with key lower or equal than the search key. */ function upperLookup(Trace224 storage self, uint32 key) internal view returns (uint224) { - uint256 length = self._checkpoints.length; - uint256 pos = _upperBinaryLookup(self._checkpoints, key, 0, length); + uint256 len = self._checkpoints.length; + uint256 pos = _upperBinaryLookup(self._checkpoints, key, 0, len); return pos == 0 ? 0 : _unsafeAccess(self._checkpoints, pos - 1)._value; } @@ -368,7 +368,7 @@ library Checkpoints { function _unsafeAccess(Checkpoint224[] storage self, uint256 pos) private - view + pure returns (Checkpoint224 storage result) { assembly { @@ -403,17 +403,17 @@ library Checkpoints { * @dev Returns the value in the oldest checkpoint with key greater or equal than the search key, or zero if there is none. */ function lowerLookup(Trace160 storage self, uint96 key) internal view returns (uint160) { - uint256 length = self._checkpoints.length; - uint256 pos = _lowerBinaryLookup(self._checkpoints, key, 0, length); - return pos == length ? 0 : _unsafeAccess(self._checkpoints, pos)._value; + uint256 len = self._checkpoints.length; + uint256 pos = _lowerBinaryLookup(self._checkpoints, key, 0, len); + return pos == len ? 0 : _unsafeAccess(self._checkpoints, pos)._value; } /** * @dev Returns the value in the most recent checkpoint with key lower or equal than the search key. */ function upperLookup(Trace160 storage self, uint96 key) internal view returns (uint160) { - uint256 length = self._checkpoints.length; - uint256 pos = _upperBinaryLookup(self._checkpoints, key, 0, length); + uint256 len = self._checkpoints.length; + uint256 pos = _upperBinaryLookup(self._checkpoints, key, 0, len); return pos == 0 ? 0 : _unsafeAccess(self._checkpoints, pos - 1)._value; } @@ -533,7 +533,7 @@ library Checkpoints { function _unsafeAccess(Checkpoint160[] storage self, uint256 pos) private - view + pure returns (Checkpoint160 storage result) { assembly { diff --git a/scripts/generate/templates/Checkpoints.js b/scripts/generate/templates/Checkpoints.js index 61c398d8f..b78ed5ceb 100644 --- a/scripts/generate/templates/Checkpoints.js +++ b/scripts/generate/templates/Checkpoints.js @@ -49,17 +49,17 @@ function push( * @dev Returns the value in the oldest checkpoint with key greater or equal than the search key, or zero if there is none. */ function lowerLookup(${opts.historyTypeName} storage self, ${opts.keyTypeName} key) internal view returns (${opts.valueTypeName}) { - uint256 length = self.${opts.checkpointFieldName}.length; - uint256 pos = _lowerBinaryLookup(self.${opts.checkpointFieldName}, key, 0, length); - return pos == length ? 0 : _unsafeAccess(self.${opts.checkpointFieldName}, pos).${opts.valueFieldName}; + uint256 len = self.${opts.checkpointFieldName}.length; + uint256 pos = _lowerBinaryLookup(self.${opts.checkpointFieldName}, key, 0, len); + return pos == len ? 0 : _unsafeAccess(self.${opts.checkpointFieldName}, pos).${opts.valueFieldName}; } /** * @dev Returns the value in the most recent checkpoint with key lower or equal than the search key. */ function upperLookup(${opts.historyTypeName} storage self, ${opts.keyTypeName} key) internal view returns (${opts.valueTypeName}) { - uint256 length = self.${opts.checkpointFieldName}.length; - uint256 pos = _upperBinaryLookup(self.${opts.checkpointFieldName}, key, 0, length); + uint256 len = self.${opts.checkpointFieldName}.length; + uint256 pos = _upperBinaryLookup(self.${opts.checkpointFieldName}, key, 0, len); return pos == 0 ? 0 : _unsafeAccess(self.${opts.checkpointFieldName}, pos - 1).${opts.valueFieldName}; } `; @@ -73,8 +73,8 @@ function getAtBlock(${opts.historyTypeName} storage self, uint256 blockNumber) i require(blockNumber < block.number, "Checkpoints: block not yet mined"); uint32 key = SafeCast.toUint32(blockNumber); - uint256 length = self.${opts.checkpointFieldName}.length; - uint256 pos = _upperBinaryLookup(self.${opts.checkpointFieldName}, key, 0, length); + uint256 len = self.${opts.checkpointFieldName}.length; + uint256 pos = _upperBinaryLookup(self.${opts.checkpointFieldName}, key, 0, len); return pos == 0 ? 0 : _unsafeAccess(self.${opts.checkpointFieldName}, pos - 1).${opts.valueFieldName}; } @@ -88,13 +88,13 @@ function getAtProbablyRecentBlock(${opts.historyTypeName} storage self, uint256 require(blockNumber < block.number, "Checkpoints: block not yet mined"); uint32 key = SafeCast.toUint32(blockNumber); - uint256 length = self.${opts.checkpointFieldName}.length; + uint256 len = self.${opts.checkpointFieldName}.length; uint256 low = 0; - uint256 high = length; + uint256 high = len; - if (length > 5) { - uint256 mid = length - Math.sqrt(length); + if (len > 5) { + uint256 mid = len - Math.sqrt(len); if (key < _unsafeAccess(self.${opts.checkpointFieldName}, mid)._blockNumber) { high = mid; } else { @@ -248,7 +248,7 @@ function _lowerBinaryLookup( function _unsafeAccess(${opts.checkpointTypeName}[] storage self, uint256 pos) private - view + pure returns (${opts.checkpointTypeName} storage result) { assembly {