Skip to content

Commit ffcd987

Browse files
committed
fix warnings
1 parent fef5520 commit ffcd987

26 files changed

+141
-169
lines changed

act/Act/Execution.hs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
{-# LANGUAGE DuplicateRecordFields
2-
, NoFieldSelectors
3-
, OverloadedRecordDot
4-
#-}
1+
{-# LANGUAGE DuplicateRecordFields #-}
2+
{-# LANGUAGE OverloadedRecordDot #-}
3+
{-# LANGUAGE NoFieldSelectors #-}
4+
55
module Act.Execution where
66

77
import Act.Prelude
8-
import Data.Bifunctor
9-
import EVM.Types
10-
import Data.ByteString
118

129
-- An ACT contract is a pair of a _name_ and a function that updates
1310
-- a state `s` given a transaction
@@ -33,3 +30,4 @@ combine contracts (t : ts) globalState =
3330
case Prelude.lookup (t.contract) contracts of
3431
Just trans -> let newState = trans globalState t in combine contracts ts newState
3532
Nothing -> error ("got illegal transaction " ++ show t)
33+
combine _ [] st = error "we were not given any transactions"

act/Act/Prelude.hs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
{-# LANGUAGE DuplicateRecordFields
2-
, NoFieldSelectors
3-
, OverloadedRecordDot
4-
#-}
5-
module Act.Prelude (Word256, EthTransaction(..), Transaction (..), AbiType (..), AbiValue(..)) where
1+
{-# LANGUAGE DuplicateRecordFields #-}
2+
{-# LANGUAGE OverloadedRecordDot #-}
3+
{-# LANGUAGE NoFieldSelectors #-}
64

7-
import EVM.ABI (AbiType (..), AbiValue (..))
8-
import EVM.Solidity (SlotType)
9-
import EVM.Types (Addr, W256)
5+
module Act.Prelude (Word256, EthTransaction (..), Transaction (..), AbiType (..), AbiValue (..)) where
106

11-
import Data.Text
127
import Data.DoubleWord (Word256)
8+
import Data.Text
9+
import EVM.ABI (AbiType (..), AbiValue (..))
10+
import EVM.Types (Addr, W256)
1311

1412
data Transaction = Transaction
1513
{ contract :: String,

act/Act/TH.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ mapMethod2TH (Behaviour methodName _ (Interface _ args) _ _ _ actExp _) = do
154154
rewriteOne (Constant loc) = pure (mkName "unimplemented", VarE (mkName "undefined"))
155155
rewriteOne (Rewrite (Update ty (Item _ _ (SVar _ _ varName)) newValue)) =
156156
(mkName varName,) <$> mapExp newValue
157+
rewriteOne _ = error "unsupported method"
157158

158159
-- The rest of this file is for debugging purposes
159160

act/Act/TH/Extractor.hs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import Act.Prelude
88
import Act.Utils
99
import Data.Data
1010
import Data.List
11-
import EVM.ABI
1211
import Language.Haskell.TH.Syntax as TH
1312
import Syntax.Annotated
1413

@@ -65,17 +64,17 @@ generateExtract (name, signature) = do
6564
]
6665

6766
constructorNameForType :: String -> AbiType -> Pat
68-
constructorNameForType name (AbiUIntType _) = ConP (mkName "AbiUInt") [] [WildP, VarP (mkName name)]
69-
constructorNameForType name (AbiIntType _) = ConP (mkName "AbiInt") [] [WildP, VarP (mkName name)]
70-
constructorNameForType name (AbiAddressType) = ConP (mkName "AbiAddress") [] [VarP (mkName name)]
71-
constructorNameForType name (AbiBoolType) = ConP (mkName "AbiBool") [] [VarP (mkName name)]
72-
constructorNameForType name (AbiBytesType _) = ConP (mkName "AbiBytes") [] [WildP, VarP (mkName name)]
73-
constructorNameForType name (AbiBytesDynamicType) = ConP (mkName "AbiBytesDynamic") [] [VarP (mkName name)]
74-
constructorNameForType name (AbiStringType) = ConP (mkName "AbiString") [] [VarP (mkName name)]
67+
constructorNameForType name (AbiUIntType _) = ConP (mkName "AbiUInt") [] [WildP, VarP (mkName name)]
68+
constructorNameForType name (AbiIntType _) = ConP (mkName "AbiInt") [] [WildP, VarP (mkName name)]
69+
constructorNameForType name (AbiAddressType) = ConP (mkName "AbiAddress") [] [VarP (mkName name)]
70+
constructorNameForType name (AbiBoolType) = ConP (mkName "AbiBool") [] [VarP (mkName name)]
71+
constructorNameForType name (AbiBytesType _) = ConP (mkName "AbiBytes") [] [WildP, VarP (mkName name)]
72+
constructorNameForType name (AbiBytesDynamicType) = ConP (mkName "AbiBytesDynamic") [] [VarP (mkName name)]
73+
constructorNameForType name (AbiStringType) = ConP (mkName "AbiString") [] [VarP (mkName name)]
7574
constructorNameForType name (AbiArrayDynamicType ty) = ConP (mkName "AbiArrayDynamic") [] [WildP, VarP (mkName name)]
76-
constructorNameForType name (AbiArrayType size ty) = ConP (mkName "AbiArray") [] [WildP, WildP, VarP (mkName name)]
77-
constructorNameForType name (AbiTupleType types) = ConP (mkName "AbiTuple") [] [VarP (mkName name)]
78-
constructorNameForType name (AbiFunctionType) = error "functions unsupported"
75+
constructorNameForType name (AbiArrayType size ty) = ConP (mkName "AbiArray") [] [WildP, WildP, VarP (mkName name)]
76+
constructorNameForType name (AbiTupleType types) = ConP (mkName "AbiTuple") [] [VarP (mkName name)]
77+
constructorNameForType name (AbiFunctionType) = error "functions unsupported"
7978

8079
-- Generate a pattern for a given declaration, the declaration tells us the type of the ACT
8180
-- variable and therefore the constructor to use for out `AbiType` the name will be used as

act/Act/TH/State.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
module Act.TH.State where
44

55
import Act.Utils
6-
import Data.Bifunctor
76
import qualified Data.Map as M
87
import Language.Haskell.TH.Syntax
98
import Syntax.Annotated (Id, SlotType, Store)

act/Act/Utils.hs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@
44
module Act.Utils where
55

66
import Data.Char (toLower, toUpper)
7+
import Data.DoubleWord (Word256)
8+
import Data.Vector (Vector)
79
import EVM.ABI
810
import EVM.Types (Addr)
911
import Language.Haskell.TH.Syntax as TH
1012
import Syntax.Annotated as ACT
11-
import Data.DoubleWord (Word256)
12-
import Data.Vector (Vector)
13-
1413

1514
storeTypeName :: String -> Name
1615
storeTypeName storeName = mkName (capitalise (storeName ++ "State"))

act/EVM/TH.hs

Lines changed: 98 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,112 +1,129 @@
1-
{-# LANGUAGE DuplicateRecordFields, OverloadedLabels, OverloadedRecordDot #-}
1+
{-# LANGUAGE DuplicateRecordFields #-}
2+
{-# LANGUAGE OverloadedLabels #-}
3+
{-# LANGUAGE OverloadedRecordDot #-}
4+
{-# LANGUAGE ScopedTypeVariables #-}
25
{-# LANGUAGE TemplateHaskell #-}
6+
{-# LANGUAGE TupleSections #-}
37

48
module EVM.TH where
59

6-
import Prelude hiding (FilePath, readFile)
7-
import Data.Text (Text, pack, unpack)
8-
import Data.Text.IO (readFile)
9-
import Data.Map as Map
10+
import Act.Prelude (EthTransaction (..))
11+
import Control.Monad.Trans.State.Strict (State, put)
1012
import Data.ByteString (ByteString)
11-
import Data.Vector as Vector (fromList)
12-
import Data.Tree.Zipper qualified as Zipper
13-
14-
import Language.Haskell.TH.Syntax as TH
13+
import Data.Map as Map
14+
import Data.Text (Text, unpack)
15+
import Data.Text.IO (readFile)
16+
import qualified Data.Tree.Zipper as Zipper
17+
import Data.Vector as Vector (fromList)
18+
import EVM (blankState, initialContract)
1519
import EVM.ABI
20+
import EVM.FeeSchedule
1621
import EVM.Solidity (solcRuntime)
1722
import EVM.Types
18-
import EVM.FeeSchedule
19-
import EVM (blankState, initialContract)
20-
import Act.Prelude (EthTransaction(..))
21-
import Control.Monad.Trans.State.Strict (State, put)
22-
2323
import GHC.IO.Unsafe
24+
import Language.Haskell.TH.Syntax as TH
25+
import Prelude hiding (FilePath, readFile)
2426

27+
-- put this in sttate.callData
28+
-- run it to execute the transaction
29+
-- put more for subsequent calls
30+
-- run more for more results
2531
makeCallData :: EthTransaction -> ByteString
2632
makeCallData (EthTransaction _ method args _ _) =
2733
abiMethod method (AbiTuple (Vector.fromList args))
2834

2935
emptyVM :: [(Addr, ByteString)] -> VM
30-
emptyVM contracts = VM
31-
{ result = Nothing
32-
, state = blankState
33-
, frames = []
34-
, env = envForContracts contracts
35-
, block = emptyBlock
36-
, tx = emptyTransaction
37-
, logs = []
38-
, traces = Zipper.fromForest mempty
39-
, cache = Cache mempty mempty mempty
40-
, burned = 0
41-
, iterations = mempty
42-
, constraints = []
43-
, keccakEqs = []
44-
, allowFFI = True
45-
, overrideCaller = Nothing
46-
}
47-
where
48-
-- question: Is that a reasonable empty first block?
49-
emptyBlock :: Block
50-
emptyBlock = Block
51-
{ coinbase = 0
52-
, timestamp = Lit 0
53-
, number = 0
54-
, prevRandao = 0
55-
, maxCodeSize = 0
56-
, gaslimit = 0
57-
, baseFee = 0
58-
, schedule = berlin -- specifically this, what is it suppsoed to be?
59-
}
60-
emptyTransaction :: TxState
61-
emptyTransaction = TxState
62-
{ gasprice = 0
63-
, gaslimit = 0
64-
, priorityFee = 0
65-
, origin = 0
66-
, toAddr = 0
67-
, value = Lit 0
68-
, substate = emptySubState
69-
, isCreate = True
70-
, txReversion = mempty
71-
}
72-
emptySubState :: SubState
73-
emptySubState = SubState
74-
{ selfdestructs = []
75-
, touchedAccounts = []
76-
, accessedAddresses = mempty
77-
, accessedStorageKeys = mempty
78-
, refunds = []
36+
emptyVM contracts =
37+
VM
38+
{ result = Nothing,
39+
state = blankState,
40+
frames = [],
41+
env = envForContracts contracts,
42+
block = emptyBlock,
43+
tx = emptyTransaction,
44+
logs = [],
45+
traces = Zipper.fromForest mempty,
46+
cache = Cache mempty mempty mempty,
47+
burned = 0,
48+
iterations = mempty,
49+
constraints = [],
50+
keccakEqs = [],
51+
allowFFI = True,
52+
overrideCaller = Nothing
7953
}
54+
where
55+
-- question: Is that a reasonable empty first block?
56+
emptyBlock :: Block
57+
emptyBlock =
58+
Block
59+
{ coinbase = 0,
60+
timestamp = Lit 0,
61+
number = 0,
62+
prevRandao = 0,
63+
maxCodeSize = 0,
64+
gaslimit = 0,
65+
baseFee = 0,
66+
schedule = berlin -- specifically this, what is it suppsoed to be?
67+
}
68+
emptyTransaction :: TxState
69+
emptyTransaction =
70+
TxState
71+
{ gasprice = 0,
72+
gaslimit = 0,
73+
priorityFee = 0,
74+
origin = 0,
75+
toAddr = 0,
76+
value = Lit 0,
77+
substate = emptySubState,
78+
isCreate = True,
79+
txReversion = mempty
80+
}
81+
emptySubState :: SubState
82+
emptySubState =
83+
SubState
84+
{ selfdestructs = [],
85+
touchedAccounts = [],
86+
accessedAddresses = mempty,
87+
accessedStorageKeys = mempty,
88+
refunds = []
89+
}
8090

81-
envForContracts :: [(Addr, ByteString)] -> Env
82-
envForContracts contracts = Env
83-
{ contracts = Map.fromList (fmap (fmap bytecodeToContract) contracts)
84-
, chainId = 0
85-
, storage = EmptyStore
86-
, origStorage = mempty
87-
, sha3Crack = mempty
88-
}
91+
envForContracts :: [(Addr, ByteString)] -> Env
92+
envForContracts contracts =
93+
Env
94+
{ contracts = Map.fromList (fmap (fmap bytecodeToContract) contracts),
95+
chainId = 0,
96+
storage = EmptyStore,
97+
origStorage = mempty,
98+
sha3Crack = mempty
99+
}
89100

90-
bytecodeToContract :: ByteString -> Contract
91-
bytecodeToContract = initialContract . RuntimeCode . ConcreteRuntimeCode
101+
bytecodeToContract :: ByteString -> Contract
102+
bytecodeToContract = initialContract . RuntimeCode . ConcreteRuntimeCode
92103

93104
-- setup a new VM state from the list of contracts we are using
94105
loadIntoVM :: [(Addr, ByteString)] -> State VM ()
95-
loadIntoVM contracts =
96-
put (emptyVM contracts)
106+
loadIntoVM contracts = put (emptyVM contracts)
97107

98108
-- import a list of contracts as an open game
99109
-- - first we read off all the files and translate them into solidity bytecode
100110
-- - Then we associate each contract to a contract name which
101111
loadEVM :: [(Text, Text)] -> IO (State VM ())
102112
loadEVM contracts = do
103113
files :: [(Text, Text)] <- traverse (\(name, filename) -> (name,) <$> readFile (unpack filename)) (contracts)
104-
contracts :: [ByteString] <- traverse (\(nm, body) -> do
105-
Just bytecode <- solcRuntime nm body
106-
pure bytecode) files
107-
let bytecodeMap :: [(Addr, ByteString)] = zip [0 .. ] contracts
114+
contracts :: [ByteString] <-
115+
traverse
116+
( \(nm, body) -> do
117+
Just bytecode <- solcRuntime nm body
118+
pure bytecode
119+
)
120+
files
121+
let bytecodeMap :: [(Addr, ByteString)] = zip [0 ..] contracts
108122
let newVM = loadIntoVM bytecodeMap
109123
pure newVM
110124

111-
loadContracts :: [(Text,Text)] -> Q [Dec]
112-
loadContracts arg = [d|vmState :: State VM (); vmState = $([e|unsafePerformIO $ loadEVM arg|])|]
125+
loadContracts :: [(Text, Text)] -> State VM ()
126+
loadContracts arg = unsafePerformIO $ loadEVM arg
127+
128+
compileTimeLoad :: [(Text, Text)] -> Q [Dec]
129+
compileTimeLoad = undefined

act/Examples/EVM.hs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1-
{-# LANGUAGE TemplateHaskell #-}
21
{-# LANGUAGE OverloadedStrings #-}
2+
33
module Examples.EVM where
44

55
import EVM.TH
6-
import Data.Text
7-
8-
$(loadContracts [ ("token1", "erc20.sol")
9-
, ("token2", "erc20.sol")
10-
, ("amm", "amm.sol")
11-
])
126

7+
-- todo:
8+
-- - Lending platform, look for aave. aave.sol ??
9+
-- - Implement state into the open game
10+
-- - Obtain amm.sol and erc20.sol
11+
-- - test arbitrage strategy
12+
blockchainState =
13+
loadContracts
14+
[ ("token1", "ERC20.sol"),
15+
("token2", "ERC20.sol"),
16+
("amm", "AMM.sol")
17+
]

open-games-hs.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ executable act-exec
108108
Paths_open_games_hs
109109
hs-source-dirs:
110110
act
111-
ghc-options: -fwarn-unused-imports
111+
ghc-options: -fwarn-unused-imports -Wno-partial-type-signatures
112112
build-depends:
113113
QuickCheck
114114
, act

package.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ executables:
8989
source-dirs: act
9090
ghc-options:
9191
- -fwarn-unused-imports
92+
- -Wno-partial-type-signatures
9293
dependencies:
9394
- act
9495
- data-dword

0 commit comments

Comments
 (0)