EIP-663: Unlimited SWAP and DUP instructions

Discussion topic for

@axic Where does the 1024 item limit come from? This seems out of line with the semantics of the current DUP* instructions. Also, is there currently any consensus on which of the three options to go with?

It is the core design of EVM, see the Yellow Paper page 11:

The EVM is a simple stack-based architec-ture. The word size of the machine (and thus size of stackitems) is 256-bit. This was chosen to facilitate the Keccak-256 hash scheme and elliptic-curve computations. Thememory model is a simple word-addressed byte array. Thestack has a maximum size of 1024.

Thanks, I see it now in the exceptional halting conditions too:

This states that the execution is in an exceptional halt-ing state if there is insufficient gas, if the instruction is invalid (and therefore its δ subscript is undefined), if there are insufficient stack items, if a destination is invalid, the new stack size would be larger than 1024 or state modification is attempted during a static call.

If the current stack depth is at the limit, a stack overflow exception is issued.

SWAP instructions do not increase the stack height so this sentence do not apply.
It is not true for Option A where an additional argument is popped from the stack (so SWAP decreases stack and DUP keeps it the same height).

I prefer the immediate argument form, as I think in most all cases the swap or dup offset will be constant. Variable offsets might help if you want to treat the stack more like an array in memory, but we have memory for that.

It must be specified if we count stack items from 0 or 1. I.e. is the top stack item an item at depth 0 or 1?

Currently, the spec for SWAPn is incorrect.

the top stack item is swapped with the item at depth n

For n referring the stack top item the instruction will swap the top item with itself.

Following the current convention, instructions should be named all uppercase.