Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to use specific filter for direct symexec #1251

Merged
merged 2 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/Echidna/Campaign.hs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ runSymWorker callback vm dict workerId initialCorpus name cs = do
-- We can't do callseq vm' [symTx] because callseq might post the full call sequence as an event
newCoverage <- or <$> mapM (\symTx -> snd <$> callseq vm (txsBase <> [symTx])) symTxs

unless newCoverage (pushWorkerEvent SymNoNewCoverage)
unless (newCoverage || null symTxs) (pushWorkerEvent SymNoNewCoverage)

-- | Run a fuzzing campaign given an initial universe state, some tests, and an
-- optional dictionary to generate calls with. Return the 'Campaign' state once
Expand Down
1 change: 1 addition & 0 deletions lib/Echidna/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ instance FromJSON EConfigWithUsage where
<*> v ..:? "server"
<*> v ..:? "symExec" ..!= False
<*> v ..:? "symExecConcolic" ..!= True
<*> v ..:? "symExecTargets" ..!= Nothing
<*> v ..:? "symExecTimeout" ..!= defaultSymExecTimeout
<*> v ..:? "symExecNSolvers" ..!= defaultSymExecNWorkers
<*> v ..:? "symExecMaxIters" ..!= defaultSymExecMaxIters
Expand Down
6 changes: 5 additions & 1 deletion lib/Echidna/SymExec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ exploreContract conf contract tx vm = do
let
isConc = isJust tx
allMethods = Map.elems contract.abiMap
concMethods (Tx { call = SolCall (methodName, _) }) = filter (\method -> method.name == methodName) allMethods
filterMethod name method = method.name == name &&
case conf.campaignConf.symExecTargets of
Just ms -> name `elem` ms
_ -> True
concMethods (Tx { call = SolCall (methodName, _) }) = filter (filterMethod methodName) allMethods
concMethods _ = error "`exploreContract` should only be called with Nothing or Just Tx{call=SolCall _} for its tx argument"
methods = maybe allMethods concMethods tx
timeout = Just (fromIntegral conf.campaignConf.symExecTimeout)
Expand Down
1 change: 1 addition & 0 deletions lib/Echidna/Types/Campaign.hs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ data CampaignConf = CampaignConf
, symExecConcolic :: Bool
-- ^ Whether symbolic execution will be concolic (vs full symbolic execution)
-- Only relevant if symExec is True
, symExecTargets :: Maybe [Text]
, symExecTimeout :: Int
-- ^ Timeout for symbolic execution SMT solver.
-- Only relevant if symExec is True
Expand Down
5 changes: 5 additions & 0 deletions src/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ data Options = Options
, cliCryticArgs :: Maybe String
, cliSolcArgs :: Maybe String
, cliSymExec :: Maybe Bool
, cliSymExecTargets :: Maybe Text
, cliSymExecTimeout :: Maybe Int
, cliSymExecNSolvers :: Maybe Int
}
Expand Down Expand Up @@ -220,6 +221,9 @@ options = Options
<*> optional (option bool $ long "sym-exec"
<> metavar "BOOL"
<> help "Whether to enable the experimental symbolic execution feature.")
<*> optional (option str $ long "sym-exec-target"
<> metavar "SELECTOR"
<> help "Target for the symbolic execution run (assuming sym-exec is enabled). Default is all functions")
<*> optional (option auto $ long "sym-exec-timeout"
<> metavar "INTEGER"
<> help ("Timeout for each symbolic execution run, in seconds (assuming sym-exec is enabled). Default is " ++ show defaultSymExecTimeout))
Expand Down Expand Up @@ -268,6 +272,7 @@ overrideConfig config Options{..} = do
, workers = cliWorkers <|> campaignConf.workers
, serverPort = cliServerPort <|> campaignConf.serverPort
, symExec = fromMaybe campaignConf.symExec cliSymExec
, symExecTargets = (\ t -> Just [t]) =<< cliSymExecTargets
, symExecTimeout = fromMaybe campaignConf.symExecTimeout cliSymExecTimeout
, symExecNSolvers = fromMaybe campaignConf.symExecNSolvers cliSymExecNSolvers
}
Expand Down
3 changes: 3 additions & 0 deletions tests/solidity/basic/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,6 @@ symExecMaxIters: 10
# Number of times we may revisit a particular branching point before we consult the smt solver to check reachability
# only relevant if symExec is true and symExecConcolic is false
symExecAskSMTIters: 1
# List of whitelisted functions for using symbolic/concolic exploration
# only relevant if symExec is true
symExecTargets: null
Loading