foundry-rs / foundry

Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.
https://getfoundry.sh
Apache License 2.0
8.33k stars 1.76k forks source link

Could not instantiate forked environment with fork url #9374

Closed heitor-lassarote closed 12 hours ago

heitor-lassarote commented 13 hours ago

Component

Forge

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

What version of Foundry are you on?

forge 0.2.0 (7bef9ca 2024-06-26T00:18:22.002685333Z)

What command(s) is the bug in?

forge script

Operating System

Linux

Describe the bug

After trying to deploy a pretty simple mock ERC-20 token to the Polygon Amoy testnet, I got this error, which the CLI asked me to report as a bug:

forge script script/MockToken.s.sol --rpc-url https://rpc-amoy.polygon.technology/ --broadcast -vvvv
[⠊] Compiling...
No files changed, compilation skipped
2024-11-21T15:25:27.218837Z ERROR foundry_evm_core::fork::init: It looks like you're trying to fork from an older block with a non-archive node which is not supported. Please try to change your RPC url to an archive node if the issue persists.
The application panicked (crashed).
Message:  Unable to create fork: 
Could not instantiate forked environment with fork url: https://rpc-amoy.polygon.technology/
Location: crates/evm/core/src/backend/mod.rs:454

This is a bug. Consider reporting it at https://github.com/foundry-rs/foundry

  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ BACKTRACE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   1: __libc_start_main<unknown>
      at <unknown source file>:<unknown line>

Run with COLORBT_SHOW_HIDDEN=1 environment variable to disable frame filtering.
[1]    15730 IOT instruction (core dumped)  forge script script/MockToken.s.sol --rpc-url  --broadcast -vvvv

The script doesn't do much:

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import {Script} from "forge-std/Script.sol";
import {MockToken} from "../src/MockToken.sol";

contract MockTokenScript is Script {
    function run() external {
        uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
        vm.startBroadcast(deployerPrivateKey);

        new MockToken("Mock ERC20 Token", "MCK");

        vm.stopBroadcast();
    }
}

And the contract is as dumb as possible:

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract MockToken is ERC20 {
    constructor(
        string memory _name,
        string memory _symbol
    ) ERC20(_name, _symbol) {}

    function mint(address to, uint256 amount) public virtual {
        _mint(to, amount);
    }

    function burn(address form, uint amount) public virtual {
        _burn(form, amount);
    }
}

Note: foundryup --version returns an empty string, I was not able to find out its version.

grandizzy commented 13 hours ago

@heitor-lassarote pls add forge --version output, looks like an older version as sources doesn't match crates/evm/core/src/backend/mod.rs:454 Also there's a good hint what happens: 2024-11-21T15:25:27.218837Z ERROR foundry_evm_core::fork::init: It looks like you're trying to fork from an older block with a non-archive node which is not supported. Please try to change your RPC url to an archive node if the issue persists.

grandizzy commented 13 hours ago

nm, I see forge version now, that's quite old, you should run foundryup and retest

grandizzy commented 12 hours ago

Confirming forge doesn't panic with latest but prints message

image

Going to close for now, please reopen if still an issue. thank you