echidna icon indicating copy to clipboard operation
echidna copied to clipboard

echidna error during compilation

Open eladalkabets2603 opened this issue 3 years ago • 8 comments

i have given echidna the flat file of masterchef (which i compiled beforehand) without the pragma solidity line (as seen in examples)

then i ran the docker container using the following line docker run -it -v pwd:/src ghcr.io/crytic/echidna/echidna echidna-test /src/test.sol.

test.sol is attached below.

when ran i get the following error:

echidna-test: Couldn't compile given file
stdout:
stderr:
ERROR:CryticCompile:Invalid solc compilation /src/test.sol:305:42: Error: Expected ';' but got '{'
        (bool success, ) = recipient.call{ value: amount }("");

any suggestions or ideas to what i did wrong? p.s is there any way to define compiler version in the docekr run line? FlatFile.txt

eladalkabets2603 avatar Aug 10 '22 12:08 eladalkabets2603

Hi, thanks for the report. The echidna docker container has solc 0.5.7 preinstalled, but your contract requires a newer version. You'll need to remove that solc installation and install a compatible solc. You can use solc-select for that:

docker run -it -v `pwd`:/src ghcr.io/crytic/echidna/echidna bash -c "rm /usr/bin/solc && pip3 install solc-select && solc-select install 0.6.12 && solc-select use 0.6.12 && echidna-test /src/test.sol"

We have a PR in progress (#706) to update the Docker image and include solc-select in it, so this use case is better handled in the future 👍

elopez avatar Aug 10 '22 12:08 elopez

Hi, thanks for the report. The echidna docker container has solc 0.5.7 preinstalled, but your contract requires a newer version. You'll need to remove that solc installation and install a compatible solc. You can use solc-select for that:

docker run -it -v `pwd`:/src ghcr.io/crytic/echidna/echidna bash -c "rm /usr/bin/solc && pip3 install solc-select && solc-select install 0.6.12 && solc-select use 0.6.12 && echidna-test /src/test.sol"

We have a PR in progress (#706) to update the Docker image and include solc-select in it, so this use case is better handled in the future 👍

when i ran it now i get the following

Installing '0.6.12'...
Version '0.6.12' installed.
Switched global version to 0.6.12
Multiple contracts found, only analyzing the first
Analyzing contract: /src/test.sol:Address
echidna-test: ABI is empty, are you sure your constructor is right?

is there any way to specify which contract to test?

eladalkabets2603 avatar Aug 10 '22 12:08 eladalkabets2603

yep, you can add the echidna --contract Foo option for that

elopez avatar Aug 10 '22 12:08 elopez

--contract Thanks for the quick feedback!

echidna-test: Constructor arguments are required: [("_sushi",address),("_devaddr",address),("_sushiPerBlock",uint256),("_startBlock",uint256),("_bonusEndBlock",uint256)].

in what format should i pass the parameter?,

furthermore i saw that the process can be done automatically using slither-prop but when itry to use slither-prop on my contract "slither-prop ./FlatFile.sol --contract MasterChef" I get:

MasterChef is not ERC20 compliant. Consider checking the contract with slither-check-erc

any advices?

eladalkabets2603 avatar Aug 10 '22 13:08 eladalkabets2603

It seems that you are on track, however you should use a contract without parameters for testing, Echidna cannot initialize it for you.

gustavo-grieco avatar Aug 10 '22 13:08 gustavo-grieco

It seems that you are on track, however you should use a contract without parameters for testing, Echidna cannot initialize it for you.

what about the slither prop? and is there a way to manually pass parameters?

eladalkabets2603 avatar Aug 10 '22 13:08 eladalkabets2603

slither-prop will generate a contract with properties, but only for ERC20/ERC721, but it cannot initialize any contract. You can edit the resulting file to fill in any missing initialization, however in this case, keep in mind that you need to provide address to contracts that are non-trivial. For instance, _sushi should point to a functional SushSwap contract that you deploy during the initialization of your testing contract. The best workaround is to edit the constructor of the file to create a scenario where all the required components of a MasterChef are properly created.

If you do not want to recreate this, considering checking this: https://github.com/crytic/building-secure-contracts/blob/master/program-analysis/echidna/end-to-end-testing.md

gustavo-grieco avatar Aug 10 '22 13:08 gustavo-grieco

To add on to what @ggrieco-tob said, and for anyone else reading in the future, there is no manual way in Echidna to pass constructor arguments; you should use a contract that doesn't take arguments. If your arguments are simple enough, you can do so by having a FooTest contract that inherits from Foo and in its parameterless constructor, calls Foo with a set of default arguments:

contract FooTest is Test {
    // update the constructor
    constructor() public Test("foo", "bar", "baz") { }

    // add the properties you want to use in echidna
    function echidna_test_balance() public view returns (bool) {
        return ...;
    }
}

elopez avatar Aug 10 '22 13:08 elopez

This is already documented

gustavo-grieco avatar Dec 14 '22 17:12 gustavo-grieco