Assumption 1:

If we create a local variable, call stack increases by 1, because we put this new local variable on the stack. if I create another local variable, it again increases by 1. So, with this logic, i shouldn't be able to create more than 1024 local variables ?

Assumption 2:

maybe solidity means 1024 of external calls . but as you can see, it justs says this:

External function calls can fail any time because they exceed the maximum call stack of 1024 It doesn't concrete and just say call stack of 1024 .

So, what does it mean exactly ? call stack increases even for local variables.

  • They are two different stacks. One is exclusively for external calls. It cannot be inspected from the EVM. The other one is used by EVM to store a manipulate data. – Ismael Feb 6 at 16:32
  • I know that stack is the same thing as call stack. Isn't this principle in the ethereum world the same ? – Nika Kurashvili Feb 6 at 16:39
  • They are two separate stacks, one is used by the contract for data manipulation, the other one is used when calling other contracts. Both have 1024 entries of 32 bytes each but they are different, they are not the same stack. – Ismael Feb 6 at 16:45
  • Do you think the same principle applies to other languages(python, c++, js) or it's only Ethereum where we need 2 different stacks ? because I saw that in normal languages, we only have 1 stack... – Nika Kurashvili Feb 6 at 16:46
  • Depends on the language and its abstraction level. I think Ethereum went that way to prevent a possible attacks by manipulation of the return address in the stack . – Ismael Feb 6 at 16:53

Stack in Solidity means same as it means in any other machine or virtual machine.

Stack is being allocated for call return addresses, function arguments and local variables.

Besides limited by gas consumption, transactions are limited by stack size and cannot push more than 1024 EVM words on the stack.

Probably the easiest place to study the stack usage in EVM, is PyEVM implementation.

  • I meant something else with my question. As seen in google, stack is the same as call stack. If that's so, call stack can reach 1024 even without calling more than 1 function(just creating 1024 local variables). I think this is not what solidity docs mean. They mean the function call depth. and their explanation is misguiding. What do you think ? – Nika Kurashvili Feb 6 at 14:13
  • "I think this is not what solidity docs mean." please if you are referring to any particular paragraph in the documentation link it, as I do not know what documentation you have been reading. – Mikko Ohtamaa Feb 6 at 14:19
  • We can correct Solidity documentation then. – Mikko Ohtamaa Feb 6 at 14:20
  • External function calls can fail any time because they exceed the maximum call stack of 1024 . That's all it says. nothing else. And I say the following: call stack is the same as stack. So 1024 limit can be reached without calling 1024 functions inside each other. How can it be reached ? just by creating 1024 local variables. The thing solidity's docs is misleading is that they mean 1024 as 1024 function calls inside each one and not 1024 call stack limit. makes sense ? – Nika Kurashvili Feb 6 at 14:23
  • Can you give me a link to the page where you read this text and I can go to edit it for you if there is any unclarity? – Mikko Ohtamaa Feb 6 at 14:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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