Skip to content
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
35 changes: 15 additions & 20 deletions bench/bench.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,25 @@ module Main where
import GHC.Natural
import Control.Monad
import Data.Maybe
import System.Environment (lookupEnv, getEnv)
import System.Environment (getEnv)

import qualified Paths_hevm as Paths

import Test.Tasty (localOption, withResource)
import Test.Tasty.Bench
import Data.Functor
import Data.String.Here
import Data.ByteString (ByteString)
import System.FilePath.Posix
import Control.Monad.State.Strict
import qualified Data.Map.Strict as Map
import qualified Data.Text as T
import qualified System.FilePath.Find as Find
import qualified Data.ByteString.Lazy as LazyByteString

import EVM (StorageModel(..))
import EVM.SymExec
import EVM.Solidity
import EVM.Solvers
import EVM.ABI
import EVM.Dapp
import EVM.Types
import EVM.Types (Expr(AbstractStore))
import EVM.Format (hexByteString)
import qualified EVM.TTY as TTY
import qualified EVM.Stepper as Stepper
import qualified EVM.Fetch as Fetch
Expand All @@ -34,10 +30,10 @@ import EVM.Test.BlockchainTests qualified as BCTests

main :: IO ()
main = defaultMain
[ mkbench erc20 "erc20" Nothing [1]
, mkbench (pure vat) "vat" Nothing [4]
, mkbench (pure deposit) "deposit" (Just 32) [4]
, mkbench (pure uniV2Pair) "uniV2" (Just 10) [4]
[ mkbench erc20 "erc20" 0 [1]
, mkbench (pure vat) "vat" 0 [4]
, mkbench (pure deposit) "deposit" 32 [4]
, mkbench (pure uniV2Pair) "uniV2" 10 [4]
, withResource bcjsons (pure . const ()) blockchainTests
]

Expand All @@ -59,7 +55,7 @@ bcjsons = do
parseSuite path = do
contents <- LazyByteString.readFile path
case BCTests.parseBCSuite contents of
Left e -> pure (path, mempty)
Left _ -> pure (path, mempty)
Right tests -> pure (path, tests)

-- | executes all provided bc tests in sequence and accumulates a boolean value representing their success.
Expand All @@ -75,7 +71,6 @@ blockchainTests ts = bench "blockchain-tests" $ nfIO $ do
then pure True
else do
res <- runBCTest c
putStrLn $ " " <> n
pure $ acc && res
) True cases

Expand All @@ -84,7 +79,7 @@ runBCTest :: BCTests.Case -> IO Bool
runBCTest x =
do
let vm0 = BCTests.vmForCase x
result <- execStateT (Stepper.interpret (Fetch.zero 0 (Just 0)) . void $ Stepper.execFully) vm0
result <- Stepper.interpret (Fetch.zero 0 Nothing) vm0 Stepper.runFully
maybeReason <- BCTests.checkExpectation False x result
pure $ isNothing maybeReason

Expand All @@ -94,15 +89,15 @@ runBCTest x =

debugContract :: ByteString -> IO ()
debugContract c = withSolvers CVC5 4 Nothing $ \solvers -> do
let prestate = abstractVM (mkCalldata Nothing []) c Nothing SymbolicS
let prestate = abstractVM (mkCalldata Nothing []) c Nothing AbstractStore False
void $ TTY.runFromVM solvers Nothing Nothing emptyDapp prestate

findPanics :: Solver -> Natural -> Maybe Integer -> ByteString -> IO ()
findPanics :: Solver -> Natural -> Integer -> ByteString -> IO ()
findPanics solver count iters c = do
(_, res) <- withSolvers solver count Nothing $ \s -> do
_ <- withSolvers solver count Nothing $ \s -> do
let opts = defaultVeriOpts
{ maxIter = iters
, askSmtIters = (+ 1) <$> iters
{ maxIter = Just iters
, askSmtIters = iters + 1
}
checkAssert s allPanicCodes c Nothing [] opts
putStrLn "done"
Expand All @@ -112,7 +107,7 @@ findPanics solver count iters c = do
-- assertion violations takes an iteration bound, as well as a list of solver
-- counts to benchmark, allowing us to construct benchmarks that compare the
-- performance impact of increasing solver parallelisation
mkbench :: IO ByteString -> String -> Maybe Integer -> [Natural] -> Benchmark
mkbench :: IO ByteString -> String -> Integer -> [Natural] -> Benchmark
mkbench c name iters counts = localOption WallTime $ env c (bgroup name . bmarks)
where
bmarks c' = concat $ [
Expand Down
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@

# --- packages ----

packages.ci = with pkgs.haskell.lib; dontHaddock (disableLibraryProfiling hevmUnwrapped);
packages.ci = with pkgs.haskell.lib; doBenchmark (dontHaddock (disableLibraryProfiling hevmUnwrapped));
packages.noTests = pkgs.haskell.lib.dontCheck hevmUnwrapped;
packages.hevm = hevmWrapped;
packages.redistributable = hevmRedistributable;
Expand Down