Skip to content

Commit

Permalink
forcelit when showing address in events (#891)
Browse files Browse the repository at this point in the history
  • Loading branch information
ggrieco-tob authored Jan 5, 2023
1 parent 8a265c2 commit 85a3c32
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
4 changes: 3 additions & 1 deletion lib/Echidna/Events.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import EVM.Format (showValues, showError, contractNamePart)
import EVM.Types (Expr(ConcreteBuf), W256, maybeLitWord)
import EVM.Solidity (contractName)

import Echidna.Types.Buffer (forceLit)

type EventMap = M.Map W256 Event
type Events = [Text]

Expand Down Expand Up @@ -53,7 +55,7 @@ extractEvents decodeErrors dappInfo' vm =
showValues [t | (_, t, NotIndexed) <- types] bytes <>
pack " from: " <>
maybe mempty (\ x -> x <> pack "@") maybeContractName <>
pack (show addr)]
pack (show $ forceLit addr)]
Nothing -> [pack $ show word]
ErrorTrace e ->
case e of
Expand Down
9 changes: 2 additions & 7 deletions lib/Echidna/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ import Data.Set (Set)
import Data.Vector qualified as V
import EVM hiding (value)
import EVM.ABI (abiValueType)
import EVM.Types (Expr(ConcreteBuf, Lit), EType(EWord), Addr, W256)
import EVM.Types (Expr(ConcreteBuf, Lit), Addr, W256)

import Echidna.ABI
import Echidna.Types.Random
import Echidna.Orphans.JSON ()
import Echidna.Types.Buffer (viewBuffer)
import Echidna.Types.Buffer (viewBuffer, forceLit)
import Echidna.Types.Signature (SignatureMap, SolCall, ContractA, FunctionHash, BytecodeMemo, lookupBytecodeMetadata)
import Echidna.Types.Tx
import Echidna.Types.World (World(..))
Expand Down Expand Up @@ -148,8 +148,3 @@ setupTx (Tx c s r g gp v (t, b)) = liftSH . sequence_ $
incrementBalance = (env . contracts . ix r . balance) += v
encode (n, vs) = abiCalldata
(encodeSig (n, abiValueType <$> vs)) $ V.fromList vs

forceLit :: Expr 'EWord -> W256
forceLit x = case x of
Lit x' -> x'
_ -> error "expected Lit"
7 changes: 6 additions & 1 deletion lib/Echidna/Types/Buffer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@
module Echidna.Types.Buffer where

import Data.ByteString (ByteString)
import EVM.Types (Expr(ConcreteBuf), EType(Buf))
import EVM.Types (Expr(ConcreteBuf, Lit), EType(Buf), EType(EWord), W256)

viewBuffer :: Expr 'Buf -> Maybe ByteString
viewBuffer (ConcreteBuf b) = Just b
viewBuffer _ = Nothing

forceLit :: Expr 'EWord -> W256
forceLit x = case x of
Lit x' -> x'
_ -> error "expected Lit"

0 comments on commit 85a3c32

Please sign in to comment.