Stack too deep, try removing local variables.
DApp developers will get the following error message, if there are too many local variables.
Stack too deep, try removing local variables.
This is a common issue for stack-based virtual machine, specifically FastVM and EVM. Only the top N stack items can be read/written; therefore, all high level languages on top of it has to limit the number of local variables which are stored on the stack.
Both Aion and Ethereum's solidity have the same limit on number of local stack items where local variables can occupate. However, the actual number of local variables are typically less in Aion's platfrom, because some local variable may take more than one stack item. For example, variable of address type will take two 128-bit stack items in Aion, while only one 256-bit stack item in Ethereum.
I believe the only solution to make Aion Solidity support more local variables is to update the FastVM by:
- Introduce
DUP17-DUP32andSWAP17-SWAP32; - OR add new opcodes
DUPXandSWAPXwhich take on argument specifying the N-th stack item to operate on. - OR add new opcodes
DUP + (1 byte offset)andSWAP + (1 byte offset)which take a number of arguments as specified in the next byte.
solution one would have the lowest cost. DUPX's max depth is up to 256*16 bytes = 4KB, cache miss should be under consideration. data access from ddr will cost much more.