Using the sum of hashes of addresses might not prevent collisions, as different sets of addresses could potentially result in the same root hash.
A more secure approach would be to use a data structure specifically designed for maintaining sets, such as a Merkle tree.
Merkle trees provide cryptographic security by ensuring that any change to the set of addresses will lead to a different root hash. This allows for efficient verification of the integrity of the address set.
Here's a simplified overview of how you could use a Merkle tree for this purpose:
- Construct a Merkle tree with the addresses as leaf nodes.
- Store the root hash of the Merkle tree in your smart contract.
- To verify the integrity of the address set, participants can provide the Merkle proof (a path from the leaf node to the root) along with their claimed address.
- The smart contract can then verify the Merkle proof to ensure that the claimed address is indeed part of the original set.
This approach provides both efficiency and cryptographic security, making it suitable for maintaining sets of addresses in a smart contract.
This medium article might be helpful.