Variable length params for functions

It is common in many languages to support a variable number of function parameters of the same type. Solidity could benefit from this as well. Consider the case where you want to efficiently hash 1 or more values. Abi encode is very expensive in this case, and given a known number of input values to encode and hash you can write this much more efficiently in assembly. If you want to make a library for this you would have to make an overload of the efficient hashing function for each possible number of values to hash. A great language feature would be to allow passing in an arbitrary number of values and have them automatically wrapped into an array. For example:

_efficientHash(value1, value2, value3);

...

function _efficientHash(params bytes32[] values) internal pure returns (bytes32 hash) {
  ...
}

For an example of what this looks like in other languages, see Method parameters are passed by value. Modifiers enable pass-by-reference semantics, including distinctions such as read-only, and `out` parameters. Learn the different parameter passing modes and how to use them. The params modifier allows a series of optional arguments. - C# | Microsoft Learn
Params Keyword in C#

1 Like