Introduce Opcodes B0 DUPN and B1 SWAPN (ignore)

I mainly want to understand why only the 16 first elements of the stack can be interacted with, and start a conversation about introducing two opcodes that could allow for all stack elements to be brought forward

  • was there any security consideration when adding this limitation? (like, not allowing other functions to tamper with previous stack?)
  • was it just intended to keep the DUP and SWAP mechanic simple? (by not needing to deal with the N element of the stack)
  • if DoS, could it get compensated by increasing gas costs?

DUPN: pops the passed N and pushes the nth element of the stack (Nth considered after consuming the N)

[3, 10, 11, 12, 13, 14] =>
[13, 10, 11, 12, 13, 14]

SWAPN: pops the passed N and swaps the now first and nth element of the stack (Nth considered after consuming the N)

[3, 10, 11, 12, 13, 14] =>
[13, 11, 12, 10, 14]

N > 1023 reverts

gas could be larger than their shorter counterparts, if there were any DoS concerns

This was proposed many times, see latest version of the proposal at EIP-663: Unlimited SWAP and DUP instructions

1 Like