diff --git a/.travis.yml b/.travis.yml index 29c8df2f..e7e3f78f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,6 +26,7 @@ install: - unset CC - export PATH=$HOME/.local/bin:$PATH - ./.travis/install-libsecp256k1.sh + - ./.travis/install-libff.sh - ./.travis/install-ghr.sh - ./.travis/install-stack.sh - ./.travis/install-solc.sh diff --git a/.travis/install-libff.sh b/.travis/install-libff.sh new file mode 100755 index 00000000..55c81c1d --- /dev/null +++ b/.travis/install-libff.sh @@ -0,0 +1,23 @@ +#!/bin/sh + +set -eux + +if ls /usr/local/lib | grep -q libff; then exit 0; fi + +git clone https://github.com/scipr-lab/libff --recursive +git submodule init && git submodule update +cd libff +ARGS="-DWITH_PROCPS=OFF" +CXXFLAGS="" +if [ "$TRAVIS_OS_NAME" = "osx" ]; then + export LDFLAGS=-L/usr/local/opt/openssl/lib + export CPPFLAGS=-I/usr/local/opt/openssl/include + export CXXFLAGS=-I/usr/local/opt/openssl/include + ARGS="$ARGS -DOPENSSL_INCLUDE_DIR=/usr/local/opt/openssl/include/openssl -DCURVE=ALT_BN128" + sed -i '' 's/STATIC/SHARED/' libff/CMakeLists.txt # Fix GHC segfaults from hell (idk why) + sed -i '' 's/STATIC/SHARED/' depends/CMakeLists.txt +fi +mkdir build +cd build +CXXFLAGS="-fPIC $CXXFLAGS" cmake $ARGS .. +make && sudo make install diff --git a/examples/solidity/exercises/testme.sol b/examples/solidity/exercises/testme.sol index b5e73153..d165f24c 100644 --- a/examples/solidity/exercises/testme.sol +++ b/examples/solidity/exercises/testme.sol @@ -21,6 +21,7 @@ contract Canal { } } } + function raise(bool first_gate) { if(first_gate) { first_gate_up = true; @@ -28,4 +29,14 @@ contract Canal { second_gate_up = true; } } + + function echidna_bothdown() returns (bool) { + return(first_gate_up || second_gate_up); + } + + function echidna_can_lower_second() returns (bool) { + bool a0 = lower(true); + raise(true); + return(a0); + } } diff --git a/lib/Echidna/Exec.hs b/lib/Echidna/Exec.hs index 0a3e0351..3c57ba83 100644 --- a/lib/Echidna/Exec.hs +++ b/lib/Echidna/Exec.hs @@ -69,8 +69,10 @@ execTxWith h m t = do og <- get case (res, isRight $ t ^. call) of (Reversion, _) -> put og (VMFailure x, _) -> h x - (VMSuccess bc, True) -> hasLens %= execState ( replaceCodeOfSelf bc - >> loadContract (t ^. dst)) + (VMSuccess bc, True) -> (hasLens %=) . execState $ do + env . contracts . at (t ^. dst) . _Just . contractcode .= InitCode "" + replaceCodeOfSelf (RuntimeCode bc) + loadContract (t ^. dst) _ -> pure () return res diff --git a/lib/Echidna/Solidity.hs b/lib/Echidna/Solidity.hs index fcadb030..cb08fc12 100644 --- a/lib/Echidna/Solidity.hs +++ b/lib/Echidna/Solidity.hs @@ -100,7 +100,7 @@ contracts fp = do populateAddresses :: [Addr] -> Integer -> VM -> VM populateAddresses [] _ vm = vm populateAddresses (a:as) b vm = populateAddresses as b (vm & set (env . EVM.contracts . at a) (Just account)) - where account = initialContract mempty & set nonce 1 & set balance (w256 $ fromInteger b) + where account = initialContract (RuntimeCode mempty) & set nonce 1 & set balance (w256 $ fromInteger b) -- | Given an optional contract name and a list of 'SolcContract's, try to load the specified -- contract, or, if not provided, the first contract in the list, into a 'VM' usable for Echidna diff --git a/lib/Echidna/Transaction.hs b/lib/Echidna/Transaction.hs index bffd7edf..bd8ec933 100644 --- a/lib/Echidna/Transaction.hs +++ b/lib/Echidna/Transaction.hs @@ -116,9 +116,9 @@ liftSH = S.state . runState . zoom hasLens setupTx :: (MonadState x m, Has VM x) => Tx -> m () setupTx (Tx c s r v) = S.state . runState . zoom hasLens . sequence_ $ [ result .= Nothing, state . pc .= 0, state . stack .= mempty, state . memory .= mempty, state . gas .= 0xffffffff - , env . origin .= s, state . caller .= s, state . callvalue .= v, setup] where + , tx . origin .= s, state . caller .= s, state . callvalue .= v, setup] where setup = case c of Left cd -> loadContract r >> state . calldata .= encode cd - Right bc -> assign (env . contracts . at r) (Just $ initialContract bc) >> loadContract r + Right bc -> assign (env . contracts . at r) (Just $ initialContract (RuntimeCode bc)) >> loadContract r encode (n, vs) = abiCalldata (n <> "(" <> T.intercalate "," (abiTypeSolidity . abiValueType <$> vs) <> ")") $ V.fromList vs diff --git a/stack.yaml b/stack.yaml index 3e20e72f..3e1320f1 100644 --- a/stack.yaml +++ b/stack.yaml @@ -1,22 +1,27 @@ -resolver: lts-12.18 +resolver: lts-12.10 packages: - '.' extra-deps: +- git: https://github.com/dapphub/dapptools.git + commit: 80c39ced5653727e7e38873bb215a99bc6acc56c + subdirs: + - src/hevm + - ghci-pretty-0.0.2 -- hevm-0.24 -- HSH-2.1.3 -- ipprint-0.6 - multiset-0.3.4.1 -- readline-1.0.3.0 - restless-git-0.7 - rosezipper-0.2 - s-cargot-0.1.4.0 -- sr-extra-1.46.3.2 - text-format-0.3.2 - tree-view-0.5 +- HSH-2.1.3 +- ipprint-0.6 +- sr-extra-1.46.3.2 - Unixutils-1.54.1 +- github: dmjio/semver-range + commit: d8d9db892ddb6ae267c9bcbc4f6602668433f12a extra-include-dirs: - /usr/local/opt/readline/include