I have a set of address values, each of them can contain a real Ethereum account (user account or contract) or a "virtual" address (an address pseudo-randomly generated by my contract, in fact first 160 bits of an NFT token ID).

I want virtual addresses to be distinguished from real accounts by being less than a certain 2**N.

I generate a virtual address like this:

address next = address(truncate(keccak256(abi.encodePacked(previous))));

where truncate() takes the lower N bits.

How to choose N for both:

  • low probability that a real address will be less than 2**N and mistook for a virtual address;
  • low probability that two virtual addresses will clash.
  • An address bits should be random since they are derived from a strong hash function keccak. So having an address withe the first N bits set to zero has probality 1/(2**N). I've seen vanity addresses with non random 11 hex digits (N=44), perhaps N=80 is good enough.
    – Ismael
    Mar 4 '21 at 20:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.