I've been getting more familiar with solidity, but I'm trying to learn more about gas optimisation. For example...

If you have the same function in two different smart contracts, but one contract is much longer and more complex than the other, is the gas consumption still identical?


  • Refer this answer ethereum.stackexchange.com/a/37898/79294
    – pbsh
    Commented Feb 2, 2022 at 18:32
  • @pbsh, thanks for that. It was a worthwhile read! But the question is less about deployment and more gas consumption when making function calls.
    – RaaaCode
    Commented Feb 3, 2022 at 12:48

3 Answers 3


Yes. Gas is a measure of the resources used to execute a function including both compute and storage.


Doing more computational work means more gas. Saving to storage is by far the highest gas cost. Here is a breakdown of gas cost to each respective op code.



No, it depends on what every single line is doing.

You can have a function with a lot of lines with simple operations in memory, which costs a lot less than a single line of code doing complex operations like ecrecover, hashing, calling other smart contracts, etc.

Also, Solidity is compiled in EVM codes, the actual smart contract.

And again, a more extended sequence of EVM codes does not mean more costs; it depends on how much that code costs in the EVM.

You can consult the Yellow Paper to check the cost for each EVM code.

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.