EIP-7912: Pragmatic expansion of stack manipulation tools

PR: Add EIP: Pragmatic expansion of stack manipulation tools by lightclient · Pull Request #9501 · ethereum/EIPs · GitHub

Add SWAP17-SWAP24, DUP17 - DUP24, SWAPN, DUPN, and EXCHANGE

instructions. The arbitrary depth operations must be preceded by PUSH1 instructions defining operands.

1 Like

The argument X must be provided by a PUSH2 operation immediately preceding the EXCHANGE instruction

This argument must be provided by a PUSH1 operation immediately preceding the SWAPN and DUPN instructions.

Why not just read from the stack and exceptional-halt if the param is too large?

Why not just read from the stack and exceptional-halt if the param is too large?

You do read them from the stack, but this simplifies static analysis i) by ensuring the operand is available directly before the instruction and ii) avoiding dynamic stack manipulation by using values from calldata or storage as the operand.

We really need this more than the entire EOF. Even though the Solidity compiler might have fixed its “stack-too-deep” errors by putting local variables into memory.

Why burn 17 opcodes for the fixed values and add 2 dynamic ones for same gas that do the same thing?

Also the 4 dynamic opcodes have 34 byte code look backs so 3 gas seems very low?

I think we have ample opcodes left and stack-too-deep is a common issue. The static N versions relieve some pressure efficiently while the dynamic N versions support much deeper stack manipulation at a slightly higher cost.

Yeah 3 has could be too low, will have to see how expensive the look back ends up being. Could also consider doing look after.