Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting gas limits for individual transactions inside scripts using solidities {gas: x} syntax #2627

Closed
ckoopmann opened this issue Aug 5, 2022 · 7 comments · Fixed by #4219
Labels
C-forge Command: forge Cmd-forge-script Command: forge script D-average Difficulty: average P-low Priority: low T-feature Type: feature

Comments

@ckoopmann
Copy link
Contributor

ckoopmann commented Aug 5, 2022

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-om
Copy link

1-om commented Aug 7, 2022

+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();
       }
}

@onbjerg
Copy link
Member

onbjerg commented Aug 8, 2022

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

@onbjerg onbjerg added C-forge Command: forge P-low Priority: low D-average Difficulty: average Cmd-forge-script Command: forge script labels Aug 8, 2022
@minaminao
Copy link
Contributor

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.

@jpiabrantes
Copy link

+1 would love to have this!

@plotchy
Copy link
Contributor

plotchy commented Sep 22, 2022

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.

@advock
Copy link

advock commented Apr 13, 2024

Hey guys I am trying to deploy contract on sei and my max fee per gas is 30000.. is it some what related to this error ..
Currently I am facing error of insufficient fund

@GabrielCartier
Copy link

Hey guys I am trying to deploy contract on sei and my max fee per gas is 30000.. is it some what related to this error .. Currently I am facing error of insufficient fund

I've ran into issues deploying to SEI. Make sure your address is properly linked (meaning you got a native address). If you don't, an easy way is to send yourself some SEI from the same address with an EVM wallet, this will create a SEI address for you.

Also, on Testnet I ran into insufficient fund errors, I found that if I did a transaction before deploying (i.e. send yourself SEI), I was able to get rid of the insufficient fund error. It doesn't seem to happen on mainnet, fees are so little I'd suggest you deploy right there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-forge Command: forge Cmd-forge-script Command: forge script D-average Difficulty: average P-low Priority: low T-feature Type: feature
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

8 participants