Skip to content
Draft
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
26 changes: 17 additions & 9 deletions lib/Echidna/Solidity.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import Echidna.Etheno (loadEthenoBatch)
import Echidna.Events (extractEvents)
import Echidna.Exec (execTx, execTxWithCov, initialVM)
import Echidna.SourceAnalysis.Slither
import Echidna.Test (createTests, isAssertionMode, isPropertyMode, isDapptestMode)
import Echidna.Test (createTests, isAssertionMode, isPropertyMode, isDapptestMode, isBenchmarkMode)
import Echidna.Types.Campaign (CampaignConf(..))
import Echidna.Types.Config (EConfig(..), Env(..))
import Echidna.Types.Signature
Expand Down Expand Up @@ -155,11 +155,16 @@ filterMethodsWithArgs ms =
[] -> error "No dapptest tests found"
fs -> NE.fromList fs

fullAbiOf :: SolcContract -> NonEmpty SolSignature
fullAbiOf solcContract =
fallback :|
(Map.elems solcContract.abiMap <&> \method -> (method.name, snd <$> method.inputs))

abiOf :: Text -> SolcContract -> NonEmpty SolSignature
abiOf pref solcContract =
fallback :|
filter (not . isPrefixOf pref . fst)
(Map.elems solcContract.abiMap <&> \method -> (method.name, snd <$> method.inputs))
(NE.tail $ fullAbiOf solcContract)

-- | 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
Expand Down Expand Up @@ -262,17 +267,20 @@ mkSignatureMap
mkSignatureMap solConf mainContract contracts = do
let
-- Filter ABI according to the config options
fabiOfc = if isDapptestMode solConf.testMode
then NE.toList $ filterMethodsWithArgs (abiOf solConf.prefix mainContract)
else filterMethods mainContract.contractName solConf.methodFilter $
abiOf solConf.prefix mainContract
fabiOfc
| isDapptestMode solConf.testMode = NE.toList $ filterMethodsWithArgs (abiOf solConf.prefix mainContract)
| isBenchmarkMode solConf.testMode = NE.toList $ fullAbiOf mainContract
| otherwise = filterMethods mainContract.contractName solConf.methodFilter $
abiOf solConf.prefix mainContract
-- Construct ABI mapping for World
abiMapping =
if solConf.allContracts then
Map.fromList $ mapMaybe (\contract ->
let filtered = filterMethods contract.contractName
solConf.methodFilter
(abiOf solConf.prefix contract)
let filtered = if isBenchmarkMode solConf.testMode
then NE.toList $ fullAbiOf contract
else filterMethods contract.contractName
solConf.methodFilter
(abiOf solConf.prefix contract)
in (contract.runtimeCodehash,) <$> NE.nonEmpty filtered)
contracts
else
Expand Down
9 changes: 8 additions & 1 deletion lib/Echidna/Test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ createTest m = EchidnaTest Open m v [] Stop Nothing Nothing

validateTestModeError :: String
validateTestModeError =
"Invalid test mode (should be property, assertion, dapptest, optimization, overflow or exploration)"
"Invalid test mode (should be property, assertion, dapptest, optimization, overflow, exploration or benchmark)"

validateTestMode :: String -> TestMode
validateTestMode s = case s of
Expand All @@ -64,6 +64,7 @@ validateTestMode s = case s of
"exploration" -> s
"overflow" -> s
"optimization" -> s
"benchmark" -> s
_ -> error validateTestModeError

isAssertionMode :: TestMode -> Bool
Expand All @@ -82,6 +83,10 @@ isDapptestMode :: TestMode -> Bool
isDapptestMode "dapptest" = True
isDapptestMode _ = False

isBenchmarkMode :: TestMode -> Bool
isBenchmarkMode "benchmark" = True
isBenchmarkMode _ = False

createTests
:: TestMode
-> Bool
Expand All @@ -92,6 +97,8 @@ createTests
createTests m td ts r ss = case m of
"exploration" ->
[createTest Exploration]
"benchmark" ->
[createTest Exploration]
"overflow" ->
[createTest (CallTest "Integer (over/under)flow" checkOverflowTest)]
"property" ->
Expand Down