Skip to content

Commit bf14ea4

Browse files
authored
show trace on UnknownFailure (#1283)
1 parent 4b9df9d commit bf14ea4

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

lib/Echidna/Etheno.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ execEthenoTxs et = do
178178
(_ , AccountCreated _) -> pure ()
179179
(Reversion, _) -> void $ put vm
180180
(HandleEffect (Query q), _) -> crashWithQueryError q et
181-
(VMFailure x, _) -> vmExcept x >> M.fail "impossible"
181+
(VMFailure x, _) -> vmExcept Nothing x >> M.fail "impossible"
182182
(VMSuccess (ConcreteBuf bc),
183183
ContractCreated _ ca _ _ _ _) -> do
184184
#env % #contracts % at (LitAddr ca) % _Just % #code .= InitCode mempty mempty

lib/Echidna/Exec.hs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ import System.Process (readProcessWithExitCode)
2424

2525
import EVM (bytecode, replaceCodeOfSelf, loadContract, exec1, vmOpIx)
2626
import EVM.ABI
27+
import EVM.Dapp (DappInfo)
2728
import EVM.Exec (exec, vmForEthrunCreation)
2829
import EVM.Fetch qualified
29-
import EVM.Format (hexText)
30+
import EVM.Format (hexText, showTraceTree)
3031
import EVM.Types hiding (Env, Gas)
3132

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

7273
-- | Given an execution error, throw the appropriate exception.
73-
vmExcept :: MonadThrow m => EvmError -> m ()
74-
vmExcept e = throwM $
75-
case VMFailure e of {Illegal -> IllegalExec e; _ -> UnknownFailure e}
74+
-- Also optionally takes a DappInfo and VM, which are used to show the stack trace.
75+
vmExcept :: MonadThrow m => Maybe (DappInfo, VM Concrete RealWorld) -> EvmError -> m ()
76+
vmExcept traceInfo e =
77+
let trace = uncurry showTraceTree <$> traceInfo
78+
in throwM $
79+
case VMFailure e of {Illegal -> IllegalExec e; _ -> UnknownFailure e trace}
7680

7781
execTxWith
7882
:: (MonadIO m, MonadState (VM Concrete RealWorld) m, MonadReader Env m, MonadThrow m)
@@ -201,7 +205,10 @@ execTxWith executeTx tx = do
201205
#state % #callvalue .= callvalueBeforeVMReset
202206
#traces .= tracesBeforeVMReset
203207
#state % #codeContract .= codeContractBeforeVMReset
204-
(VMFailure x, _) -> vmExcept x
208+
(VMFailure x, _) -> do
209+
dapp <- asks (.dapp)
210+
vm <- get
211+
vmExcept (Just (dapp, vm)) x
205212
(VMSuccess (ConcreteBuf bytecode'), SolCreate _) -> do
206213
-- Handle contract creation.
207214
#env % #contracts % at (LitAddr tx.dst) % _Just % #code .= InitCode mempty mempty

lib/Echidna/Types.hs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,25 @@ module Echidna.Types where
33
import Control.Exception (Exception)
44
import Control.Monad.State.Strict (MonadState, get, put, MonadIO(liftIO), runStateT)
55
import Control.Monad.ST (RealWorld, stToIO)
6+
import Data.Text (Text, unpack)
67
import Data.Word (Word64)
78
import EVM (initialContract)
89
import EVM.Types
910

1011
-- | We throw this when our execution fails due to something other than reversion.
11-
data ExecException = IllegalExec EvmError | UnknownFailure EvmError
12+
-- The `Maybe Text` on `UnknownFailure` is an optional stack trace.
13+
data ExecException = IllegalExec EvmError | UnknownFailure EvmError (Maybe Text)
1214

1315
instance Show ExecException where
1416
show = \case
1517
IllegalExec e -> "VM attempted an illegal operation: " ++ show e
16-
UnknownFailure (MaxCodeSizeExceeded limit actual) ->
18+
UnknownFailure (MaxCodeSizeExceeded limit actual) _ ->
1719
"Max code size exceeded. " ++ codeSizeErrorDetails limit actual
18-
UnknownFailure (MaxInitCodeSizeExceeded limit actual) ->
20+
UnknownFailure (MaxInitCodeSizeExceeded limit actual) _ ->
1921
"Max init code size exceeded. " ++ codeSizeErrorDetails limit actual
20-
UnknownFailure e -> "VM failed for unhandled reason, " ++ show e
22+
UnknownFailure e trace -> "VM failed for unhandled reason, " ++ show e
2123
++ ". This shouldn't happen. Please file a ticket with this error message and steps to reproduce!"
24+
++ maybe "" ((" Stack trace:\n" ++) . unpack) trace
2225
where
2326
codeSizeErrorDetails limit actual =
2427
"Configured limit: " ++ show limit ++ ", actual: " ++ show actual

0 commit comments

Comments
 (0)