Skip to content

Commit

Permalink
hevm: implement RETURNSUB
Browse files Browse the repository at this point in the history
  • Loading branch information
d-xo committed Jun 15, 2020
1 parent 0c249b3 commit f53f066
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/hevm/src/EVM.hs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ data FrameState = FrameState
, _code :: ByteString
, _pc :: Int
, _stack :: [Word]
, _return_stack :: [Word]
, _return_stack :: [Int]
, _memory :: ByteString
, _memorySize :: Int
, _calldata :: ByteString
Expand Down Expand Up @@ -914,7 +914,11 @@ exec1 = do
0x5c -> vmError InvalidSubroutineEntry

-- op: RETURNSUB
0x5d -> burn g_low next
0x5d -> case the state return_stack of
(x:xs) -> burn g_low $ do
state . pc .= x
state . return_stack .= xs
_ -> underrun

-- op: JUMPSUB
0x5e ->
Expand All @@ -923,10 +927,11 @@ exec1 = do
burn g_high $ do
theCode <- use (state . code)
theReturnStack <- use (state . return_stack)
if BS.index theCode (num x) == 0x5c
thePc <- use (state . pc)
if x < num (BS.length theCode) && BS.index theCode (num x) == 0x5c
then if length theReturnStack < 1023 then do
state . stack .= xs
state . return_stack %= (x :)
state . return_stack %= (thePc + 1 :)
state . pc .= num (x + 1)
else vmError StackLimitExceeded
else vmError BadJumpDestination
Expand Down

0 comments on commit f53f066

Please sign in to comment.