how does the size of the "actions" object affects gas cost ? What's the increment in gas, between an "actions.length = 2" and an "actions.length = 3" ?
I see the other answers talk about how memory, computation, and storage affects the gas usage, but it seems to me your question is about how more arguments or larger lists affects gas usage, without considering memory, computation and storage, so here it is:
One of the parameters that affect the amount of gas used in a transaction is the "input data", it costs 4 gas for every zero byte and 16 gas for every non-zero byte. You can read more details here.
When you pass an array, let's say [1, 2]
to a function argument, the transaction data will be:
FFFFFFFF <- The first 4 bytes of the sighash
0000000000000000000000000000000000000000000000000000000000000060 <- signal that an array will start
0000000000000000000000000000000000000000000000000000000000000002 <- the array size (size of [1, 2] is 2)
0000000000000000000000000000000000000000000000000000000000000001 <- first item of array
0000000000000000000000000000000000000000000000000000000000000002 <- second item of array
Note that everything after the sighash has a 32 byte size.
0x60 and then 0x2 (0x2 = size of array) is just how RLP encoding works, it's a way to tell the virtual machine that an array will start and how large it is.
Every 2 digits in hexadecimal represents a byte. You can calc how much more gas will be spent by multiplying the amount of "00"s by 4 and the amount of non "00"s by 16.
By looking at the example above, both items '1' and '2' in the array will spend 140 more gas because they have 1 non-zero byte and 31 zero-byte (16 * 1 + 4 * 31) = 140 gas
If the array has one more item, let's say '3', like [1, 2, 3]
, it would cost 140 more gas. Because the number 3 also only uses 1 of the 32 bytes.
If the array has a number that uses all bytes, for example:
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
Then this specific number would add a cost of 32 * 16 = 512 gas
to the transaction.