In many contracts, notably voting, there is a mapping of the kind mapping(address => bool) voted;

How many voters can be registered in that way? is there a size limit? will the contract need more and more gas for each query until it reaches the maximum gas limit?

what would happen if there are 100 million voters for example?


The cost of an addition to or a read from a mapping does not change with the number of keys mapped. The location of a value key is computed by sha3(key, p) where p is the storage slot that acts as the pointer of the mapping. As you can see the location of an individual value is random, and you may theoretically overwrite data from another key.

The total storage is 2^256 * 32 bytes, so there is, in practice, quite some time before you indeed overwrite old data.

If you have 100 million voters, that's 100 million storage slots used. You have, I believe, 1 chance in 10^69 of overwriting someone's vote on the next vote.


According to Is there a (theoretical) limit for amount of data that a contract can store? the maximum a single contract can store is around 1.46 GB of data.

So 100 million votes could be quite close to that limit.

  • 2
    A single contract has access to 2^256 slots of 32 bytes each. That's 3.6 * 10^75 TB of data. – Xavier Leprêtre B9lab Sep 13 '16 at 16:46

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.