Even though functions called with staticcall cannot modify the state, I ran into an issue when (accidentally) calling a non-view/pure function using staticcall. For example, using this contract:
pragma solidity 0.8.3;
contract TestContract {
address public foo;
function setFoo(address _foo) external {
foo = _foo;
}
function doFoo(address _target, address _foo) external returns (bool success) {
(success,) = _target.staticcall(abi.encodeWithSignature("setFoo(address)", _foo));
}
}
Calling doFoo() in Remix, with the contract address of TestContract as _target, and another random address as _foo, the total gas consumption is 2,953,792. The gas limit is set to 3,000,000. Changing the gas limit to 30,000,000 will result in a gas consumption of about 29 million gas, so it looks like it´s using up the entire gas limit.
Why does staticcall have this behaviour?