2

When my code creates or modifies a contract there is a gas cost. But when my code makes a call that does not modify a contract (e.g. reads existing data) it doesn't appear that I'm required to pay gas.

If the above is correct, what happens if a pure or constant function requires a large number of CPU cycles? For example, instead of just returning existing data a function calculates a large number of hash operations. If I can make this call without providing gas, who "pays" for those calculations?

2 Answers 2

2

If I can make this call without providing gas, who "pays" for those calculations?

It depends on which node you're querying the data on.

If you're running your own full node on your own machine, then that's where the CPU cycles are happening.

If you're using a third-party node, such as Infura, then likewise, they incur the CPU cost.

2
  • Thank you. Doesn't this mean though that it would be possible to bog down any node simply by creating a contract with cpu-heavy, pure functions? Commented Apr 5, 2018 at 20:07
  • 1
    Good question. I'm not sure how your local EVM would cope if you continuously hammered it by calling a deliberately dense contract. Might be a good follow-up question. With regards to Infura, the following explains some of how read requests are handled: Scaling INFURA: Not All API Calls are Equal Commented Apr 5, 2018 at 20:52
1

You have to remember the blockchain is distributed redundantly. Whatever node you connect to is able to execute the read-only call locally.

If you're running a node then you're paying for the call via the CPU and disk you bought.

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.