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

Upgrade hevm to release/0.54.2 #1331

Merged
merged 3 commits into from
Dec 13, 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
4 changes: 2 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@
hevm = pkgs: pkgs.lib.pipe ((hsPkgs pkgs).callCabal2nix "hevm" (pkgs.fetchFromGitHub {
owner = "ethereum";
repo = "hevm";
rev = "f1f45d3c0d9767a38df04f398d1eab8b66dbe7fc";
sha256 = "sha256-3zEUwcZm4uZZLecvFTgVTV5CAm4qMfKPbLdwO88LnrY=";
rev = "release/0.54.2";
sha256 = "sha256-h0e6QeMBIUkyANYdrGjrqZ2M4fnODOB0gNPQtsrAiL8=";
}) { secp256k1 = pkgs.secp256k1; })
([
pkgs.haskell.lib.compose.dontCheck
Expand Down
2 changes: 1 addition & 1 deletion lib/Echidna/Campaign.hs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import Echidna.Types.Config
import Echidna.Types.Signature (FunctionName)
import Echidna.Types.Test
import Echidna.Types.Test qualified as Test
import Echidna.Types.Tx (TxCall(..), Tx(..), call)
import Echidna.Types.Tx (TxCall(..), Tx(..))
import Echidna.Utility (getTimestamp)

instance MonadThrow m => MonadThrow (RandT g m) where
Expand Down
2 changes: 1 addition & 1 deletion lib/Echidna/Exec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import Echidna.Types (ExecException(..), Gas, fromEVM, emptyAccount)
import Echidna.Types.Config (Env(..), EConfig(..), UIConf(..), OperationMode(..), OutputFormat(Text))
import Echidna.Types.Coverage (CoverageInfo)
import Echidna.Types.Solidity (SolConf(..))
import Echidna.Types.Tx (TxCall(..), Tx, TxResult(..), call, dst, initialTimestamp, initialBlockNumber, getResult)
import Echidna.Types.Tx (TxCall(..), Tx(call, dst), TxResult(..), initialTimestamp, initialBlockNumber, getResult)
import Echidna.Utility (getTimestamp, timePrefix)

-- | Broad categories of execution failures: reversions, illegal operations, and ???.
Expand Down
6 changes: 4 additions & 2 deletions lib/Echidna/SymExec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ exploreContract conf contract tx vm = do
doneChan <- newEmptyMVar
resultChan <- newEmptyMVar

flip runReaderT defaultEnv $ withSolvers Z3 (fromIntegral conf.campaignConf.symExecNSolvers) timeout $ \solvers -> do
flip runReaderT defaultEnv $ withSolvers Z3 (fromIntegral conf.campaignConf.symExecNSolvers) 1 timeout $ \solvers -> do
threadId <- liftIO $ forkIO $ flip runReaderT defaultEnv $ do
res <- forM methods $ \method -> do
let
Expand Down Expand Up @@ -108,7 +108,7 @@ exploreContract conf contract tx vm = do
pure (threadId, resultChan)

-- | Turn the expression returned by `interpret` into into SMT2 values to feed into the solver
manipulateExprInter :: Bool -> Expr End -> [SMT2]
manipulateExprInter :: Bool -> Expr End -> [Either String SMT2]
manipulateExprInter isConc = map (assertProps defaultConfig) . middleStep . map (extractProps . simplify) . flattenExpr . simplify where
middleStep = if isConc then middleStepConc else id
middleStepConc = map singleton . concatMap (go (PBool True))
Expand Down Expand Up @@ -155,6 +155,8 @@ frameStateMakeSymbolic fs
, gas = ()
, returndata = fs.returndata
, static = fs.static
, overrideCaller = fs.overrideCaller
, resetCaller = fs.resetCaller
}

frameMakeSymbolic :: Frame Concrete s -> Frame Symbolic s
Expand Down
2 changes: 1 addition & 1 deletion lib/Echidna/Types/Tx.hs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ getResult = \case
VMFailure BadJumpDestination -> ErrorBadJumpDestination
VMFailure (Revert _) -> ErrorRevert
VMFailure (OutOfGas _ _) -> ErrorOutOfGas
VMFailure (BadCheatCode _) -> ErrorBadCheatCode
VMFailure (BadCheatCode _ _) -> ErrorBadCheatCode
VMFailure StackLimitExceeded -> ErrorStackLimitExceeded
VMFailure IllegalOverflow -> ErrorIllegalOverflow
VMFailure StateChangeWhileStatic -> ErrorStateChangeWhileStatic
Expand Down
2 changes: 1 addition & 1 deletion src/test/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import Echidna.Types.Campaign
import Echidna.Types.Signature (ContractName)
import Echidna.Types.Solidity (SolConf(..))
import Echidna.Types.Test
import Echidna.Types.Tx (Tx(..), TxCall(..), call)
import Echidna.Types.Tx (Tx(..), TxCall(..))
import Echidna.Types.World (World(..))

import EVM.Solidity (Contracts(..), BuildOutput(..), SolcContract(..))
Expand Down
8 changes: 7 additions & 1 deletion src/test/Tests/Cheat.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Tests.Cheat (cheatTests) where

import Test.Tasty (TestTree, testGroup)

import Common (testContract', solcV, solved)
import Common (testContract', solcV, solved, passed)

import Echidna.Types.Campaign (WorkerType(..))

Expand All @@ -15,4 +15,10 @@ cheatTests =
[ ("echidna_ffi passed", solved "echidna_ffi") ]
, testContract' "cheat/gas.sol" (Just "TestCheatGas") (Just (> solcV (0,5,0))) (Just "cheat/ffi.yaml") False FuzzWorker
[ ("echidna_gas_zero passed", solved "echidna_gas_zero") ]
, testContract' "cheat/prank.sol" (Just "TestPrank") (Just (> solcV (0,5,0))) (Just "cheat/prank.yaml") False FuzzWorker
[ ("withPrank failed", passed "withPrank")
, ("withStartPrank failed", passed "withStartPrank")
, ("withStartPrankStopPrank failed", passed "withStartPrankStopPrank")
, ("withNothing failed", passed "withNothing")
]
]
2 changes: 1 addition & 1 deletion stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ packages:

extra-deps:
- git: https://github.com/ethereum/hevm.git
commit: f1f45d3c0d9767a38df04f398d1eab8b66dbe7fc
commit: 037ff11779d0089378f01cb103db1171dc642be2

- smt2-parser-0.1.0.1@sha256:1e1a4565915ed851c13d1e6b8bb5185cf5d454da3b43170825d53e221f753d77,1421
- spawn-0.3@sha256:b91e01d8f2b076841410ae284b32046f91471943dc799c1af77d666c72101f02,1162
Expand Down
94 changes: 94 additions & 0 deletions tests/solidity/cheat/prank.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
interface IHevm {
function prank(address newSender) external;
function startPrank(address sender) external;
function stopPrank() external;
}

contract ExpectedCreator {
event Sender(address);
event AssertionFailed(string);
IHevm constant vm = IHevm(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D);

constructor(address s) public {
if (s != msg.sender) {
emit Sender(msg.sender);
emit AssertionFailed("fail on construct");
}
}
}

contract SenderVerifierChild {
event Sender(address);
event AssertionFailed(string);
IHevm constant vm = IHevm(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D);

function verifyMsgSender(address s) public {
if (s != msg.sender) {
emit Sender(msg.sender);
emit AssertionFailed("fail on inner call");
}
}
}

contract SenderVerifierParent {
event Sender(address);
event AssertionFailed(string);
IHevm constant vm = IHevm(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D);

SenderVerifierChild c;
constructor() public {
c = new SenderVerifierChild();
}

function verifyMsgSender(address s) public {
if (s != msg.sender) {
emit Sender(msg.sender);
emit AssertionFailed("fail on first call");
}
c.verifyMsgSender(address(this));
new ExpectedCreator(address(this));
}
}

contract TestPrank {
IHevm constant vm = IHevm(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D);

SenderVerifierParent p;
constructor() public {
p = new SenderVerifierParent();
}

function withPrank() public {
vm.prank(address(0x123));
p.verifyMsgSender(address(0x123));
p.verifyMsgSender(address(this));

vm.prank(address(0x123));
new ExpectedCreator(address(0x123));
new ExpectedCreator(address(this));
}

function withStartPrank() public {
vm.startPrank(address(0x123));
p.verifyMsgSender(address(0x123));
p.verifyMsgSender(address(0x123));
new ExpectedCreator(address(0x123));
new ExpectedCreator(address(0x123));
}

function withStartPrankStopPrank() public {
vm.startPrank(address(0x123));
p.verifyMsgSender(address(0x123));
p.verifyMsgSender(address(0x123));
new ExpectedCreator(address(0x123));
new ExpectedCreator(address(0x123));
vm.stopPrank();
p.verifyMsgSender(address(this));
new ExpectedCreator(address(this));
}

function withNothing() public {
p.verifyMsgSender(address(this));
new ExpectedCreator(address(this));
}
}
3 changes: 3 additions & 0 deletions tests/solidity/cheat/prank.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
testLimit: 1000
seqLen: 10
testMode: assertion
Loading