@@ -83,6 +83,8 @@ blankState = do
83
83
, gas = initialGas
84
84
, returndata = mempty
85
85
, static = False
86
+ , overrideCaller = Nothing
87
+ , resetCaller = False
86
88
}
87
89
88
90
-- | An "external" view of a contract's bytecode, appropriate for
@@ -145,6 +147,8 @@ makeVm o = do
145
147
, gas = o. gas
146
148
, returndata = mempty
147
149
, static = False
150
+ , overrideCaller = Nothing
151
+ , resetCaller = False
148
152
}
149
153
, env = env
150
154
, cache = cache
@@ -153,8 +157,6 @@ makeVm o = do
153
157
, iterations = mempty
154
158
, config = RuntimeConfig
155
159
{ allowFFI = o. allowFFI
156
- , resetCaller = True
157
- , overrideCaller = Nothing
158
160
, baseState = o. baseState
159
161
}
160
162
, forks = Seq. singleton (ForkState env block cache " " )
@@ -866,17 +868,15 @@ exec1 = do
866
868
forceAddr xTo' " unable to determine a call target" $ \ xTo ->
867
869
case gasTryFrom xGas of
868
870
Left _ -> vmError IllegalOverflow
869
- Right gas ->
871
+ Right gas -> do
872
+ overrideC <- use $ # state % # overrideCaller
870
873
delegateCall this gas xTo xTo xValue xInOffset xInSize xOutOffset xOutSize xs $
871
874
\ callee -> do
872
- let from' = fromMaybe self vm . config . overrideCaller
875
+ let from' = fromMaybe self overrideC
873
876
zoom # state $ do
874
877
assign # callvalue xValue
875
878
assign # caller from'
876
879
assign # contract callee
877
- do
878
- resetCaller <- use (# config % # resetCaller)
879
- when (resetCaller) $ assign (# config % # overrideCaller) Nothing
880
880
touchAccount from'
881
881
touchAccount callee
882
882
transfer from' callee xValue
@@ -889,14 +889,12 @@ exec1 = do
889
889
forceAddr xTo' " unable to determine a call target" $ \ xTo ->
890
890
case gasTryFrom xGas of
891
891
Left _ -> vmError IllegalOverflow
892
- Right gas ->
892
+ Right gas -> do
893
+ overrideC <- use $ # state % # overrideCaller
893
894
delegateCall this gas xTo self xValue xInOffset xInSize xOutOffset xOutSize xs $ \ _ -> do
894
895
zoom # state $ do
895
896
assign # callvalue xValue
896
- assign # caller $ fromMaybe self vm. config. overrideCaller
897
- do
898
- resetCaller <- use (# config % # resetCaller)
899
- when (resetCaller) $ assign (# config % # overrideCaller) Nothing
897
+ assign # caller $ fromMaybe self overrideC
900
898
touchAccount self
901
899
_ ->
902
900
underrun
@@ -978,17 +976,15 @@ exec1 = do
978
976
Just xTo' ->
979
977
case gasTryFrom xGas of
980
978
Left _ -> vmError IllegalOverflow
981
- Right gas ->
979
+ Right gas -> do
980
+ overrideC <- use $ # state % # overrideCaller
982
981
delegateCall this gas xTo' xTo' (Lit 0 ) xInOffset xInSize xOutOffset xOutSize xs $
983
982
\ callee -> do
984
983
zoom # state $ do
985
984
assign # callvalue (Lit 0 )
986
- assign # caller $ fromMaybe self (vm . config . overrideCaller)
985
+ assign # caller $ fromMaybe self overrideC
987
986
assign # contract callee
988
987
assign # static True
989
- do
990
- resetCaller <- use (# config % # resetCaller)
991
- when (resetCaller) $ assign (# config % # overrideCaller) Nothing
992
988
touchAccount self
993
989
touchAccount callee
994
990
_ ->
@@ -1101,7 +1097,7 @@ callChecks this xGas xContext xTo xValue xInOffset xInSize xOutOffset xOutSize x
1101
1097
accessMemoryRange xOutOffset xOutSize $ do
1102
1098
availableGas <- use (# state % # gas)
1103
1099
let recipientExists = accountExists xContext vm
1104
- let from = fromMaybe vm. state. contract vm. config . overrideCaller
1100
+ let from = fromMaybe vm. state. contract vm. state . overrideCaller
1105
1101
fromBal <- preuse $ # env % # contracts % ix from % # balance
1106
1102
costOfCall fees recipientExists xValue availableGas xGas xTo $ \ cost gas' -> do
1107
1103
let checkCallDepth =
@@ -1145,9 +1141,6 @@ callChecks this xGas xContext xTo xValue xInOffset xInSize xOutOffset xOutSize x
1145
1141
partial $ UnexpectedSymbolicArg pc (getOpName state) " Attempting to transfer eth from a symbolic address that is not present in the state" (wrap [from])
1146
1142
GVar _ -> internalError " Unexpected GVar"
1147
1143
1148
-
1149
-
1150
-
1151
1144
precompiledContract
1152
1145
:: (? op :: Word8 , VMOps t )
1153
1146
=> Contract
@@ -1799,26 +1792,27 @@ cheatActions = Map.fromList
1799
1792
\ sig input -> case decodeStaticArgs 0 1 input of
1800
1793
[addr] -> case wordToAddr addr of
1801
1794
Just a -> do
1802
- assign (# config % # overrideCaller) (Just a)
1803
1795
doStop
1796
+ assign (# state % # overrideCaller) (Just a)
1797
+ assign (# state % # resetCaller) True
1804
1798
Nothing -> vmError (BadCheatCode " prank(address), could not decode address provided" sig)
1805
1799
_ -> vmError (BadCheatCode " prank(address) parameter decoding failed" sig)
1806
1800
1807
1801
, action " startPrank(address)" $
1808
1802
\ sig input -> case decodeStaticArgs 0 1 input of
1809
1803
[addr] -> case wordToAddr addr of
1810
1804
Just a -> do
1811
- assign (# config % # overrideCaller) (Just a)
1812
- assign (# config % # resetCaller) False
1813
1805
doStop
1806
+ assign (# state % # overrideCaller) (Just a)
1807
+ assign (# state % # resetCaller) False
1814
1808
Nothing -> vmError (BadCheatCode " startPrank(address), could not decode address provided" sig)
1815
1809
_ -> vmError (BadCheatCode " startPrank(address) parameter decoding failed" sig)
1816
1810
1817
1811
, action " stopPrank()" $
1818
1812
\ _ _ -> do
1819
- assign (# config % # overrideCaller) Nothing
1820
- assign (# config % # resetCaller) True
1821
1813
doStop
1814
+ assign (# state % # overrideCaller) Nothing
1815
+ assign (# state % # resetCaller) False
1822
1816
1823
1817
, action " createFork(string)" $
1824
1818
\ sig input -> case decodeBuf [AbiStringType ] input of
@@ -1969,6 +1963,8 @@ delegateCall this gasGiven xTo xContext xValue xInOffset xInSize xOutOffset xOut
1969
1963
| otherwise =
1970
1964
callChecks this gasGiven xContext xTo xValue xInOffset xInSize xOutOffset xOutSize xs $
1971
1965
\ xGas -> do
1966
+ resetCaller <- use $ # state % # resetCaller
1967
+ when resetCaller $ assign (# state % # overrideCaller) Nothing
1972
1968
vm0 <- get
1973
1969
fetchAccount xTo $ \ target -> case target. code of
1974
1970
UnknownCode _ -> do
@@ -1993,7 +1989,6 @@ delegateCall this gasGiven xTo xContext xValue xInOffset xInSize xOutOffset xOut
1993
1989
pushTrace (FrameTrace newContext)
1994
1990
next
1995
1991
vm1 <- get
1996
-
1997
1992
pushTo # frames $ Frame
1998
1993
{ state = vm1. state { stack = xs }
1999
1994
, context = newContext
@@ -2014,6 +2009,8 @@ delegateCall this gasGiven xTo xContext xValue xInOffset xInSize xOutOffset xOut
2014
2009
assign # memorySize 0
2015
2010
assign # returndata mempty
2016
2011
assign # calldata calldata
2012
+ assign # overrideCaller Nothing
2013
+ assign # resetCaller False
2017
2014
continue xTo
2018
2015
2019
2016
-- -- * Contract creation
0 commit comments