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

vm.pauseGasMetering() bricks construction of contracts with external calls #6057

Closed
2 tasks done
3docSec opened this issue Oct 18, 2023 · 2 comments
Closed
2 tasks done
Labels
A-cheatcodes Area: cheatcodes C-forge Command: forge Cmd-forge-test Command: forge test T-bug Type: bug

Comments

@3docSec
Copy link

3docSec commented Oct 18, 2023

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 (b0b8cfb 2023-10-18T00:17:29.353012000Z)

What command(s) is the bug in?

forge test

Operating System

macOS (Apple Silicon)

Describe the bug

The below test contract shows how the creation of SomeContract succeeds with gas metering enabled, but fails when gas metering is disabled.

This applies to both CREATE and CREATE2 opcodes.

pragma solidity ^0.8.20;

import {Test} from "forge-std/Test.sol";

contract BugTest is Test {

    address public something;

    function testNoBug() public {
        new SomeContract();
    }

    function testFailBug() public {
        vm.pauseGasMetering();
        new SomeContract();
    }
}

contract SomeContract {
    constructor() {
        BugTest(msg.sender).something();
    }
}

Extra-verbose output is:

$ forge test -vvvv
[⠢] Compiling...
No files changed, compilation skipped

Running 2 tests for test/Counter.t.sol:BugTest
[PASS] testFailBug() (gas: 9223372036854754743)
Traces:
  [0] BugTest::testFailBug()
    ├─ [0] VM::pauseGasMetering()
    │   └─ ← ()
    ├─ [0] → new <Unknown>@0x5615dEB798BB3E4dFa0139dFa1b3D433Cc23b72f
    │   ├─ [0] BugTest::something() [staticcall]
    │   │   └─ ← 0x0000000000000000000000000000000000000000
    │   └─ ← 0 bytes of code
    └─ ← "EvmError: Revert"

[PASS] testNoBug() (gas: 47801)
Traces:
  [47801] BugTest::testNoBug()
    ├─ [15457] → new SomeContract@0x5615dEB798BB3E4dFa0139dFa1b3D433Cc23b72f
    │   ├─ [2382] BugTest::something() [staticcall]
    │   │   └─ ← 0x0000000000000000000000000000000000000000
    │   └─ ← 63 bytes of code
    └─ ← ()

Test result: ok. 2 passed; 0 failed; 0 skipped; finished in 344.46µs

Ran 1 test suites: 2 tests passed, 0 failed, 0 skipped (2 total tests)

The full project can be found in this public repo. LMK if I can provide more info 🤗

@3docSec 3docSec added the T-bug Type: bug label Oct 18, 2023
@gakonst gakonst added this to Foundry Oct 18, 2023
@github-project-automation github-project-automation bot moved this to Todo in Foundry Oct 18, 2023
@zerosnacks
Copy link
Member

zerosnacks commented Jun 28, 2024

Able to reproduce except now throws [OutOfGas]

Ran 2 tests for test/BugTest.t.sol:BugTest
[PASS] testFailBug() (gas: 9223372036854754743)
Traces:
  [0] BugTest::testFailBug()
    ├─ [0] VM::pauseGasMetering()
    │   └─ ← [Return] 
    ├─ [0] → new SomeContract@0x5615dEB798BB3E4dFa0139dFa1b3D433Cc23b72f
    │   ├─ [0] BugTest::something() [staticcall]
    │   │   └─ ← [Return] 0x0000000000000000000000000000000000000000
    │   └─ ← [OutOfGas] 63 bytes of code
    └─ ← [Revert] EvmError: Revert

[PASS] testNoBug() (gas: 47812)
Traces:
  [47812] BugTest::testNoBug()
    ├─ [15468] → new SomeContract@0x5615dEB798BB3E4dFa0139dFa1b3D433Cc23b72f
    │   ├─ [2393] BugTest::something() [staticcall]
    │   │   └─ ← [Return] 0x0000000000000000000000000000000000000000
    │   └─ ← [Return] 63 bytes of code
    └─ ← [Stop] 

Related to #5564

@zerosnacks zerosnacks added A-cheatcodes Area: cheatcodes Cmd-forge-test Command: forge test C-forge Command: forge labels Jun 28, 2024
@zerosnacks zerosnacks changed the title vm.pauseGasMetering() bricks construction of contracts with external calls vm.pauseGasMetering() bricks construction of contracts with external calls Jul 4, 2024
@zerosnacks
Copy link
Member

Closing in favor of #5564 as it is an effect of running out of gas due to excessive gas usage by pauseGasMetering: #5491

@zerosnacks zerosnacks closed this as not planned Won't fix, can't repro, duplicate, stale Jul 4, 2024
@jenpaff jenpaff moved this from Todo to Completed in Foundry Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cheatcodes Area: cheatcodes C-forge Command: forge Cmd-forge-test Command: forge test T-bug Type: bug
Projects
Archived in project
Development

No branches or pull requests

2 participants