Skip to content

bug: vm.etch does not work in forge script simulation[/-] #11731

@wjmelements

Description

@wjmelements

Component

Forge

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

  • Foundry
  • Foundryup

What version of Foundry are you on?

forge Version: 1.3.5-stable Commit SHA: 9979a41 Build Timestamp: 2025-09-09T04:49:14.583356000Z (1757393354) Build Profile: maxperf

What version of Foundryup are you on?

foundryup: 1.1.0

What command(s) is the bug in?

forge script

Operating System

macOS (Intel)

Describe the bug

I'm using vm.etch to mock filecoin precompiles (FilOzone/filecoin-pay#234). It works fine in forge test but fails in forge script.

Here is the relevant part of the script:

contract Profile is Script {
    function endAuction(address sender, Payments payments, uint256 railId) public {
        Payments.RailView memory railView = payments.getRail(railId);
        IERC20 token = railView.token;

        (uint256 fullAmount,,,) = payments.accounts(token, address(payments));

        address recipient = address(0x4a6f6B9fF1fc974096f9063a45Fd12bD5B928AD1);

        FVMPrecompileMock precompileMock = new FVMPrecompileMock();
        vm.etch(0xfe00000000000000000000000000000000000005, address(precompileMock).code);

        vm.startBroadcast();

        payments.burnFILForFees{value: AUCTION_START_PRICE}(token, recipient, fullAmount);
    }
}

The output is

[⠊] Compiling...
No files changed, compilation skipped
Script ran successfully.

## Setting up 1 EVM.
  [19407] 0xF6990c51dC94B36c5D5184BF60107EFe99DDE592::burnFILForFees{value: 31320000000000000000}(0xe9AE74E0C182AAb11bdDb483227CC1F6600b3625, 0x4a6f6B9fF1fc974096f9063a45Fd12bD5B928AD1, 5000)
    ├─ [0] 0xfe00000000000000000000000000000000000005::00000000{value: 31320000000000000000}(00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001b2a6fe0f3d3c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000630000000000000000000000000000000000000000000000000000000000000000) [delegatecall]
    │   └─ ← [Stop]
    └─ ← [Revert] FVM precompile invalid response

Error: Simulated execution failed.

Based on the [Stop] I don't think etch is working in the simulation. I also believe it is not working because when I intercept the rpc with a reverse proxy I see it fetching the actual code.

[::1]:60468: POST http://localhost:1234/rpc/v1
    content-type: application/json
    accept: */*
    user-agent: foundry/1.3.5
    accept-encoding: gzip
    host: localhost:1234
    content-length: 111

    {
        "method": "eth_getCode",
        "params": [
            "0xfe00000000000000000000000000000000000005",
            "0x1c"
        ],
        "id": 37,
        "jsonrpc": "2.0"
    }

 << 200 OK 40b
    Date: Fri, 19 Sep 2025 21:16:23 GMT
    Content-Length: 40
    Content-Type: text/plain; charset=utf-8

    {"id":37,"jsonrpc":"2.0","result":"0x"}

I also believe that vm.deal doesn't work for the simulation either, though this is less important to me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions