Use explicit conversions between addresses and numbers (#2439)

Co-authored-by: hrkrshnn <webmail.hari@gmail.com>
Co-authored-by: cameel <cameel2@gmail.com>
pull/2443/head
Alex Beregszaszi 4 years ago committed by GitHub
parent 051d340171
commit 6be0b410dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      contracts/token/ERC1155/ERC1155Receiver.sol
  2. 2
      contracts/utils/Create2.sol
  3. 8
      contracts/utils/EnumerableMap.sol
  4. 8
      contracts/utils/EnumerableSet.sol

@ -11,8 +11,8 @@ import "../../introspection/ERC165.sol";
abstract contract ERC1155Receiver is ERC165, IERC1155Receiver { abstract contract ERC1155Receiver is ERC165, IERC1155Receiver {
constructor() internal { constructor() internal {
_registerInterface( _registerInterface(
ERC1155Receiver(0).onERC1155Received.selector ^ ERC1155Receiver(address(0)).onERC1155Received.selector ^
ERC1155Receiver(0).onERC1155BatchReceived.selector ERC1155Receiver(address(0)).onERC1155BatchReceived.selector
); );
} }
} }

@ -54,6 +54,6 @@ library Create2 {
bytes32 _data = keccak256( bytes32 _data = keccak256(
abi.encodePacked(bytes1(0xff), deployer, salt, bytecodeHash) abi.encodePacked(bytes1(0xff), deployer, salt, bytecodeHash)
); );
return address(uint256(_data)); return address(uint160(uint256(_data)));
} }
} }

@ -177,7 +177,7 @@ library EnumerableMap {
* already present. * already present.
*/ */
function set(UintToAddressMap storage map, uint256 key, address value) internal returns (bool) { 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) { function at(UintToAddressMap storage map, uint256 index) internal view returns (uint256, address) {
(bytes32 key, bytes32 value) = _at(map._inner, index); (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. * - `key` must be in the map.
*/ */
function get(UintToAddressMap storage map, uint256 key) internal view returns (address) { 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. * @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) { 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))));
} }
} }

@ -199,7 +199,7 @@ library EnumerableSet {
* already present. * already present.
*/ */
function add(AddressSet storage set, address value) internal returns (bool) { 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. * present.
*/ */
function remove(AddressSet storage set, address value) internal returns (bool) { 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). * @dev Returns true if the value is in the set. O(1).
*/ */
function contains(AddressSet storage set, address value) internal view returns (bool) { 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}. * - `index` must be strictly less than {length}.
*/ */
function at(AddressSet storage set, uint256 index) internal view returns (address) { 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))));
} }

Loading…
Cancel
Save