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

echidna error during compilation #813

Closed
eladalkabets2603 opened this issue Aug 10, 2022 · 9 comments
Closed

echidna error during compilation #813

eladalkabets2603 opened this issue Aug 10, 2022 · 9 comments

Comments

@eladalkabets2603
Copy link

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

@elopez
Copy link
Member

elopez commented Aug 10, 2022

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 👍

@eladalkabets2603
Copy link
Author

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?

@elopez
Copy link
Member

elopez commented Aug 10, 2022

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

@eladalkabets2603
Copy link
Author

--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?

@ggrieco-tob
Copy link
Member

ggrieco-tob commented Aug 10, 2022

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

@eladalkabets2603
Copy link
Author

eladalkabets2603 commented Aug 10, 2022

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?

@ggrieco-tob
Copy link
Member

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

@elopez
Copy link
Member

elopez commented Aug 10, 2022

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 ...;
    }
}

@ggrieco-tob
Copy link
Member

This is already documented

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants