crytic / echidna

Ethereum smart contract fuzzer
https://secure-contracts.com/program-analysis/echidna/index.html
GNU Affero General Public License v3.0
2.72k stars 362 forks source link

Unclear how to pick a specific Solidity compiler version when using the Docker package #642

Closed PaulRBerg closed 3 years ago

PaulRBerg commented 3 years ago

I followed the instructions in the README listed under Docker container and executed the following comand:

$ docker run -it -v `pwd`:/src echidna echidna-test /src/contracts/invariants/MulDivInvariant.sol

But I encountered this error:

echidna-test: Couldn't compile given file
stdout:
stderr:
ERROR:CryticCompile:Invalid solc compilation /src/contracts/invariants/MulDivInvariant.sol:2:1: Error: Source file requires different compiler version (current compiler is 0.5.7+commit.6da8b019.Linux.g++ - note that nightly builds are considered to be strictly less than the released version
pragma solidity >=0.8.0;

Now, I am not quite sure whence this v0.5.7 of Solidity is picked up from. Is it the default used by Echidna (which I can override)? Is it the one I have locally installed on my Mac? If yes, which installation option takes priority: node.js, docker, homebrew, etc.?

It would be helpful if there was an explanation in the README about how to set the compiler version when running Echidna via the Docker package.

ggrieco-tob commented 3 years ago

Your contract is compiled inside Docker so solc is installed inside it.

PaulRBerg commented 3 years ago

Thanks for the quick reply! So is there no way to override that? Am I bound to solc@0.5.17 with this Docker package?

Update: I know that I can switch the compiler version with the eth-security-box image, but I was looking to use the bespoke Echidna package.

ggrieco-tob commented 3 years ago

Yes, you can go inside the docker container (running bash for instance), install anything you need (or use solc-select as I think it is already installed) and then run your fuzzing campaign from the shell.

PaulRBerg commented 3 years ago

Oh, makes sense! Sorry, I am not a Docker expert.

ggrieco-tob commented 3 years ago

That's fine. Please feel free to comment on this closed issue what worked better for you so we can update the README and clarify this.

PaulRBerg commented 3 years ago

I figured it out eventually, but it was quite a detour. I tried to run the commands listed under the Linux packages section in the Solidity docs, but I got this error:

Error sudo: add-apt-repository: command not found

I then found this thread on StackExchange, and realised I have to install software-properties-common:

$ apt install software-properties-common

Only then I was able to run the commands from the Solidity documentation (without sudo):

$ add-apt-repository ppa:ethereum/ethereum
$ apt-get update
$ apt-get install solc

I then tried to compile my contract, but unfortunately that didn't work. From within the Docker container, I ran this:

$  echidna-test /src/contracts/invariants/MulDivInvariant.sol

But I got this error back:

echidna-test: Couldn't compile given file
stdout:
stderr:
Traceback (most recent call last):
  File "/root/.local/bin/crytic-compile", line 11, in <module>
    sys.exit(main())
  File "/root/.local/lib/python3.6/site-packages/crytic_compile/__main__.py", line 157, in main
    compilations = compile_all(**vars(args))
  File "/root/.local/lib/python3.6/site-packages/crytic_compile/crytic_compile.py", line 1076, in compile_all
    compilations.append(CryticCompile(target, **kwargs))
  File "/root/.local/lib/python3.6/site-packages/crytic_compile/crytic_compile.py", line 137, in __init__
    self._compile(**kwargs)
  File "/root/.local/lib/python3.6/site-packages/crytic_compile/crytic_compile.py", line 987, in _compile
    self._platform.compile(self, **kwargs)
  File "/root/.local/lib/python3.6/site-packages/crytic_compile/platform/solc.py", line 180, in compile
    crytic_compile.abis[contract_name] = json.loads(info["abi"])
  File "/usr/lib/python3.6/json/__init__.py", line 348, in loads
    'not {!r}'.format(s.__class__.__name__))
TypeError: the JSON object must be str, bytes or bytearray, not 'list'

Not sure how to fix this. For the record, I am using Hardhat. In the meantime, I will switch back to the eth-security-toolbox.

Update: After providing the path to the Echidna config (via the --config argument) and the name of the contract (via the --contract argument), running echidna-test worked, but the compilation didn't succeed. It seems like Solidity v0.8 is not supported by crytic-compile?

PaulRBerg commented 3 years ago

Also solc-select is not installed, by default.

alexon1234 commented 3 years ago

You can just install the solc version you need as it does inside the Dockerfile

docker run -it -v `pwd`:/src trailofbits/echidna bash

Inside the bash run the following command, but replacing v0.X.X for the version you want.

wget https://github.com/ethereum/solidity/releases/download/v0.X.X/solc-static-linux && chmod +x solc-static-linux && mv solc-static-linux /usr/bin/solc