Skip to content

Commit c9d0872

Browse files
added some basic verification tests
1 parent 45ab9f8 commit c9d0872

File tree

8 files changed

+54
-45
lines changed

8 files changed

+54
-45
lines changed

lib/Echidna/Types/Test.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,11 @@ isPassed t = case t.state of
146146
Passed -> True
147147
_ -> False
148148

149+
isVerified :: EchidnaTest -> Bool
150+
isVerified t = case t.state of
151+
Unsolvable -> True
152+
_ -> False
153+
149154
instance ToJSON TestState where
150155
toJSON s =
151156
object $ ("passed", toJSON passed) : maybeToList desc

src/test/Common.hs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module Common
1010
, solnFor
1111
, solved
1212
, passed
13+
, verified
1314
, solvedLen
1415
, solvedWith
1516
, solvedWithout
@@ -219,6 +220,15 @@ passed n (env, _) = do
219220
Nothing -> error ("no test was found with name: " ++ show n)
220221
_ -> False
221222

223+
verified :: Text -> (Env, WorkerState) -> IO Bool
224+
verified n (env, _) = do
225+
tests <- traverse readIORef env.testRefs
226+
pure $ case getResult n tests of
227+
Just t | isVerified t -> True
228+
Just t | isOpen t -> True
229+
Nothing -> error ("no test was found with name: " ++ show n)
230+
_ -> False
231+
222232
solvedLen :: Int -> Text -> (Env, WorkerState) -> IO Bool
223233
solvedLen i t final = (== Just i) . fmap length <$> solnFor t final
224234

src/test/Tests/Symbolic.hs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
module Tests.Symbolic (symbolicTests) where
22

33
import Test.Tasty (TestTree, testGroup)
4-
import Common (testContract', solved, passed)
4+
import Common (testContract', solved, verified)
55
import Echidna.Types.Campaign (WorkerType(..))
66

77
symbolicTests :: TestTree
88
symbolicTests = testGroup "Symbolic tests"
9-
[ testContract' "symbolic/sym.sol" Nothing Nothing (Just "symbolic/sym.yaml") True SymbolicWorker
10-
[ ("echidna_sym passed", passed "echidna_sym") ]
11-
12-
, testContract' "symbolic/sym-assert.sol" Nothing Nothing (Just "symbolic/sym-assert.yaml") True SymbolicWorker
13-
[ ("func_one passed", solved "func_one")
14-
, ("func_two passed", solved "func_two") ]
9+
[ testContract' "symbolic/verify.sol" Nothing Nothing (Just "symbolic/verify.yaml") True SymbolicWorker
10+
[ ("simple passed", solved "simple")
11+
, ("array passed", solved "array")
12+
, ("negative passed", solved "negative")
13+
, ("close passed", solved "close")
14+
, ("far not verified", verified "far")
15+
, ("correct not verified", verified "correct")
16+
]
1517
]

tests/solidity/symbolic/sym-assert.sol

Lines changed: 0 additions & 15 deletions
This file was deleted.

tests/solidity/symbolic/sym.sol

Lines changed: 0 additions & 21 deletions
This file was deleted.

tests/solidity/symbolic/sym.yaml

Lines changed: 0 additions & 2 deletions
This file was deleted.

tests/solidity/symbolic/verify.sol

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
contract VulnerableContract {
2+
mapping (uint256 => uint256) a;
3+
uint256 private last_number = block.number;
4+
function simple(uint256 x) public payable {
5+
a[12323] = ((x >> 5) / 7777);
6+
if (a[12323] == 2222) {
7+
assert(false); // BUG
8+
}
9+
}
10+
function array(uint256[3] calldata xs) public {
11+
assert(xs[0] != xs[2] + 1);
12+
}
13+
14+
function negative(int24 x) public {
15+
assert(x != -42);
16+
}
17+
18+
function correct(int24 x) public {
19+
assert(int256(x) != type(int256).max);
20+
}
21+
22+
function close(uint256 x) public {
23+
assert(block.number != last_number + 123);
24+
}
25+
26+
function far(uint256 x) public {
27+
assert(block.number != type(uint256).max);
28+
}
29+
30+
}

0 commit comments

Comments
 (0)