EIP-5656: MCOPY instruction

What do you mean by “memory expansion”?
AFAIK reading (MLOAD) from unwritten/uninitialized memory doesn’t expand it to the offset, only return the default value (0) which would fit your case

you can do this today with CALLDATACOPY or CODECOPY, which do not by themselves trigger memory expansion

any reference to a storage slot expands the memory. the user pays: Gmem * a + a^2 // 512 where “a” is the highest referenced slot (there’s a complex formula so that on each memory access that raises this total.
even MLOAD(highOffset) causes a memory expansion, and thus so is MCOPY.
so if you want to zero-out a block range by copying in zeroes from high offset, it will work, but cause a memory expansion.
So my suggestion was to define a certain very high offset as “always zero”, which means:

  • this memory range can’t be set with MSTORE/MCOPY
  • Referencing above this memory offset is always zero, and doesn’t cause memory expansion.
    The value itself should be high enough so it is infeasible to use it.
    e.g. 2**32 would cost 3*2**32 + (2**64/512), which obviously is out-of-gas
1 Like