|
2 | 2 |
|
3 | 3 | module Echidna.SourceAnalysis.Slither where |
4 | 4 |
|
| 5 | +import Control.Applicative ((<|>)) |
5 | 6 | import Data.Aeson ((.:), (.:?), (.!=), eitherDecode, parseJSON, withEmbeddedJSON, withObject) |
6 | 7 | import Data.Aeson.Types (FromJSON, Parser, Value(String)) |
7 | 8 | import Data.ByteString.Base16 qualified as BS16 (decode) |
@@ -40,11 +41,53 @@ enhanceConstants si = |
40 | 41 | enh (AbiString s) = makeArrayAbiValues s |
41 | 42 | enh v = [v] |
42 | 43 |
|
| 44 | +data AssertLocation = AssertLocation |
| 45 | + { start :: Int |
| 46 | + , filenameRelative :: String |
| 47 | + , filenameAbsolute :: String |
| 48 | + , assertLines :: [Int] |
| 49 | + , startColumn :: Int |
| 50 | + , endingColumn :: Int |
| 51 | + } deriving (Show) |
| 52 | + |
| 53 | +-- | Assertion listing for a contract. |
| 54 | +-- There are two possibilities because different solc's give different formats. |
| 55 | +-- We either have a list of functions that have assertions, or a full listing of individual assertions. |
| 56 | +data ContractAssertListing |
| 57 | + = AssertFunctionList [FunctionName] |
| 58 | + | AssertLocationList (Map FunctionName [AssertLocation]) |
| 59 | + deriving (Show) |
| 60 | + |
| 61 | +type AssertListingByContract = Map ContractName ContractAssertListing |
| 62 | + |
| 63 | +-- | Get a list of functions that have assertions |
| 64 | +assertFunctionList :: ContractAssertListing -> [FunctionName] |
| 65 | +assertFunctionList (AssertFunctionList l) = l |
| 66 | +assertFunctionList (AssertLocationList m) = map fst $ filter (not . null . snd) $ Map.toList m |
| 67 | + |
| 68 | +-- | Get a list of assertions, or an empty list if we don't have enough info |
| 69 | +assertLocationList :: ContractAssertListing -> [AssertLocation] |
| 70 | +assertLocationList (AssertFunctionList _) = [] |
| 71 | +assertLocationList (AssertLocationList m) = concat $ Map.elems m |
| 72 | + |
| 73 | +instance FromJSON AssertLocation where |
| 74 | + parseJSON = withObject "" $ \o -> do |
| 75 | + start <- o.: "start" |
| 76 | + filenameRelative <- o.: "filename_relative" |
| 77 | + filenameAbsolute <- o.: "filename_absolute" |
| 78 | + assertLines <- o.: "lines" |
| 79 | + startColumn <- o.: "starting_column" |
| 80 | + endingColumn <- o.: "ending_column" |
| 81 | + pure AssertLocation {..} |
| 82 | + |
| 83 | +instance FromJSON ContractAssertListing where |
| 84 | + parseJSON x = (AssertFunctionList <$> parseJSON x) <|> (AssertLocationList <$> parseJSON x) |
| 85 | + |
43 | 86 | -- we loose info on what constants are in which functions |
44 | 87 | data SlitherInfo = SlitherInfo |
45 | 88 | { payableFunctions :: Map ContractName [FunctionName] |
46 | 89 | , constantFunctions :: Map ContractName [FunctionName] |
47 | | - , asserts :: Map ContractName [FunctionName] |
| 90 | + , asserts :: AssertListingByContract |
48 | 91 | , constantValues :: Map ContractName (Map FunctionName [AbiValue]) |
49 | 92 | , generationGraph :: Map ContractName (Map FunctionName [FunctionName]) |
50 | 93 | , solcVersions :: [Version] |
|
0 commit comments