Skip to content

Commit

Permalink
show trace on UnknownFailure
Browse files Browse the repository at this point in the history
  • Loading branch information
samalws-tob committed Jul 2, 2024
1 parent 882c699 commit fe2cf07
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/Echidna/Etheno.hs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ execEthenoTxs et = do
(_ , AccountCreated _) -> pure ()
(Reversion, _) -> void $ put vm
(HandleEffect (Query q), _) -> crashWithQueryError q et
(VMFailure x, _) -> vmExcept x >> M.fail "impossible"
(VMFailure x, _) -> vmExcept Nothing x >> M.fail "impossible"
(VMSuccess (ConcreteBuf bc),
ContractCreated _ ca _ _ _ _) -> do
#env % #contracts % at (LitAddr ca) % _Just % #code .= InitCode mempty mempty
Expand Down
14 changes: 9 additions & 5 deletions lib/Echidna/Exec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ import System.Process (readProcessWithExitCode)

import EVM (bytecode, replaceCodeOfSelf, loadContract, exec1, vmOpIx)
import EVM.ABI
import EVM.Dapp (DappInfo)
import EVM.Exec (exec, vmForEthrunCreation)
import EVM.Fetch qualified
import EVM.Format (hexText)
import EVM.Format (hexText, showTraceTree)
import EVM.Types hiding (Env, Gas)

import Echidna.Events (emptyEvents)
Expand Down Expand Up @@ -70,9 +71,12 @@ pattern Illegal :: VMResult Concrete s
pattern Illegal <- VMFailure (classifyError -> IllegalE)

-- | Given an execution error, throw the appropriate exception.
vmExcept :: MonadThrow m => EvmError -> m ()
vmExcept e = throwM $
case VMFailure e of {Illegal -> IllegalExec e; _ -> UnknownFailure e}
vmExcept :: (MonadThrow m, MonadState (VM Concrete RealWorld) m) => Maybe DappInfo -> EvmError -> m ()
vmExcept maybeDapp e = do
vm <- get
let trace = maybe "" (`showTraceTree` vm) maybeDapp
throwM $
case VMFailure e of {Illegal -> IllegalExec e; _ -> UnknownFailure e trace}

execTxWith
:: (MonadIO m, MonadState (VM Concrete RealWorld) m, MonadReader Env m, MonadThrow m)
Expand Down Expand Up @@ -201,7 +205,7 @@ execTxWith executeTx tx = do
#state % #callvalue .= callvalueBeforeVMReset
#traces .= tracesBeforeVMReset
#state % #codeContract .= codeContractBeforeVMReset
(VMFailure x, _) -> vmExcept x
(VMFailure x, _) -> asks (.dapp) >>= (\dapp -> vmExcept (Just dapp) x)
(VMSuccess (ConcreteBuf bytecode'), SolCreate _) -> do
-- Handle contract creation.
#env % #contracts % at (LitAddr tx.dst) % _Just % #code .= InitCode mempty mempty
Expand Down
10 changes: 6 additions & 4 deletions lib/Echidna/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,24 @@ module Echidna.Types where
import Control.Exception (Exception)
import Control.Monad.State.Strict (MonadState, get, put, MonadIO(liftIO), runStateT)
import Control.Monad.ST (RealWorld, stToIO)
import Data.Text (Text, unpack)
import Data.Word (Word64)
import EVM (initialContract)
import EVM.Types

-- | We throw this when our execution fails due to something other than reversion.
data ExecException = IllegalExec EvmError | UnknownFailure EvmError
data ExecException = IllegalExec EvmError | UnknownFailure EvmError Text

instance Show ExecException where
show = \case
IllegalExec e -> "VM attempted an illegal operation: " ++ show e
UnknownFailure (MaxCodeSizeExceeded limit actual) ->
UnknownFailure (MaxCodeSizeExceeded limit actual) _ ->
"Max code size exceeded. " ++ codeSizeErrorDetails limit actual
UnknownFailure (MaxInitCodeSizeExceeded limit actual) ->
UnknownFailure (MaxInitCodeSizeExceeded limit actual) _ ->
"Max init code size exceeded. " ++ codeSizeErrorDetails limit actual
UnknownFailure e -> "VM failed for unhandled reason, " ++ show e
UnknownFailure e trace -> "VM failed for unhandled reason, " ++ show e
++ ". This shouldn't happen. Please file a ticket with this error message and steps to reproduce!"
++ " Stack trace:\n" ++ unpack trace
where
codeSizeErrorDetails limit actual =
"Configured limit: " ++ show limit ++ ", actual: " ++ show actual
Expand Down

0 comments on commit fe2cf07

Please sign in to comment.