How does the EVM track the operations it performs when tallying up the gas cost of a tx?

For example when a word is pushed to the stack - there is nothing in the solidity code explicitly saying to push a word to the stack. I'm assuming there's some underlying, lower level code that has a "push to stack" callout that triggers the gas counter to add gas or something.

Is this correct? Could anyone point me in a direction where I might be able to find more info?

Thanks in advance.

1 Answer 1


The Ethereum Virtual Machine executes the bytecode that is present on the Ethereum blockchain. Each bytecode has a specific gas price that is defined in the consesus specification and can be looked up in the Ethereum yellow paper (at page 27).

When you write Solidity code then solc (the Solidity compiler) will convert this code into YUL, an intermediate language, before converting it into evm bytecode.

Note: As gas costs are constantly changing and the yellow paper is not always immediately updated it might make sense to look at a evm implementation for the latest gas costs. E.g ethereumjs-vm

  • So when each opcode is executed, there's like a counter that tallies up? Rather than some mechanism that reads the entire execution plan and tallying up before executing? Feb 3, 2022 at 7:17
  • Yes, this is how this is implemented by most evms
    – Richard
    Feb 3, 2022 at 7:29

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.