Skip to content

Commit

Permalink
Merge pull request #22 from d-xo/hevm-transactions
Browse files Browse the repository at this point in the history
fixes from pairing session
  • Loading branch information
andrevidela authored Sep 26, 2023
2 parents 2c75a03 + 9f3f8bc commit 2d58f45
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
1 change: 1 addition & 0 deletions act/EVM/TH.hs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ makeTxCall tx@(EthTransaction addr caller meth args amt gas) = do
resetState
assign (#tx % #isCreate) False
execState (loadContract addr) <$> get >>= put
assign (#state % #callvalue) (Lit amt)
assign (#state % #calldata) (makeCallData tx)
assign (#state % #caller) (litAddr caller)
assign (#state % #gas) gas
Expand Down
34 changes: 27 additions & 7 deletions act/Examples/HEVM.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@ module Examples.HEVM where
import Act.Prelude
import Control.Monad.Trans.State.Strict
import Data.DoubleWord
import Data.Text (Text)
import Data.Text qualified as T
import Data.Text.IO qualified as T
import Data.Map qualified as Map
import Debug.Trace
import EVM.Exec
import EVM.Format
import EVM.Fetch (zero)
import EVM.Stepper (evm, interpret, runFully)
import EVM.TH
Expand Down Expand Up @@ -116,10 +121,25 @@ initial = loadContracts [("Piggybank", "solitidy/Withdraw.sol")]
outcome = evaluate (playerAutomatic initial) (Kleisli (const $ pure (dummyTx 10)) :- Nil) void

testExec = do
makeTxCall (deposit 100)
run

-- makeTxCall (dummyTx 20)
-- run

interp = interpret (zero 0 (Just 0)) initial (evm testExec >> runFully)
evm $ makeTxCall (deposit 100)
runFully
evm $ makeTxCall (dummyTx 20)
runFully

showVM :: VM -> Text
showVM vm = T.unlines
[ "Contracts:"
, indent 2 . T.unlines . Map.elems $ Map.mapWithKey (\a c -> T.pack (show a) <> " :\n " <> showContract c) vm.env.contracts
, "Storage: " <> (formatExpr vm.env.storage)
, "CallValue: " <> (formatExpr vm.state.callvalue)
, "Result: " <> (T.pack $ show vm.result)
]

showContract :: Contract -> Text
showContract c = T.unlines
[ "balance: " <> (T.pack $ show c.balance)
]

interp = do
vm <- interpret (zero 0 (Just 0)) initial (testExec)
T.putStrLn (showVM vm)
5 changes: 3 additions & 2 deletions solitidy/Withdraw.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

pragma solidity >=0.8.2 <0.9.0;

/**
Expand All @@ -23,6 +22,8 @@ contract Piggybank {
function retrieve(uint256 _amount) public {
require(_balance >= _amount, "insufficient funds.");
_balance = _balance - _amount;
msg.sender.call{value: _amount};
(bool res, ) = msg.sender.call{value: _amount}("");
require(res, "transfer failed!");
}
}

0 comments on commit 2d58f45

Please sign in to comment.