Solidity Limitation For Variable Updates/Emits

I have tried looking into if I can find any information about what limitations Solidity has in regards to how many times it can store information, read information, etc. in one contract interaction.

In general, all the information I am locating is that it depends on the gas you want to use.

Though I have run into a case, where the contract is using a little over 400k gas and fails with an “out of gas” error.

Then if I comment out a variable assignment or a few variable reads, it is able to run again. This makes me wonder if there is a hard number on how many times you can read/write that is not tied to the gas.

1 Like

Hi @sven,

I assumed that it was purely as gas limit for a transaction, though the gas used will vary depending on what you are doing. Feel free to post links to any documentation to expand the knowledge base.

From: https://docs.soliditylang.org/en/v0.7.5/introduction-to-smart-contracts.html?highlight=gas#message-calls

Calls are limited to a depth of 1024, which means that for more complex operations, loops should be preferred over recursive calls. Furthermore, only 63/64th of the gas can be forwarded in a message call, which causes a depth limit of a little less than 1000 in practice.

From: https://docs.soliditylang.org/en/v0.7.5/security-considerations.html#gas-limit-and-loops

Loops that do not have a fixed number of iterations, for example, loops that depend on storage values, have to be used carefully: Due to the block gas limit, transactions can only consume a certain amount of gas. Either explicitly or just due to normal operation, the number of iterations in a loop can grow beyond the block gas limit which can cause the complete contract to be stalled at a certain point.

Also worth looking at the About Gas section of Falsehoods that Ethereum programmers believe:

1 Like