Search code examples
ethereumsolidity

solidity: stack limit reached 1024(1023) when trying to burn


my code is throwing that weird error when I try to call the _burn() function. I have tried everything but nothing seems to fix it.

Code: https://gateway.pinata.cloud/ipfs/QmcH7bTj3Yzow8UD1i17NXtdPZyMUcVEtCuJqRLq325xyd


Solution

  • The EVM stack has 1024 slots available and every time a function calls another function, it reserves some space on the stack to store arguments, return values and local variables. The deeper is the call chain, the more slots you need and you eventually run out of slots if you go too deep.

    Normally 1024 slots is plenty and this does not happen. The most common situation where you can get this error is if you have a bug that results in infinite recursion. I haven't analyzed your code in detail but at a glance I see some potential for a call loop that would go like this: _burn() -> _transfer() -> _transferStandard() -> _reflectFee() -> _burn() -> ... Or, instead of _transferStandard(), it could also go through one of the other_transferXXX() functions.