Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show trace on UnknownFailure #1283

Merged
merged 1 commit into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
17 changes: 12 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}
-- Also optionally takes a DappInfo and VM, which are used to show the stack trace.
vmExcept :: MonadThrow m => Maybe (DappInfo, VM Concrete RealWorld) -> EvmError -> m ()
vmExcept traceInfo e =
let trace = uncurry showTraceTree <$> traceInfo
in 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,10 @@ execTxWith executeTx tx = do
#state % #callvalue .= callvalueBeforeVMReset
#traces .= tracesBeforeVMReset
#state % #codeContract .= codeContractBeforeVMReset
(VMFailure x, _) -> vmExcept x
(VMFailure x, _) -> do
dapp <- asks (.dapp)
vm <- get
vmExcept (Just (dapp, vm)) x
(VMSuccess (ConcreteBuf bytecode'), SolCreate _) -> do
-- Handle contract creation.
#env % #contracts % at (LitAddr tx.dst) % _Just % #code .= InitCode mempty mempty
Expand Down
11 changes: 7 additions & 4 deletions lib/Echidna/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,25 @@ 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
-- The `Maybe Text` on `UnknownFailure` is an optional stack trace.
data ExecException = IllegalExec EvmError | UnknownFailure EvmError (Maybe 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!"
++ maybe "" ((" Stack trace:\n" ++) . unpack) trace
where
codeSizeErrorDetails limit actual =
"Configured limit: " ++ show limit ++ ", actual: " ++ show actual
Expand Down
Loading