In other words, is there a limit on the amount of storage a contract can hold?
Suppose a field is an Array for instance, and the contract has a method for adding items. Can I keep calling the contract so it adds more and more data?
Ethereum Stack Exchange is a question and answer site for users of Ethereum, the decentralized application platform and smart contract enabled blockchain. It only takes a minute to sign up.Sign up to join this community
Yes, a contract has infinite internal storage.
But there are 2 limits to practicality: gas costs and the block gas limit.
Gas costs are discussed in: Is there anything stopping me from using the ethereum blockchain as data storage?
Furthermore, the block gas limit will limit how much computation, search, iteration, etc can be performed on the data.
No, contracts' internal storage cannot increment forever. However, it is fairly more than enough for all types of purposes.
The limits for all storage variables together is:
2^256 Keys of 32 bytes = 2^261 bytes .
This is: 115,792,089,237,316,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000 of Keys 32 bytes.
That is equal to: 3,705,346,855,594,120,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000 bytes.
Witch is in terabytes: 3,705,346,855,594,120,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000 terabytes
There are 2^256 different keys, and each key can store 32 bytes, so that's a total of 2^261 bytes that could be stored. That said, by then the Ethereum blockchain will probably break due to a hash collision
However, as @eth♦ suggest, you should also consider the gas cost and the block gas limits.
Moreover, if you are using a mapping, a collision may happen because the location of a value key is computed using the hash function
sha3(key, p). Check here for more details: Is there a maximum number of entries for a mapping?. But again this collision is a concern when your data size is about 2^160 or 2^80 bytes. And this is a very large storage to consider.