Skip to content

Commit

Permalink
Improved debug capabilities
Browse files Browse the repository at this point in the history
Soooo much easier to write a hex in repl this way
  • Loading branch information
msooseth committed Dec 17, 2024
1 parent 037ff11 commit 3cf49e8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/EVM/Format.hs
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,8 @@ formatPartial = \case
, "program counter: " <> T.pack (show pc)
, "arguments: "
, indent 2 $ T.unlines . fmap formatSomeExpr $ args
, "simplified arguments: "
, indent 2 $ T.unlines . fmap formatSomeExprSimp $ args
]
]
MaxIterationsReached pc addr -> "Max Iterations Reached in contract: " <> formatAddr addr <> " pc: " <> pack (show pc) <> " To increase the maximum, set a fixed large (or negative) value for `--max-iterations` on the command line"
Expand All @@ -473,6 +475,9 @@ formatPartial = \case
formatSomeExpr :: SomeExpr -> Text
formatSomeExpr (SomeExpr e) = formatExpr e

formatSomeExprSimp :: SomeExpr -> Text
formatSomeExprSimp (SomeExpr e) = formatExpr (Expr.simplify e)

formatExpr :: Expr a -> Text
formatExpr = go
where
Expand Down
29 changes: 29 additions & 0 deletions test/test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import Data.Tree (flatten)
import Data.Typeable
import Data.Vector qualified as V
import Data.Word (Word8, Word64)
import Data.Char (digitToInt)
import GHC.Conc (getNumProcessors)
import System.Directory
import System.Environment
Expand Down Expand Up @@ -4597,3 +4598,31 @@ expectedConcVals nm val = case val of
_ -> internalError $ "unsupported Abi type " <> show nm <> " val: " <> show val <> " val type: " <> showAlter val
where
mkWord = word . encodeAbiValue

hexStringToByteString :: String -> BS.ByteString
hexStringToByteString hexStr
| odd (length hexStr) = error "Hex string has an odd length"
| otherwise = case traverse hexPairToByte (pairs hexStr) of
Just bytes -> (BS.pack bytes)
Nothing -> error "Invalid hex string"
where
-- Convert a pair of hex characters to a byte
hexPairToByte :: (Char, Char) -> Maybe Word8
hexPairToByte (c1, c2) = do
b1 <- hexCharToDigit c1
b2 <- hexCharToDigit c2
return $ fromIntegral (b1 * 16 + b2)

-- Convert a single hex character to its integer value
hexCharToDigit :: Char -> Maybe Int
hexCharToDigit c
| c >= '0' && c <= '9' = Just (digitToInt c)
| c >= 'a' && c <= 'f' = Just (digitToInt c)
| c >= 'A' && c <= 'F' = Just (digitToInt c)
| otherwise = Nothing

-- Split a string into pairs of characters
pairs :: [a] -> [(a, a)]
pairs [] = []
pairs (x:y:xs) = (x, y) : pairs xs
pairs _ = error "Unexpected odd length"

0 comments on commit 3cf49e8

Please sign in to comment.