Skip to content

Commit

Permalink
hevm: EVM: reject JUMPSUB into pushdata
Browse files Browse the repository at this point in the history
  • Loading branch information
d-xo committed Jun 16, 2020
1 parent 424ccaa commit b9b238a
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions src/hevm/src/EVM.hs
Original file line number Diff line number Diff line change
Expand Up @@ -924,14 +924,17 @@ exec1 = do
(x:xs) ->
burn g_high $ do
theCode <- use (state . code)
theCodeOps <- use (env . contracts . ix self . codeOps)
theReturnStack <- use (state . return_stack)
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 %= (thePc + 1 :)
state . pc .= num (x + 1)
else vmError StackLimitExceeded
if x < num (BS.length theCode) then
case findOpAt x OpBeginsub theCodeOps of
Nothing -> vmError BadJumpDestination
_ -> if length theReturnStack < 1023 then do
state . stack .= xs
state . return_stack %= (thePc + 1 :)
state . pc .= num (x + 1)
else vmError StackLimitExceeded
else vmError BadJumpDestination
_ -> underrun

Expand Down Expand Up @@ -2136,14 +2139,16 @@ checkJump x xs = do
theCode <- use (state . code)
self <- use (state . codeContract)
theCodeOps <- use (env . contracts . ix self . codeOps)
if x < num (BS.length theCode) && BS.index theCode (num x) == 0x5b
then
case RegularVector.find (\(i, op) -> i == num x && op == OpJumpdest) theCodeOps of
Nothing -> vmError BadJumpDestination
_ -> do
state . stack .= xs
state . pc .= num x
else vmError BadJumpDestination
if x < num (BS.length theCode) then
case findOpAt x OpJumpdest theCodeOps of
Nothing -> vmError BadJumpDestination
_ -> do
state . stack .= xs
state . pc .= num x
else vmError BadJumpDestination

findOpAt :: (Integral n) => n -> Op -> RegularVector.Vector (Int, Op) -> Maybe (Int, Op)
findOpAt x op ops = RegularVector.find (\(i, o) -> i == num x && o == op) ops

opSize :: Word8 -> Int
opSize x | x >= 0x60 && x <= 0x7f = num x - 0x60 + 2
Expand Down

0 comments on commit b9b238a

Please sign in to comment.