From 08041e4b6e327eb258d34124dfd8c83c7ae1ca4e Mon Sep 17 00:00:00 2001 From: Gustavo Grieco <31542053+ggrieco-tob@users.noreply.github.com> Date: Thu, 11 Jul 2024 15:28:59 +0200 Subject: [PATCH] Initial support for tstore/tload (#1286) * switch to tstore branch on hevm fork. all we should need now is a call to clearTStorages * call clearTStorages after each transaction * test case * bump hevm * bump hevm again --------- Co-authored-by: Sam Alws --- flake.nix | 4 ++-- lib/Echidna/Exec.hs | 3 ++- stack.yaml | 2 +- tstore_test.sol | 24 ++++++++++++++++++++++++ 4 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 tstore_test.sol diff --git a/flake.nix b/flake.nix index a9399895f..b774761bb 100644 --- a/flake.nix +++ b/flake.nix @@ -51,8 +51,8 @@ pkgs.haskellPackages.callCabal2nix "hevm" (pkgs.fetchFromGitHub { owner = "trail-of-forks"; repo = "hevm"; - rev = "2aa7b3e5fea0e0657fe44549ccefbb18f61eb024"; - sha256 = "sha256-/9NMvSOzP0agJ1qEFDN/OQvV0DXRTN3AbntTAzPXbCw="; + rev = "7d4344c5e71d14466e86331af064bab61d06bdad"; + sha256 = "sha256-kts6mdwx5KUrVdNztzewWgNM9xGViAhFIZPnWOUllOU="; }) { secp256k1 = pkgs.secp256k1; }); # FIXME: figure out solc situation, it conflicts with the one from diff --git a/lib/Echidna/Exec.hs b/lib/Echidna/Exec.hs index e6711fe13..99f3aa3ce 100644 --- a/lib/Echidna/Exec.hs +++ b/lib/Echidna/Exec.hs @@ -22,7 +22,7 @@ import Data.Vector qualified as V import Data.Vector.Unboxed.Mutable qualified as VMut import System.Process (readProcessWithExitCode) -import EVM (bytecode, replaceCodeOfSelf, loadContract, exec1, vmOpIx) +import EVM (bytecode, replaceCodeOfSelf, loadContract, exec1, vmOpIx, clearTStorages) import EVM.ABI import EVM.Dapp (DappInfo) import EVM.Exec (exec, vmForEthrunCreation) @@ -98,6 +98,7 @@ execTxWith executeTx tx = do vmResult <- runFully gasLeftAfterTx <- gets (.state.gas) handleErrorsAndConstruction vmResult vmBeforeTx + fromEVM clearTStorages pure (vmResult, gasLeftBeforeTx - gasLeftAfterTx) where runFully = do diff --git a/stack.yaml b/stack.yaml index d09734d4f..d63fc4282 100644 --- a/stack.yaml +++ b/stack.yaml @@ -5,7 +5,7 @@ packages: extra-deps: - git: https://github.com/trail-of-forks/hevm.git - commit: 2aa7b3e5fea0e0657fe44549ccefbb18f61eb024 + commit: 7d4344c5e71d14466e86331af064bab61d06bdad - restless-git-0.7@sha256:346a5775a586f07ecb291036a8d3016c3484ccdc188b574bcdec0a82c12db293,968 - s-cargot-0.1.4.0@sha256:61ea1833fbb4c80d93577144870e449d2007d311c34d74252850bb48aa8c31fb,3525 diff --git a/tstore_test.sol b/tstore_test.sol new file mode 100644 index 000000000..eea83c138 --- /dev/null +++ b/tstore_test.sol @@ -0,0 +1,24 @@ +pragma solidity >=0.8.25; + +contract Test { + uint256 x; + uint256 y; + function A() public { + assembly { + if tload(0) { revert(0,0) } + tstore(0, 1) + if iszero(tload(0)) { revert(0,0) } + } + x = 5; + } + function B() public { + if (x != 5) revert(); + assembly { + if tload(0) { revert(0,0) } + } + y = 10; + } + function echidna_foo() public view returns (bool) { + return y != 10; + } +}