We are currently testing functions on Ropsten test network and have an issue regarding the gas usage. Our functions sometimes use 12 gas more and we can not fathom why that would be the case. To test this we defined a function
function refund (bytes32 sessionId) public {
require (false);
...
}
It fails after the first line and reverts the transaction. We called it 30 times with different byte32 values approx. every 3min. Here are two transactions to this function with different gas usage:
https://ropsten.etherscan.io/tx/0xa48c4f09da3a8d57fc4061ecad27a3097c225ad3e524e81948e6d38461e41b1f
https://ropsten.etherscan.io/tx/0x3126bdcdb6c5fd569a85a9c95928b1fd8c856ded7047670064f0d4e965199fe8
The only difference there seems to be the nonce(duh), the block index position and a different 32 bytes long input (that is not used). Is there some calculation for the used gas that we are missing?
EDIT:
Tested with an even simpler contract on goerli.
pragma solidity ^0.5;
contract FairDataExchange {
function refund(bytes32 t) public{
}
}
Issue is the same here. Without parameter t this issue does not seem to come up (n=45).
Transactions on goerli:
1. https://goerli.etherscan.io/tx/0xd48b8ad613145af060489082507253786e6211fd34dfbe641c10f5e03b82f3d8
2. https://goerli.etherscan.io/tx/0x434a546e43f2e2bfc5bf509f67fd8543506e9223b0d52fa41213063ca90595b7
x++
will cost a lot more the first time it is called (changingx
from zero to non-zero), than every other time it is called (changingx
from non-zero to non-zero). Show what your function does, and we'll be able to point it out more accurately.require(false)
always fails. But that doesn't explain the difference in some executions.