Skip to content

Commit ee906ef

Browse files
authored
Merge pull request #609 from ethereum/fix_prank
Fixing prank: no longer override the sender on lower frames
2 parents 0a21109 + 6d61bb6 commit ee906ef

File tree

4 files changed

+28
-30
lines changed

4 files changed

+28
-30
lines changed

Diff for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6363
- Respect --smt-timeout in equivalence checking
6464
- Fixed the handling of returndata with an abstract size during transaction finalization
6565
- Error handling for user-facing cli commands is much improved
66+
- Fixing prank so it doesn't override the sender address on lower call frames
6667

6768
## [0.53.0] - 2024-02-23
6869

Diff for: src/EVM.hs

+24-27
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ blankState = do
8383
, gas = initialGas
8484
, returndata = mempty
8585
, static = False
86+
, overrideCaller = Nothing
87+
, resetCaller = False
8688
}
8789

8890
-- | An "external" view of a contract's bytecode, appropriate for
@@ -145,6 +147,8 @@ makeVm o = do
145147
, gas = o.gas
146148
, returndata = mempty
147149
, static = False
150+
, overrideCaller = Nothing
151+
, resetCaller = False
148152
}
149153
, env = env
150154
, cache = cache
@@ -153,8 +157,6 @@ makeVm o = do
153157
, iterations = mempty
154158
, config = RuntimeConfig
155159
{ allowFFI = o.allowFFI
156-
, resetCaller = True
157-
, overrideCaller = Nothing
158160
, baseState = o.baseState
159161
}
160162
, forks = Seq.singleton (ForkState env block cache "")
@@ -866,17 +868,15 @@ exec1 = do
866868
forceAddr xTo' "unable to determine a call target" $ \xTo ->
867869
case gasTryFrom xGas of
868870
Left _ -> vmError IllegalOverflow
869-
Right gas ->
871+
Right gas -> do
872+
overrideC <- use $ #state % #overrideCaller
870873
delegateCall this gas xTo xTo xValue xInOffset xInSize xOutOffset xOutSize xs $
871874
\callee -> do
872-
let from' = fromMaybe self vm.config.overrideCaller
875+
let from' = fromMaybe self overrideC
873876
zoom #state $ do
874877
assign #callvalue xValue
875878
assign #caller from'
876879
assign #contract callee
877-
do
878-
resetCaller <- use (#config % #resetCaller)
879-
when (resetCaller) $ assign (#config % #overrideCaller) Nothing
880880
touchAccount from'
881881
touchAccount callee
882882
transfer from' callee xValue
@@ -889,14 +889,12 @@ exec1 = do
889889
forceAddr xTo' "unable to determine a call target" $ \xTo ->
890890
case gasTryFrom xGas of
891891
Left _ -> vmError IllegalOverflow
892-
Right gas ->
892+
Right gas -> do
893+
overrideC <- use $ #state % #overrideCaller
893894
delegateCall this gas xTo self xValue xInOffset xInSize xOutOffset xOutSize xs $ \_ -> do
894895
zoom #state $ do
895896
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
900898
touchAccount self
901899
_ ->
902900
underrun
@@ -978,17 +976,15 @@ exec1 = do
978976
Just xTo' ->
979977
case gasTryFrom xGas of
980978
Left _ -> vmError IllegalOverflow
981-
Right gas ->
979+
Right gas -> do
980+
overrideC <- use $ #state % #overrideCaller
982981
delegateCall this gas xTo' xTo' (Lit 0) xInOffset xInSize xOutOffset xOutSize xs $
983982
\callee -> do
984983
zoom #state $ do
985984
assign #callvalue (Lit 0)
986-
assign #caller $ fromMaybe self (vm.config.overrideCaller)
985+
assign #caller $ fromMaybe self overrideC
987986
assign #contract callee
988987
assign #static True
989-
do
990-
resetCaller <- use (#config % #resetCaller)
991-
when (resetCaller) $ assign (#config % #overrideCaller) Nothing
992988
touchAccount self
993989
touchAccount callee
994990
_ ->
@@ -1101,7 +1097,7 @@ callChecks this xGas xContext xTo xValue xInOffset xInSize xOutOffset xOutSize x
11011097
accessMemoryRange xOutOffset xOutSize $ do
11021098
availableGas <- use (#state % #gas)
11031099
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
11051101
fromBal <- preuse $ #env % #contracts % ix from % #balance
11061102
costOfCall fees recipientExists xValue availableGas xGas xTo $ \cost gas' -> do
11071103
let checkCallDepth =
@@ -1145,9 +1141,6 @@ callChecks this xGas xContext xTo xValue xInOffset xInSize xOutOffset xOutSize x
11451141
partial $ UnexpectedSymbolicArg pc (getOpName state) "Attempting to transfer eth from a symbolic address that is not present in the state" (wrap [from])
11461142
GVar _ -> internalError "Unexpected GVar"
11471143

1148-
1149-
1150-
11511144
precompiledContract
11521145
:: (?op :: Word8, VMOps t)
11531146
=> Contract
@@ -1799,26 +1792,27 @@ cheatActions = Map.fromList
17991792
\sig input -> case decodeStaticArgs 0 1 input of
18001793
[addr] -> case wordToAddr addr of
18011794
Just a -> do
1802-
assign (#config % #overrideCaller) (Just a)
18031795
doStop
1796+
assign (#state % #overrideCaller) (Just a)
1797+
assign (#state % #resetCaller) True
18041798
Nothing -> vmError (BadCheatCode "prank(address), could not decode address provided" sig)
18051799
_ -> vmError (BadCheatCode "prank(address) parameter decoding failed" sig)
18061800

18071801
, action "startPrank(address)" $
18081802
\sig input -> case decodeStaticArgs 0 1 input of
18091803
[addr] -> case wordToAddr addr of
18101804
Just a -> do
1811-
assign (#config % #overrideCaller) (Just a)
1812-
assign (#config % #resetCaller) False
18131805
doStop
1806+
assign (#state % #overrideCaller) (Just a)
1807+
assign (#state % #resetCaller) False
18141808
Nothing -> vmError (BadCheatCode "startPrank(address), could not decode address provided" sig)
18151809
_ -> vmError (BadCheatCode "startPrank(address) parameter decoding failed" sig)
18161810

18171811
, action "stopPrank()" $
18181812
\_ _ -> do
1819-
assign (#config % #overrideCaller) Nothing
1820-
assign (#config % #resetCaller) True
18211813
doStop
1814+
assign (#state % #overrideCaller) Nothing
1815+
assign (#state % #resetCaller) False
18221816

18231817
, action "createFork(string)" $
18241818
\sig input -> case decodeBuf [AbiStringType] input of
@@ -1969,6 +1963,8 @@ delegateCall this gasGiven xTo xContext xValue xInOffset xInSize xOutOffset xOut
19691963
| otherwise =
19701964
callChecks this gasGiven xContext xTo xValue xInOffset xInSize xOutOffset xOutSize xs $
19711965
\xGas -> do
1966+
resetCaller <- use $ #state % #resetCaller
1967+
when resetCaller $ assign (#state % #overrideCaller) Nothing
19721968
vm0 <- get
19731969
fetchAccount xTo $ \target -> case target.code of
19741970
UnknownCode _ -> do
@@ -1993,7 +1989,6 @@ delegateCall this gasGiven xTo xContext xValue xInOffset xInSize xOutOffset xOut
19931989
pushTrace (FrameTrace newContext)
19941990
next
19951991
vm1 <- get
1996-
19971992
pushTo #frames $ Frame
19981993
{ state = vm1.state { stack = xs }
19991994
, context = newContext
@@ -2014,6 +2009,8 @@ delegateCall this gasGiven xTo xContext xValue xInOffset xInSize xOutOffset xOut
20142009
assign #memorySize 0
20152010
assign #returndata mempty
20162011
assign #calldata calldata
2012+
assign #overrideCaller Nothing
2013+
assign #resetCaller False
20172014
continue xTo
20182015

20192016
-- -- * Contract creation

Diff for: src/EVM/Types.hs

+2-2
Original file line numberDiff line numberDiff line change
@@ -665,8 +665,6 @@ data BaseState
665665
-- | Configuration options that need to be consulted at runtime
666666
data RuntimeConfig = RuntimeConfig
667667
{ allowFFI :: Bool
668-
, overrideCaller :: Maybe (Expr EAddr)
669-
, resetCaller :: Bool
670668
, baseState :: BaseState
671669
}
672670
deriving (Show)
@@ -728,6 +726,8 @@ data FrameState (t :: VMType) s = FrameState
728726
, gas :: !(Gas t)
729727
, returndata :: Expr Buf
730728
, static :: Bool
729+
, overrideCaller :: Maybe (Expr EAddr)
730+
, resetCaller :: Bool
731731
}
732732
deriving (Generic)
733733

Diff for: test/test.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1231,7 +1231,7 @@ tests = testGroup "hevm"
12311231
Right e <- reachableUserAsserts c (Just $ Sig "f(address,uint256)" [AbiAddressType, AbiUIntType 256])
12321232
assertBoolM "The expression is not partial" $ Expr.containsNode isPartial e
12331233
,
1234-
test "vm.prank underflow" $ do
1234+
test "vm.prank-underflow" $ do
12351235
Just c <- solcRuntime "C"
12361236
[i|
12371237
interface Vm {

0 commit comments

Comments
 (0)