Skip to content

Commit 4ccf67a

Browse files
authored
Merge pull request #1346 from crytic/dev-hevm-update
Update `hevm` to `9924e80dd0226c1f3e1eda651bbeb3558f419843`
2 parents f889503 + 4dcd863 commit 4ccf67a

File tree

14 files changed

+58
-29
lines changed

14 files changed

+58
-29
lines changed

.github/scripts/install-libff.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,14 @@ if [ "$HOST_OS" = "Linux" ] && [ "$(uname -m)" = "aarch64" ]; then
3535
fi
3636

3737
if [ "$HOST_OS" = "Windows" ]; then
38-
ARGS+=("-G" "Ninja")
38+
ARGS+=("-G" "Ninja" "-DCMAKE_TOOLCHAIN_FILE=$PWD/../.github/scripts/windows-ghc-toolchain.cmake")
3939
sed -i 's/find_library(GMP_LIBRARY gmp)/find_library(GMP_LIBRARY NAMES libgmp.a)/' CMakeLists.txt
4040

41+
# This ends up causing the system headers to be included with -I and
42+
# thus they override the GHC mingw compiler ones. So this removes it
43+
# and re-adds the include with idirafter via the toolchain file
44+
sed -i '/INCLUDE_DIRECTORIES.*OPENSSL_INCLUDE_DIR/d' CMakeLists.txt
45+
4146
# Apply windows-specific libff patch carried by hevm
4247
curl -fsSL https://raw.githubusercontent.com/ethereum/hevm/1abe4c79eeada928acc279b631c48eeb2a1376c2/.github/scripts/libff.patch | patch -p1
4348
fi
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
set(CMAKE_SYSTEM_NAME Windows)
2+
3+
set(CMAKE_C_COMPILER "$ENV{HASKELL_MINGW_PATH}/bin/cc.exe")
4+
set(CMAKE_CXX_COMPILER "$ENV{HASKELL_MINGW_PATH}/bin/c++.exe")
5+
6+
set(CMAKE_C_FLAGS "-idirafter $ENV{SYSTEM_MINGW_PATH}/include")
7+
set(CMAKE_CXX_FLAGS "-idirafter $ENV{SYSTEM_MINGW_PATH}/include")
8+
9+
set(CMAKE_FIND_ROOT_PATH "$ENV{HASKELL_MINGW_PATH}")
10+
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH)
11+
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH)
12+
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH)

.github/workflows/ci.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ jobs:
4040
- name: Get Packages (Windows)
4141
uses: msys2/setup-msys2@v2
4242
if: runner.os == 'Windows'
43+
id: msys2
4344
with:
4445
msystem: CLANG64
4546
path-type: minimal
@@ -104,11 +105,16 @@ jobs:
104105
if: runner.os == 'Windows'
105106
run: |
106107
HASKELL_PATHS="$(cygpath -u "$GHC_PATH"):$(cygpath -u "$CABAL_PATH"):$(cygpath -u "$STACK_PATH")"
108+
HASKELL_MINGW_PATH="$(cygpath -u "$GHC_PATH/../mingw")"
109+
SYSTEM_MINGW_PATH="$(cygpath -m "$MSYS2_LOCATION/$MSYSTEM")"
107110
echo "HASKELL_PATHS=$HASKELL_PATHS" >> "$GITHUB_ENV"
111+
echo "HASKELL_MINGW_PATH=$HASKELL_MINGW_PATH" >> "$GITHUB_ENV"
112+
echo "SYSTEM_MINGW_PATH=$SYSTEM_MINGW_PATH" >> "$GITHUB_ENV"
108113
env:
109114
GHC_PATH: ${{ steps.stack.outputs.ghc-path }}
110115
CABAL_PATH: ${{ steps.stack.outputs.cabal-path }}
111116
STACK_PATH: ${{ steps.stack.outputs.stack-path }}
117+
MSYS2_LOCATION: ${{ steps.msys2.outputs.msys2-location }}
112118

113119
- name: Checkout
114120
uses: actions/checkout@v4
@@ -140,7 +146,7 @@ jobs:
140146
- name: Build Libraries
141147
run: |
142148
if [ "$HOST_OS" = "Windows" ]; then
143-
export PATH="$(cygpath -u "$GHC_BIN_PATH/../mingw/bin"):$PATH"
149+
export PATH="$(cygpath -u "$HASKELL_MINGW_PATH/bin"):$PATH"
144150
fi
145151
.github/scripts/install-libsecp256k1.sh
146152
.github/scripts/install-libff.sh

flake.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@
5252
hevm = pkgs: pkgs.lib.pipe ((hsPkgs pkgs).callCabal2nix "hevm" (pkgs.fetchFromGitHub {
5353
owner = "ethereum";
5454
repo = "hevm";
55-
rev = "release/0.54.2";
56-
sha256 = "sha256-h0e6QeMBIUkyANYdrGjrqZ2M4fnODOB0gNPQtsrAiL8=";
55+
rev = "9924e80dd0226c1f3e1eda651bbeb3558f419843";
56+
sha256 = "sha256-HGvWD7AjqKinE/oYu9L4b2HetcKrO3B+hNCzJ761XAk=";
5757
}) { secp256k1 = pkgs.secp256k1; })
5858
([
5959
pkgs.haskell.lib.compose.dontCheck

lib/Echidna/ABI.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ getRandomInt :: MonadRandom m => Int -> m Integer
191191
getRandomInt n =
192192
getRandomR =<< Random.weighted
193193
[ ((-1023, 1023), 1)
194-
, ((-1 * 2 ^ (n - 1), 2 ^ (n - 1) - 1), 9)
194+
, (((-1) * 2 ^ (n - 1), 2 ^ (n - 1) - 1), 9)
195195
]
196196

197197
-- | Synthesize a random 'AbiValue' given its 'AbiType'. Doesn't use a dictionary.

lib/Echidna/Etheno.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import Text.Read (readMaybe)
2525

2626
import EVM
2727
import EVM.ABI (AbiType(..), AbiValue(..), decodeAbiValue, selector)
28+
import EVM.Effects (defaultConfig)
2829
import EVM.Exec (exec)
2930
import EVM.Types
3031

@@ -173,7 +174,7 @@ execEthenoTxs et = do
173174
runFully vm
174175
where
175176
runFully vm = do
176-
res <- fromEVM exec
177+
res <- fromEVM $ exec defaultConfig
177178
case (res, et) of
178179
(_ , AccountCreated _) -> pure ()
179180
(Reversion, _) -> void $ put vm

lib/Echidna/Events.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import Data.Vector (fromList)
1717
import EVM (traceForest)
1818
import EVM.ABI (Event(..), Indexed(..), decodeAbiValue, AbiType(..), AbiValue(..))
1919
import EVM.Dapp (DappContext(..), DappInfo(..))
20+
import EVM.Expr (maybeLitWordSimp)
2021
import EVM.Format (showValues, showError, contractNamePart)
2122
import EVM.Solidity (SolcContract(..))
2223
import EVM.Types
@@ -37,7 +38,7 @@ extractEvents decodeErrors dappInfo vm =
3738
where
3839
showTrace trace =
3940
let ?context = DappContext { info = dappInfo, contracts = vm.env.contracts, labels = vm.labels } in
40-
let codehash' = fromJust $ maybeLitWord trace.contract.codehash
41+
let codehash' = fromJust $ maybeLitWordSimp trace.contract.codehash
4142
maybeContractName = maybeContractNameFromCodeHash dappInfo codehash'
4243
in case trace.tracedata of
4344
EventTrace addr bytes (topic:_) ->

lib/Echidna/Exec.hs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import System.Process qualified as P
2626
import EVM (bytecode, replaceCodeOfSelf, loadContract, exec1, vmOpIx, clearTStorages)
2727
import EVM.ABI
2828
import EVM.Dapp (DappInfo)
29+
import EVM.Effects (defaultConfig)
2930
import EVM.Exec (exec, vmForEthrunCreation)
3031
import EVM.Fetch qualified
3132
import EVM.Format (hexText, showTraceTree)
@@ -240,7 +241,7 @@ execTx
240241
=> VM Concrete RealWorld
241242
-> Tx
242243
-> m ((VMResult Concrete RealWorld, Gas), VM Concrete RealWorld)
243-
execTx vm tx = runStateT (execTxWith (fromEVM exec) tx) vm
244+
execTx vm tx = runStateT (execTxWith (fromEVM (exec defaultConfig)) tx) vm
244245

245246
-- | A type alias for the context we carry while executing instructions
246247
type CoverageContext = (Bool, Maybe (VMut.IOVector CoverageInfo, Int))
@@ -289,7 +290,7 @@ execTxWithCov tx = do
289290

290291
-- | Execute one instruction on the EVM
291292
stepVM :: VM Concrete RealWorld -> IO (VM Concrete RealWorld)
292-
stepVM = stToIO . execStateT exec1
293+
stepVM = stToIO . execStateT (exec1 defaultConfig)
293294

294295
-- | Add current location to the CoverageMap
295296
addCoverage :: VM Concrete RealWorld -> IO ()
@@ -339,6 +340,6 @@ initialVM :: Bool -> ST s (VM Concrete s)
339340
initialVM ffi = do
340341
vm <- vmForEthrunCreation mempty
341342
pure $ vm & #block % #timestamp .~ Lit initialTimestamp
342-
& #block % #number .~ initialBlockNumber
343+
& #block % #number .~ Lit initialBlockNumber
343344
& #env % #contracts .~ mempty -- fixes weird nonce issues
344345
& #config % #allowFFI .~ ffi

lib/Echidna/SourceAnalysis/Slither.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ instance FromJSON SlitherInfo where
115115
:: Map ContractName (Map FunctionName [[Maybe AbiValue]])
116116
<- o .: "constants_used" >>= (traverse . traverse . traverse . traverse) parseConstant
117117
-- flatten [[AbiValue]], the array probably shouldn't be nested, fix it in Slither
118-
let constantValues = (fmap . fmap) (catMaybes . concat) constantValues'
118+
let constantValues = (fmap . fmap) (concatMap catMaybes) constantValues'
119119
functionsRelations <- o .: "functions_relations"
120120
generationGraph <-
121121
(traverse . traverse) (withObject "relations" (.: "impacts")) functionsRelations

lib/Echidna/SourceMapping.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ import Data.Maybe (mapMaybe)
1111
import Data.Vector qualified as V
1212
import Echidna.Symbolic (forceWord)
1313
import EVM.Dapp (DappInfo(..), findSrc)
14+
import EVM.Expr (maybeLitByteSimp)
1415
import EVM.Solidity (SolcContract(..))
15-
import EVM.Types (Contract(..), ContractCode(..), RuntimeCode(..), W256, maybeLitByte)
16+
import EVM.Types (Contract(..), ContractCode(..), RuntimeCode(..), W256)
1617

1718
-- | Map from contracts' codehashes to their compile-time codehash.
1819
-- This is relevant when the immutables solidity feature is used;
@@ -80,7 +81,7 @@ findSrcByMetadata contr dapp = find compareMetadata (snd <$> Map.elems dapp.solc
8081
(UnknownCode _) -> Nothing
8182
(InitCode c _) -> Just c
8283
(RuntimeCode (ConcreteRuntimeCode c)) -> Just c
83-
(RuntimeCode (SymbolicRuntimeCode c)) -> Just $ BS.pack $ mapMaybe maybeLitByte $ V.toList c
84+
(RuntimeCode (SymbolicRuntimeCode c)) -> Just $ BS.pack $ mapMaybe maybeLitByteSimp $ V.toList c
8485

8586
getBytecodeMetadata :: ByteString -> ByteString
8687
getBytecodeMetadata bs =

0 commit comments

Comments
 (0)