-
Notifications
You must be signed in to change notification settings - Fork 396
/
Copy pathCoverage.hs
34 lines (28 loc) · 1.15 KB
/
Coverage.hs
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
module Echidna.Types.Coverage where
import Control.Lens
import Data.Set (Set, size, map)
import Data.ByteString (ByteString)
import Data.Map.Strict (Map)
import Echidna.Types.Tx (TxResult)
-- Program Counter directly obtained from the EVM
type PC = Int
-- Index per operation in the source code, obtained from the source mapping
type OpIx = Int
-- Stack size from the EVM
type FrameCount = Int
-- Has the transaction ended
type TxEnded = Bool
-- How many reverts we skipped
type RevertsSkipped = Int
-- Basic coverage information
type CoverageInfo = (PC, OpIx, FrameCount, TxResult, TxEnded, RevertsSkipped)
-- Map with the coverage information needed for fuzzing and source code printing
type CoverageMap = Map ByteString (Set CoverageInfo)
-- | Given good point coverage, count unique points.
coveragePoints :: CoverageMap -> Int
coveragePoints = sum . fmap size
-- | Given good point coverage, count the number of unique points but
-- only considering the different instruction PCs (discarding the TxResult).
-- This is useful to report a coverage measure to the user
scoveragePoints :: CoverageMap -> Int
scoveragePoints = sum . fmap (size . Data.Set.map (view _1))