-
Notifications
You must be signed in to change notification settings - Fork 436
Expand file tree
/
Copy pathSolidity.hs
More file actions
92 lines (78 loc) · 4.98 KB
/
Copy pathSolidity.hs
File metadata and controls
92 lines (78 loc) · 4.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
module Echidna.Types.Solidity where
import Control.Exception (Exception)
import Data.SemVer (Version, version, toString)
import Data.Set (Set)
import Data.Text (Text, unpack)
import EVM.Types (Addr)
minSupportedSolcVersion :: Version
minSupportedSolcVersion = version 0 4 25 [] []
detectVyperVersion :: Version -> Bool
detectVyperVersion x = x > version 0 3 0 [] [] && x < version 0 4 0 [] []
data Filter = Blacklist [Text] | Whitelist [Text] deriving Show
-- | Things that can go wrong trying to load a Solidity file for Echidna testing.
-- Read the 'Show' instance for more detailed explanations.
data SolException
= BadAddr Addr
| CompileFailure String String
| SolcReadFailure
| NoContracts
| TestArgsFound Text
| PropertyWithoutReturn Text
| OptimizationWithWrongReturn Text
| ContractNotFound Text
| NoBytecode Text
| NoFuncs
| NoTests
| ConstructorArgs String
| DeploymentFailed Addr Text
| SetUpCallFailed Text
| NoCryticCompile
| InvalidMethodFilters Filter
| OutdatedSolcVersion Version
instance Show SolException where
show = \case
BadAddr a -> "No contract at " ++ show a ++ " exists"
CompileFailure x y -> "Couldn't compile given file\n" ++ "stdout:\n" ++ x ++ "stderr:\n" ++ y
SolcReadFailure -> "Could not read crytic-export/combined_solc.json"
NoContracts -> "No contracts found in given file"
ContractNotFound c -> "Given contract " ++ show c ++ " not found in given file"
TestArgsFound t -> "Test " ++ show t ++ " has arguments, aborting"
PropertyWithoutReturn t -> "Property " ++ show t ++ " does not return bool. Property functions must have signature: function " ++ unpack t ++ "() public returns (bool)"
OptimizationWithWrongReturn t -> "Optimization " ++ show t ++ " does not return int256. Optimization functions must have signature: function " ++ unpack t ++ "() public returns (int256)"
NoBytecode t -> "No bytecode found for contract " ++ show t
NoFuncs -> "ABI is empty, are you sure your constructor is right?"
NoTests -> "No tests found in ABI. If you are using assert(), use --test-mode assertion"
ConstructorArgs s -> "Constructor arguments are required: " ++ s
NoCryticCompile -> "crytic-compile not installed or not found in PATH. To install it, run:\n pip install crytic-compile"
InvalidMethodFilters f -> "Applying the filter " ++ show f ++ " to the methods produces an empty list. Are you filtering the correct functions using `filterFunctions` or fuzzing the correct contract?"
SetUpCallFailed t -> "Calling the setUp() function failed (revert, out-of-gas, sending ether to a non-payable constructor, etc.):\n" ++ unpack t
DeploymentFailed a t -> "Deploying the contract " ++ show a ++ " failed (revert, out-of-gas, sending ether to a non-payable constructor, etc.):\n" ++ unpack t
OutdatedSolcVersion v -> "Solc version " ++ toString v ++ " detected. Echidna doesn't support versions of solc before " ++ toString minSupportedSolcVersion ++ ". Please use a newer version."
instance Exception SolException
-- | Configuration for loading Solidity for Echidna testing.
data SolConf = SolConf
{ contractAddr :: Addr -- ^ Contract address to use
, deployer :: Addr -- ^ Contract deployer address to use
, sender :: Set Addr -- ^ Sender addresses to use
, balanceAddr :: Integer -- ^ Initial balance of deployer and senders
, balanceContract :: Integer -- ^ Initial balance of contract to test
, codeSize :: Integer -- ^ Max code size for deployed contracts (default 0xffffffff)
, prefix :: Text -- ^ Function name prefix used to denote tests
, disableSlither :: Bool -- ^ Whether or not to skip running Slither
, cryticArgs :: [String] -- ^ Args to pass to crytic
, solcArgs :: String -- ^ Args to pass to @solc@
, solcLibs :: [String] -- ^ List of libraries to load, in order.
, quiet :: Bool -- ^ Suppress @solc@ output, errors, and warnings
, deployContracts :: [(Addr, String)] -- ^ List of contracts to deploy in specific addresses
, deployBytecodes :: [(Addr, Text)] -- ^ List of contracts to deploy in specific addresses
, allContracts :: Bool -- ^ Whether or not to fuzz all contracts
, testMode :: String -- ^ Testing mode
, testDestruction :: Bool -- ^ Whether or not to add a property to detect contract destruction
, allowFFI :: Bool -- ^ Whether or not to allow FFI hevm cheatcode
, methodFilter :: Filter -- ^ List of methods to avoid or include calling during a campaign
, excludeViewPure :: Bool -- ^ Whether to exclude view/pure functions from fuzzing
}
defaultContractAddr :: Addr
defaultContractAddr = 0x00a329c0648769a73afac7f9381e08fb43dbea72
defaultDeployerAddr :: Addr
defaultDeployerAddr = 0x30000