Skip to content

Commit

Permalink
Initial support for tstore/tload (#1286)
Browse files Browse the repository at this point in the history
* 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 <sam.alws@trailofbits.com>
  • Loading branch information
ggrieco-tob and samalws-tob authored Jul 11, 2024
1 parent bf14ea4 commit 08041e4
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
4 changes: 2 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion lib/Echidna/Exec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
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/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
Expand Down
24 changes: 24 additions & 0 deletions tstore_test.sol
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit 08041e4

Please sign in to comment.