Environment
Truffle v4.1.8
node 10.0.0
pragma solidity ^0.4.21;
Issue
I'm calling the claimRefund
function on my smart contract using metamask. When calling the function with 37081 gas limit at 20 gwei gas price, the transaction spends 36924 gas and gets reverted with EVM Revert.
If I change params to 58080 gas limit at 20 gwei gas price, the transaction passes spending 24721 gas.
The code is shown below:
/**
* @param investor Investor address
*/
function refund(address investor) public {
require(state == State.Refunding);
uint256 depositedValue = deposited[investor];
deposited[investor] = 0;
investor.transfer(depositedValue);
emit Refunded(investor, depositedValue);
}
}
function claimRefund() public {
require(isFinalized);
require(!goalReached());
vault.refund(msg.sender);
}
Question
How is it possible that the same call results in a different gas spent amount? Also, how can a function fail after spending more gas and pass after spending less gas?
goalReached()
would also help.