I discovered that addresses can be obfuscated so that the address is not in the contract's memory, but instead the contract stores a hashed version of the address. Then it can be checked later by performing the same hash. If someone checks every ethereum address then they could figure out which one it is. It would only take a few seconds to compute. However, I think if it's an unknown address that hasn't made any transactions then it would be private because it uses a secure hash function. But it would only be private until that account makes its first transaction.
Here is an example with code:
```
bytes32 public accountHash;
bytes32 public salt;
constructor(bytes32 _accountHash, bytes32 _salt) {
accountHash = _accountHash;
salt = _salt;
}
function checkAddress(address a) public view returns (bool) {
bytes memory toHash = bytes.concat(abi.encodePacked(a), salt);
bytes32 hash = sha256(toHash);
return hash == accountHash;
}
function doSomething() public {
require(checkAddress(msg.sender));
// do whatever you want here
// only the hashed account will be able to run this code
}
```
Was this already known?
Has anyone ever used this in a contract before?
Should this be allowed? If not then how could the protocol prevent it?
[link] [comments]
You can get bonuses upto $100 FREE BONUS when you:
π° Install these recommended apps:
π² SocialGood - 100% Crypto Back on Everyday Shopping
π² xPortal - The DeFi For The Next Billion
π² CryptoTab Browser - Lightweight, fast, and ready to mine!
π° Register on these recommended exchanges:
π‘ Binanceπ‘ Bitfinexπ‘ Bitmartπ‘ Bittrexπ‘ Bitget
π‘ CoinExπ‘ Crypto.comπ‘ Gate.ioπ‘ Huobiπ‘ Kucoin.
Comments