ethereum / execution-specs

Specification for the Execution Layer. Tracking network upgrades.
Creative Commons Zero v1.0 Universal
827 stars 231 forks source link

Are gas payment and execution for opcodes/precompiles separate? #493

Open petertdavies opened 2 years ago

petertdavies commented 2 years ago

It seems that in practice the EVM is structured so that gas payment for an operation and execution of that operation are separate. This leads to a bunch of behaviour that is otherwise counter-intuitive. For example, CALL extends memory to include all the space allocated for return data, even though not all of that memory actually gets written to.

We should consider explicitly emulating this structure in the specs.

voith commented 2 years ago

CALL extends memory to include all the space allocated for return data, even though not all of that memory actually gets written to

I agree with you that it seems counter-intuitive. But it seems like the EVM was never designed with efficiency in mind. Sadly, If we don't execute the operations the way they are executed now, they break consensus. Also, gas payment needs to happen in a certain order; else, gas consumed doesn't match in case the message call results in an error.