Skip to content

Gas meter shows huge number when using vm.pauseGasMetering() along with delete X #4370

@Tudmotu

Description

@Tudmotu

Component

Forge

Have you ensured that all of these are up to date?

  • Foundry
  • Foundryup

What version of Foundry are you on?

forge 0.2.0 (25fcfef 2023-02-11T00:08:44.860915008Z)

What command(s) is the bug in?

forge test

Operating System

Linux

Describe the bug

Not sure exactly what is happening, but it seems like an integer overflow of some sort.

In one of my tests I am using vm.pauseGasMetering()/vm.resumeGasMetering() while also removing data from the storage.

Here is the simplest reproduction I could find:

pragma solidity ^0.8.18;

import 'forge-std/Test.sol';

contract NegativeGasTest is Test {
    uint a;

    function test_negativeGas () public {
        vm.pauseGasMetering();
        a = 100;
        vm.resumeGasMetering();

        delete a;
    }
}

The output of forge test looks like this:

[⠒] Compiling...
[⠔] Compiling 1 files with 0.8.18
[⠒] Solc 0.8.18 finished in 311.19ms
Compiler run successful

Running 1 test for test/negative-gas/Test.sol:NegativeGasTest
[PASS] test_negativeGas() (gas: 18446744073709549969)
Test result: ok. 1 passed; 0 failed; finished in 166.78µs

If there are any pointers to where the issue might be, I wouldn't mind trying to fix this myself and send a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Completed

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions