In a sample ERC721 contract linked from a loom-network medium post, I saw this code:
bytes4 constant InterfaceSignature_ERC721 =
bytes4(keccak256('name()')) ^
bytes4(keccak256('symbol()')) ^
bytes4(keccak256('totalSupply()')) ^
bytes4(keccak256('balanceOf(address)')) ^
bytes4(keccak256('ownerOf(uint256)')) ^
bytes4(keccak256('approve(address,uint256)')) ^
bytes4(keccak256('transfer(address,uint256)')) ^
bytes4(keccak256('transferFrom(address,address,uint256)')) ^
bytes4(keccak256('tokensOfOwner(address)')) ^
bytes4(keccak256('tokenMetadata(uint256,string)'));
Why is the bitwise XOR (^) operation used to join these values together?
I understand this is a cheap and efficient way to "mix" all of these hashes together, but I'm not sure if this is "safe" in terms of collisions and other weirdness, is this standard practice or just a simple hack to arrive at a probably-safe "unique" signature?
Code source: Line 481 on https://ethfiddle.com/09YbyJRfiI
^is bitwise XOR. – user19510 Mar 07 '18 at 02:30