I'd like to set lots of arguments in solidity functions. I wonder how many arguments contracts can handle. Does it depend on number of arguments or data size?
Asked
Active
Viewed 4,196 times
12
2 Answers
4
Someone who is more familiar with the compiler may know otherwise, but at least from looking at the code (libsolidity) that deals with parsing .sol contract code into the compiler, there doesn't appear to be a limit.
(I'm specifically looking at parseFunctionCallListArguments and parseFunctionCallArguments in Parser.cpp.)
Richard Horrocks
- 37,835
- 13
- 87
- 144
3
It looks like in order to avoid the Stack too deep, although function argument can take 16 parameters, the safest way is to avoid exceeding the 16 parameter number else you run into a Stack too deep error.
Peeman Arthur
- 31
- 1
Reference Link: https://docs.soliditylang.org/en/v0.8.2/introduction-to-smart-contracts.html#storage-memory-and-the-stack
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.
– Bharat Mallapur Mar 07 '21 at 23:57