0

I cannot find any good source on this. The "normal" stack is where all PUSH opcodes put their bytes on. The "call stack" could be some other stack where either call data or addresses are put on - which doesn't make any sense to me if it would be a different stack.

Is the call stack a different stack than the "normal" stack?

1 Answer 1

3

The normal stack is what you describe. This is where the basic opcodes take their operands.

The call stack is in relation to calls between contracts.

You see, when you send a transaction to a smart contract, the execution there starts with an empty memory and an empty normal stack.

  • That is true when you sign a transaction and send it to a contract.
  • That is also true when your contract A creates a transaction to call another smart contract B.

In the second case:

  • When the execution enters A, the memory and normal stack are empty.
  • When the execution leaves A, the memory and normal stack have been populated with stuff A did.
  • When the execution enters B, the memory and normal stack are empty.
  • When the execution leaves B and returns to A, the EVM needs to:
    • flush the memory and normal stack as last seen by B
    • and restore, for A, the memory and normal stack to what they were when it left A.

So where did this backup of the state of memory and normal stack go? It was pushed onto the call stack. When this state is popped from the call stack, it is restored into memory and normal stack.

2
  • Aha so memory is used to backup the stack. Since adding more items to memory increases the gas price for the added items this would make call depth attacks impossible because all of these attacks (up until a very high gas block limit) would run in out-of-gas.
    – JBrouwer
    Jul 6, 2018 at 13:58
  • Memory of your node is used for the call stack. The bigger the EVM memory, the bigger the cost in your node memory. Remember how expanding the EVM memory costs gas? That's why. Jul 6, 2018 at 16:54

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.