eth-sri / securify

[DEPRECATED] Security Scanner for Ethereum Smart Contracts
Apache License 2.0
215 stars 50 forks source link

Docker container NullPointerException #19

Closed ajhodges closed 5 years ago

ajhodges commented 5 years ago

Potentially related to #16? I am trying to build and run the Dockerfile from the current master@569893a. When I run it against the example it runs fine, but when I mount my sol files at /contracts I get this output:

[Ljava.lang.StackTraceElement;@6872f9c8
FAILURE
Exception in thread "main" java.lang.NullPointerException
    at ch.securify.analysis.Dataflow.dispose(Dataflow.java:43)
    at ch.securify.Main.checkPatterns(Main.java:397)
    at ch.securify.Main.processHexFile(Main.java:151)
    at ch.securify.Main.processSolidityFile(Main.java:108)
    at ch.securify.Main.main(Main.java:186)
Error: Exited with code 1
Step failed
Error: runner failed
Task failed
hiqua commented 5 years ago

Are there sol files that you could share with us so that we can reproduce the issue? Given that it's within the docker image, Soufflé should be installed.

ajhodges commented 5 years ago

I can't share the sol files in question - but I can tell you that it is a Truffle + OpenZeppelin project that I have flattened using this project: https://github.com/BlockChainCompany/soljitsu

Haven't had any problems with other analysis tools; I will do some more debugging on my end and try to come up with a simple share-able example tomorrow. Thanks!

hiqua commented 5 years ago

Ok I understand. Is the output of solc --combined-json abi,ast,bin-runtime,srcmap-runtime file.sol anything special, are there empty fields, etc?

As you can see from https://github.com/eth-sri/securify/blob/master/src/main/java/ch/securify/CompilationHelpers.java#L87 we only run solc under the hood. In the Dockerfile you can see that we still use v0.4.24 (I should update this by the way). Do your contracts compile with v0.4.24?

Can you copy paste the command you use exactly to mount your folder into the Docker container?

ajhodges commented 5 years ago

Okay - I just spent a couple hours debugging. The root cause of this error is that I am running /docker_run_securify from a working directory other than root (/). So in https://github.com/eth-sri/securify/blob/59e6fcb0e230514f149921b1b47ed670dab41ff6/src/main/java/ch/securify/analysis/AbstractDataflow.java#L138 SOUFFLE_RULES is set to smt_files/mustExplicit.dl, which is a relative path. So souffle is not finding it in my working directory and dying.

The reason why I am using a different working directory is because I am trying to get Securify running in CircleCI, which defaults to a working directory other than root.

I recommend using absolute paths for SOUFFLE_RULES to ensure this does not happen.

Also - there is a small bug in your error logging: https://github.com/eth-sri/securify/blob/59e6fcb0e230514f149921b1b47ed670dab41ff6/src/main/java/ch/securify/analysis/Dataflow.java#L36 This just prints [Ljava.lang.StackTraceElement;@6872f9c8 as shown above in my original issue comment. It should be changed to e.printStackTrace();

Once I changed my working directory to root /, I got Securify to get a little bit further in its analysis - I'll open a different issue for the next thing I encountered.

hiqua commented 5 years ago

Do you mean that you have your own Dockerfile that takes the Securify image as its base, and that you change the working directory in this one?

ajhodges commented 5 years ago

No, sorry. I am building your Dockerfile and then running commands inside that container to check out my code instead of using a volume mount. It just so happens that the working directory of those commands wasn't /.

If you want to reproduce this, just add a -w flag to your docker run command, like: docker run -w /home -v $(pwd)/folder_with_solidity_files:/contracts securify or even just to run the example.sol: docker run -w /home securify

hiqua commented 5 years ago

Ok I see, but then is there something we can fix for this issue in particular?

ajhodges commented 5 years ago

I recommend using absolute paths for SOUFFLE_RULES, but it is up to you if this issue is serious enough to warrant a fix. I just wanted to make sure I documented it just in case someone else runs into this.

hiqua commented 5 years ago

Absolute paths won't work outside of docker containers unfortunately.