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

bug(forge script): reading from other contracts that are deployed as part of the script fails #8960

Open
2 tasks done
firnprotocol opened this issue Sep 26, 2024 · 1 comment
Labels
Cmd-forge-script Command: forge script T-bug Type: bug T-to-investigate Type: to investigate

Comments

@firnprotocol
Copy link

firnprotocol commented Sep 26, 2024

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 (883bb1c 2024-09-25T00:24:44.893538000Z)

What command(s) is the bug in?

forge script

Operating System

macOS (Intel)

Describe the bug

I am trying to execute a more complex deploy, using Solidity Scripting (see script here). TLDR: the script fails, with a nondescript error. when I step through with the debugger, the problematic line comes and goes without problem. this shows (a) inconsistency between the script and the debugger and (b) it seems a bug in the script execution environment. I have run and tested these contracts extensively outside of Foundry, so I am quite sure that something is wrong.

Thorough explanation. I have not yet worked up a MWE; but this should give a lot of info for now. For an MWE, please see the comment below.

I have a contract which—during its constructor—reads from a public state variable of another contract. The problematic reads are here and here.

upon starting anvil in one window and executing

forge script script/Firn.s.sol:FirnScript --fork-url http://localhost:8545 --broadcast

I get:

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

## Setting up 1 EVM.

Failed with `EvmError: Revert`:


Failed with `EvmError: Revert`:

  [3294] → new <unknown>@0x34A1D3fff3958843C43aD80F30b94c510645C316
    ├─ [0] InnerProductVerifier::gs(0) [staticcall]
    │   └─ ← [Stop] 
    └─ ← [Revert] EvmError: Revert

  [794] → new InnerProductVerifier@0x90193C961A926261B756D1E5bb255e67ff9498A1
    ├─ [0] InnerProductVerifier::gs(0) [staticcall]
    │   └─ ← [Stop] 
    └─ ← [Revert] EvmError: Revert

Error: 
Simulated execution failed.

you can see that the problematic line is reading from state of another contract.

If you add vm.breakpoint("a"); between lines 24 and 25 of the script—i.e., before the line TransferVerifier transfer = new TransferVerifier(ip);—run forge debug ./script/Firn.s.sol, and use 'a to step past the first few constructors, then you can step into the problematic contract creation. it is clear that instead of failing on the first read of _ip.gs(0), it chugs right past it with no problem.

happy to provide further info. many thanks in advance and apologies for the non-mwe. maybe there is a problem with simulating a read of a "tuple" (i.e., of a bytes32[2]).

@firnprotocol firnprotocol added T-bug Type: bug T-needs-triage Type: this issue needs to be labelled labels Sep 26, 2024
@firnprotocol firnprotocol changed the title EvmError: Revert upon deploy; inconsistent with debugger reading from other contracts fails in solidity scripting Sep 26, 2024
@firnprotocol
Copy link
Author

UPDATE: I have created an MWE for this; please see https://github.com/firnprotocol/foundry_mwe/tree/master/src

here, there are two basic contracts, One.sol:

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

import {Other} from "./Other.sol";

contract One {
    constructor(Other other) {
        bytes32 temp = other.thing();
    }
}

and Other.sol:

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

contract Other {
    function thing() external pure returns (bytes32) {
        return bytes32(0xaaeeaaeeaaeeaaeeaaeeaaeeaaeeaaeeaaeeaaeeaaeeaaeeaaeeaaeeaaeeaaee);
    }
}

running the script

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

import {Script, console} from "forge-std/Script.sol";
import {One} from "../src/One.sol";
import {Other} from "../src/Other.sol";

contract MainScript is Script {
    function setUp() public {}

    function run() public {
        vm.startBroadcast();

        Other other = new Other();
        One one = new One(other);

        vm.stopBroadcast();
    }
}

using

forge script ./script/One.s.sol:MainScript --fork-url http://localhost:8545 --broadcast

fails with output:

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

## Setting up 1 EVM.

Failed with `EvmError: Revert`:

  [3049] → new <unknown>@0x7FA9385bE102ac3EAc297483Dd6233D62b3e1496
    ├─ [0] Other::thing() [staticcall]
    │   └─ ← [Stop] 
    └─ ← [Revert] EvmError: Revert

Error: 
Simulated execution failed.

many thanks in advance.

@zerosnacks zerosnacks changed the title reading from other contracts fails in solidity scripting bug(forge script): reading from other contracts that are deployed as part of the script fails Sep 26, 2024
@zerosnacks zerosnacks added Cmd-forge-script Command: forge script T-to-investigate Type: to investigate and removed T-needs-triage Type: this issue needs to be labelled labels Sep 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Cmd-forge-script Command: forge script T-bug Type: bug T-to-investigate Type: to investigate
Projects
None yet
Development

No branches or pull requests

2 participants