0

We know that gas fees are paid only when the state is changed.

Suppose that I write a contract that manages a big list of elements and that I decide to implement a lookup method that simply loops over all the nodes until it finds the one to return.

If the list contains billions of records, this operation will cost a lot of CPU time.

How does Ethereum protect itself from this?

5
  • 1
    And where did you find the info that gas fees are only paid when the state is changed? Jul 23, 2021 at 19:47
  • It's written in a lot of online documentation. I know that it is not always free, if for example you call the same function while running a transaction, but the question is when you are not in a transaction, you are still using CPU.
    – Ward Clark
    Jul 23, 2021 at 21:27
  • Understood you now. Keep in mind that I can delete view keyword from the getter function and it will cost gas to execute it so the state changing is not a requirement for charging fee. Jul 23, 2021 at 21:42
  • Though I'm sure there are no restrictions because every provider decides for itself how to protect from users. I mean that's why they have an API key for each user. So they will punish you if you continuously call functions that require high resources consumption. Jul 23, 2021 at 21:57
  • Because if there were such restrictions that would mean there was a problem in accessibility of data which is one of the core principles of the blockchain technology. Jul 23, 2021 at 22:07

1 Answer 1

0

Ethereum requires fees for every single opcode (that is assembly primary operation). This is the OUTDATED opcode prices table. There could be some changes made to it, the most serious one I know about for sure is SLOAD - changed from 200 to 2100. Though there are some nuances. See this for the reference.

When there is a billion records in the list the transaction gas just won't fit in the block meaning miners will just stop executing it once it bumps into the gas limit. And it will revert.

4
  • Are you saying that even view and pure functions cost gas fees?
    – Ward Clark
    Jul 23, 2021 at 21:05
  • Yes, if they are executed by a miner that is they're called inside the function that is not a pure or a view. If not then you would just crash your own node you use to execute them. Jul 23, 2021 at 21:10
  • As far as I know I can call, for example, Infura nodes using web3. If that's true, the local node is not necessarily yours.
    – Ward Clark
    Jul 23, 2021 at 21:14
  • I think Infura will trace you back and block you if you try to do that) Jul 23, 2021 at 21:16

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.