EIP-7686: Linear EVM memory limits

I make a lookup table below, and the current memory limit of 300e6 gas limit is about 12MB.

Size (KB) Linear Gas Term Quadratic Gas Term Sum
1 96 2 98
4 384 32 416
16 1,536 512 2,048
32 3,072 2,048 5,120
64 6,144 8,192 14,336
128 12,288 32,768 45,056
256 24,576 131,072 155,648
512 49,152 524,288 573,440
1,024 98,304 2,097,152 2,195,456
3,849 369,504 29,629,602 29,999,106
12,223 1,173,408 298,803,458 299,976,866

Note that, one interesting attack to bypass the existing quadratic term is to spread the memory to multiple call stacks. E.g., I can allocate 1MB to two call stacks, each allocating 512KB instead of 1MB in one call stack. As a result, the memory gas cost is reduced from 2,915,456 to 573,440 * 2 = 1,146,880.

Taking gas limit = 300e6 as an example, recursively calling a contract that allocates 256KB in each call stack can allocate 54MB of total memory, which is still much smaller than 300MB of this EIP.

gas_limit = 300 * 10 ** 6
mem_size = 0
while gas_limit >= 155648:
    mem_size = mem_size + 256 * 1024
    gas_limit = (gas_limit - 155648) * 63 // 64
mem_size # return 57409536 ~ 54MB

The 10x cap of Infura can be found here. Alchemy has an even higher gas limit of 550M.

One application as I mentioned is EVM as a decentralized HTTP server in ERC-4804/6860, where an eth_call may return a large composed HTML from EVM (potentially call an L2 to have lower storage cost). There may be other applications that I am not aware of.

1 Like