1

In other words, do any opcodes pop a variable number of elements from the stack?

The Ethereum Virtual Machine allows up to 1024 elements on the stack, so it should be possible to allow a variable number of inputs as long as this limit is respected.

2 Answers 2

3

As of 2023-10-01 all opcodes take a fixed number of stack inputs. https://ethereum.org/en/developers/docs/evm/opcodes/

Some opcodes, like call, accept an arbitrary amount of data, but they receive the length and a pointer to memory through the stack.

4
  • Thanks for your answer. Can you think of any blocker for having an opcode read a variable amount of inputs from the stack? Commented Oct 2, 2023 at 9:24
  • For context: I'm working on a rollup that implements a modified EVM Commented Oct 2, 2023 at 9:25
  • @PaulRazvanBerg Interpreting a trace will be a little more complicated. Nothing serious though.
    – Ismael
    Commented Oct 2, 2023 at 20:20
  • Thank you ser!! Commented Oct 4, 2023 at 10:41
-1

The EVM is not a register machine but a stack machine, so all computations are performed on a data area called the stack. It has a maximum size of 1024 elements and contains words of 256 bits. Access to the stack is limited to the top end in the following way: It is possible to copy one of the topmost 16 elements to the top of the stack or swap the topmost element with one of the 16 elements below it. All other operations take the topmost two (or one, or more, depending on the operation) elements from the stack and push the result onto the stack. Of course it is possible to move stack elements to storage or memory in order to get deeper access to the stack, but it is not possible to just access arbitrary elements deeper in the stack without first removing the top of the stack.

https://docs.soliditylang.org/en/v0.8.21/introduction-to-smart-contracts.html#storage-memory-and-the-stack

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.