@@ -7,7 +7,7 @@ module Echidna.Exec where
7
7
import Optics.Core
8
8
import Optics.State.Operators
9
9
10
- import Control.Monad (when , forM_ )
10
+ import Control.Monad (when )
11
11
import Control.Monad.Catch (MonadThrow (.. ))
12
12
import Control.Monad.State.Strict (MonadState (get , put ), execState , runStateT , MonadIO (liftIO ), gets , modify' , execStateT )
13
13
import Control.Monad.Reader (MonadReader , ask , asks )
@@ -287,23 +287,20 @@ execTxWithCov tx = do
287
287
addCoverage ! vm = do
288
288
let (pc, opIx, depth) = currentCovLoc vm
289
289
contract = currentContract vm
290
+ contractSize = BS. length . forceBuf . fromJust . view bytecode $ contract
290
291
291
292
maybeCovVec <- lookupUsingCodehashOrInsert env. codehashMap contract env. dapp env. coverageRef $ do
292
- let size = BS. length . forceBuf . fromJust . view bytecode $ contract
293
- if size == 0 then pure Nothing else do
293
+ if contractSize == 0 then pure Nothing else do
294
294
-- IO for making a new vec
295
- vec <- VMut. new size
296
295
-- We use -1 for opIx to indicate that the location was not covered
297
- forM_ [ 0 .. size - 1 ] $ \ i -> VMut. write vec i (- 1 , 0 , 0 )
296
+ vec <- VMut. replicate contractSize (- 1 , 0 , 0 )
298
297
pure $ Just vec
299
298
300
299
statsRef <- getTLS env. statsRef
301
300
maybeStatsVec <- lookupUsingCodehashOrInsert env. codehashMap contract env. dapp statsRef $ do
302
- let size = BS. length . forceBuf . fromJust . view bytecode $ contract
303
- if size == 0 then pure Nothing else do
301
+ if contractSize == 0 then pure Nothing else do
304
302
-- IO for making a new vec
305
- vec <- VMut. new size
306
- forM_ [0 .. size- 1 ] $ \ i -> VMut. write vec i (0 , 0 )
303
+ vec <- VMut. replicate contractSize (0 , 0 )
307
304
pure $ Just vec
308
305
309
306
case maybeCovVec of
@@ -320,7 +317,8 @@ execTxWithCov tx = do
320
317
(_, depths, results) | depth < 64 && not (depths `testBit` depth) -> do
321
318
VMut. write vec pc (opIx, depths `setBit` depth, results `setBit` fromEnum Stop )
322
319
writeIORef covContextRef (True , Just (vec, pc))
323
- _ -> modifyIORef' covContextRef $ \ (new, _) -> (new, Just (vec, pc))
320
+ _ ->
321
+ modifyIORef' covContextRef $ \ (new, _) -> (new, Just (vec, pc))
324
322
325
323
-- | Get the VM's current execution location
326
324
currentCovLoc vm = (vm. state. pc, fromMaybe 0 $ vmOpIx vm, length vm. frames)
0 commit comments