0

I know that the EVM wants to charge for reading from slots, and even more for writing to those slots. That all makes sense.

My question is, whether the EVM is smart enough to store in memory the temporary values, before writing it to storage when the transaction commits (ends without reverting).

Meaning, I would expect to be paying the same gas whether I write to a slot once, or whether I write to it, read from it, write to it, read from it multiple times. The EVM should mark that slot as "used", not "used N times".

Is this how EVM works? I understand that if I read from the slot first, and then write to it, then I might incur two gas fees, but if I write to it and read and write multiple times then it shouldn't charge me every time, right?

The reason I ask is because I want to make a "MicroMapping" of uint16 values, and I want to know if I have to write my own manual batching, or whether I can write multiple times to the same slot (calling the same setMicroMapping(index, key, value)) and keeping the code clean.

Any advice?

1 Answer 1

1

Writing multiple times to a specific storage slot is cheaper, but not free.

The current state is defined by EIP-2929

Edit:

Since you asked about temporary or so called transient storage. There is an EIP that is aimed towards this: EIP-1153

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.