12

I have some further questions about this and this threads.

For simplicity, let's imagine that I want to create a cryptocurrency on top of ethereum.

The contract that "handles" this cryptocurrency will have a mapping that will associate addresses to balances.

Now, let's imagine that this turns out as a very popular currency, used by millions of people around the world, making billions of transactions per year.

As more and more people starts "registering" to use this coin, the storage use of the contract grows indefinetly.

Questions:

  1. How much of the storage needs to be loaded in memory in order to make the contract execute?
  2. Does the size of storage influence the amount of memory needed to execute it?
  3. Is all this data always stored in the chain data? Or some of it goes to the state data?
  4. How exactly an increasing contract storage also increases gas spending?

1 Answer 1

15

Stored data is stored entirely in the state. None of the storage needs to be loaded into VM memory in order to execute transactions on the contract, other than those entries that your contract explicitly loads in code.

As a result, gas costs are independent of the amount of stored data you have (unless you're doing something like iterating over every stored value). You're charged gas for storing or updating a value, charged a much smaller amount of gas to retrieve data from state, and refunded some gas for deleting values from storage.

5
  • Thank's for your answer. Are you saying that this answer doesn't make sense? Commented Apr 14, 2016 at 14:28
  • @HenriqueBarcelos That answer is correct, but it's talking about how much computation you can do in a single transaction. If you have a lot of stored data, but only want to access a fixed amount per transaction, your costs won't go up. Commented Apr 14, 2016 at 14:30
  • I see. In your answer you've said that only the entries my contract explicitly loads in code are loaded in memory. Could you give more details on how this happens? How is this data fetched from the storage? Commented Apr 14, 2016 at 14:35
  • @HenriqueBarcelos It's loaded whenever you access it - such as with var blah := my_storage_map[foo]. More details of how this is implemented at the EVM and Solidity levels are probably out of scope for this question and for a comment. :) Commented Apr 14, 2016 at 14:39
  • I just register in this site to vote up for your question. Can you provide any link from a trusted site (ethereum, solidity) that confirm your answer?. If this is true I will be very happy. Thanks in advance. @NickJohnson
    – RJardines
    Commented May 16, 2019 at 3:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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