From 6be0b410dcb77bc046cd3c960b4170368c502162 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Fri, 18 Dec 2020 01:51:48 +0000 Subject: [PATCH] Use explicit conversions between addresses and numbers (#2439) Co-authored-by: hrkrshnn Co-authored-by: cameel --- contracts/token/ERC1155/ERC1155Receiver.sol | 4 ++-- contracts/utils/Create2.sol | 2 +- contracts/utils/EnumerableMap.sol | 8 ++++---- contracts/utils/EnumerableSet.sol | 8 ++++---- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/contracts/token/ERC1155/ERC1155Receiver.sol b/contracts/token/ERC1155/ERC1155Receiver.sol index 7a4a342dce5..c546c328389 100644 --- a/contracts/token/ERC1155/ERC1155Receiver.sol +++ b/contracts/token/ERC1155/ERC1155Receiver.sol @@ -11,8 +11,8 @@ import "../../introspection/ERC165.sol"; abstract contract ERC1155Receiver is ERC165, IERC1155Receiver { constructor() internal { _registerInterface( - ERC1155Receiver(0).onERC1155Received.selector ^ - ERC1155Receiver(0).onERC1155BatchReceived.selector + ERC1155Receiver(address(0)).onERC1155Received.selector ^ + ERC1155Receiver(address(0)).onERC1155BatchReceived.selector ); } } diff --git a/contracts/utils/Create2.sol b/contracts/utils/Create2.sol index fee0510c36a..ec1a6f41ac9 100644 --- a/contracts/utils/Create2.sol +++ b/contracts/utils/Create2.sol @@ -54,6 +54,6 @@ library Create2 { bytes32 _data = keccak256( abi.encodePacked(bytes1(0xff), deployer, salt, bytecodeHash) ); - return address(uint256(_data)); + return address(uint160(uint256(_data))); } } diff --git a/contracts/utils/EnumerableMap.sol b/contracts/utils/EnumerableMap.sol index de6f3a526ce..2daa131905a 100644 --- a/contracts/utils/EnumerableMap.sol +++ b/contracts/utils/EnumerableMap.sol @@ -177,7 +177,7 @@ library EnumerableMap { * already present. */ function set(UintToAddressMap storage map, uint256 key, address value) internal returns (bool) { - return _set(map._inner, bytes32(key), bytes32(uint256(value))); + return _set(map._inner, bytes32(key), bytes32(uint256(uint160(value)))); } /** @@ -214,7 +214,7 @@ library EnumerableMap { */ function at(UintToAddressMap storage map, uint256 index) internal view returns (uint256, address) { (bytes32 key, bytes32 value) = _at(map._inner, index); - return (uint256(key), address(uint256(value))); + return (uint256(key), address(uint160(uint256(value)))); } /** @@ -225,13 +225,13 @@ library EnumerableMap { * - `key` must be in the map. */ function get(UintToAddressMap storage map, uint256 key) internal view returns (address) { - return address(uint256(_get(map._inner, bytes32(key)))); + return address(uint160(uint256(_get(map._inner, bytes32(key))))); } /** * @dev Same as {get}, with a custom error message when `key` is not in the map. */ function get(UintToAddressMap storage map, uint256 key, string memory errorMessage) internal view returns (address) { - return address(uint256(_get(map._inner, bytes32(key), errorMessage))); + return address(uint160(uint256(_get(map._inner, bytes32(key), errorMessage)))); } } diff --git a/contracts/utils/EnumerableSet.sol b/contracts/utils/EnumerableSet.sol index 5e22e821273..858312dd997 100644 --- a/contracts/utils/EnumerableSet.sol +++ b/contracts/utils/EnumerableSet.sol @@ -199,7 +199,7 @@ library EnumerableSet { * already present. */ function add(AddressSet storage set, address value) internal returns (bool) { - return _add(set._inner, bytes32(uint256(value))); + return _add(set._inner, bytes32(uint256(uint160(value)))); } /** @@ -209,14 +209,14 @@ library EnumerableSet { * present. */ function remove(AddressSet storage set, address value) internal returns (bool) { - return _remove(set._inner, bytes32(uint256(value))); + return _remove(set._inner, bytes32(uint256(uint160(value)))); } /** * @dev Returns true if the value is in the set. O(1). */ function contains(AddressSet storage set, address value) internal view returns (bool) { - return _contains(set._inner, bytes32(uint256(value))); + return _contains(set._inner, bytes32(uint256(uint160(value)))); } /** @@ -237,7 +237,7 @@ library EnumerableSet { * - `index` must be strictly less than {length}. */ function at(AddressSet storage set, uint256 index) internal view returns (address) { - return address(uint256(_at(set._inner, index))); + return address(uint160(uint256(_at(set._inner, index)))); }