foundry
foundry copied to clipboard
Allow setting gas limits for individual transactions inside scripts using solidities `{gas: x}` syntax
Component
Forge
Describe the feature you would like
Summary
Allow the user to hardcode gas limits on individual transactions inside a forge-script using standard solidity syntax. This hardcoded value should override / have preference over existing gas estimation logic.
Example
In the below example the first call to someFunction
should be executed with exactly the specified gas limit both in simulation as well as on broadcast.
The second call to this function (as well as the contract deployment) should have its gas limit estimated the same way as usual.
contract SomeContract {
function someFunction() external {
}
}
contract SomeScript is Script {
function run() public {
vm.startBroadcast();
SomeContract someContract = new SomeContract();
someContract.someFunction{gas: 12345}();
someContract.someFunction();
vm.stopBroadcast()
}
}
Additional context
No response
+1 to the issue, but instead of introducing new syntax, perhaps vm can respect the ether balance of an address?
For e.g., following should throw meaningful "not enough gas"
contract SomeContract {
function someFunction() external {
}
}
contract SomeScript is Script {
function run() public {
SomeContract someContract = new SomeContract();
vm.deal(address(0), 0);
vm.prank(address(0));
someContract.someFunction();
}
}
These are different: your example gives the account a balance, @ckoopmann's example uses native Solidity syntax to specify the gas limit of a transaction
I had a problem today with the lack of this feature.
The pattern checks for enough remaining gas in someFunction
, and it passes the trace and the on-chain simulation but fails on the broadcast. For now, I solved the problem by specifying --gas-estimate-multiplier
(#2524) at runtime.
+1 would love to have this!
This would be nice when using --skip-simulation
and gas estimation fails. Gas estimation failure happens frequently with txs that may fail due to randomness, etc. but you may want to attempt the submission regardless.