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

Add vm.callTimeout and vm.setGas for Improved Gas Control #7892

Open
Azvect opened this issue May 8, 2024 · 0 comments
Open

Add vm.callTimeout and vm.setGas for Improved Gas Control #7892

Azvect opened this issue May 8, 2024 · 0 comments
Labels
T-feature Type: feature

Comments

@Azvect
Copy link

Azvect commented May 8, 2024

Component

Forge

Describe the feature you would like

When you use vm.pauseGasMetering() and call an address, if the address is a contract address and the contract uses the gasleft() function in a loop, the call can get stuck in an infinite loop. The reason is that the gasleft() function keeps returning the same gas limit indefinitely. While using vm.resumeGasMetering() can prevent this issue, it's not always effective.

For instance, I have a script that calls many contracts, and I don't want to encounter gas limit exceeded or out-of-gas errors. Thus, setting the gas limit again after it's lowered by vm.resumeGasMetering() isn't always possible.

A possible solution is to introduce an option like vm.callTimeout(address, data, timeout), which could be highly useful in various contexts such as fuzzing.

Alternatively, adding a function like vm.setGas(uint256) to adjust the gas limit inside the contract, allowing it to increase after execution, would be extremely beneficial.

Proposed Feature:

  1. vm.callTimeout(address, data, timeout)

    • Calls an address with a specified data payload and a timeout.
    • Terminates the call if the timeout duration is exceeded.
  2. vm.setGas(uint256)

    • Sets the gas limit to the specified value.
    • Allows resetting the gas limit to a higher value after execution.

These options would offer developers more control over gas usage and prevent infinite loops in contract calls.

Additional context

No response

@Azvect Azvect added the T-feature Type: feature label May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-feature Type: feature
Projects
None yet
Development

No branches or pull requests

1 participant