Cyfrin / foundry-smart-contract-lottery-cu

47 stars 42 forks source link

Forge commands requires a tag --via-ir while performing any command #9

Closed Nihal-Abedin closed 6 months ago

Nihal-Abedin commented 1 year ago

gives an compile error on any command without the tag Compiler error (/solidity/libsolidity/codegen/CompilerUtils.cpp:1430):Stack too deep. Try compiling with `--via-ir` (cli) or the equivalent `viaIR: true` (standard JSON) while enabling the optimizer. Otherwise, try removing local variables.

PatrickAlphaC commented 1 year ago

Can you try git cloning the repo and seeing what happens?

Also, can you give the exact commands you ran to get this error?

Skyewwww commented 1 year ago

@PatrickAlphaC I have this problem as well after adding deployerKey to the code. Every command containing forge (etc. forge test) shows the same error message when executing. However, if try with '--via-ir' (forge test --via-ir), it works normal again.

PatrickAlphaC commented 1 year ago

hmmm... Maybe we should update the foundry.toml?

Slavchew commented 1 year ago

The problem occurs after adding deployerKey as a state variable in the RaffleTest contract, this is due to too many state variables.

It can be solved by removing deployerKey from the values returned by the Helperconfig.activeNetworkConfig and also not creating a state variable for it because it will never be used.

function setUp() external {
    DeployRaffle deployer = new DeployRaffle();
    (raffle, helperConfig) = deployer.run();
    vm.deal(PLAYER, STARTING_USER_BALANCE);

    (
        entranceFee,
        interval,
        vrfCoordinator,
        gasLane,
        subscriptionId,
        callbackGasLimit,
        link,
        // deployerKey - or it can simply be commented
    ) = helperConfig.activeNetworkConfig();
}

Note: With --via-ir it works fine, but it takes too long to run all the tests.

Vitalii-1996 commented 8 months ago

forge coverage also reverts with error Stack too deep. To run coverage we need to use forge coverage --ir-minimum because --via-ir is not supported for coverage.

PatrickAlphaC commented 6 months ago

Going to close this for now... I'm not getting this from the code as written.