Skip to content

Commit cb523e4

Browse files
committed
fix rebase fuckups
1 parent a101fc8 commit cb523e4

File tree

2 files changed

+13
-28
lines changed

2 files changed

+13
-28
lines changed

src/hevm/src/EVM/Symbolic.hs

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ sgt (S _ x) (S _ y) =
101101

102102
shiftRight' :: SymWord -> SymWord -> SymWord
103103
shiftRight' a@(S _ a') b@(S _ b') = case (num <$> unliteral a', b) of
104-
(Just n, (S (FromBytes (SymbolicBuffer a)) i)) | n `mod` 8 == 0 && n <= 256 ->
104+
(Just n, (S (FromBytes (StaticSymBuffer a)) i)) | n `mod` 8 == 0 && n <= 256 ->
105105
let bs = replicate (n `div` 8) 0 <> (take ((256 - n) `div` 8) a)
106-
in S (FromBytes (SymbolicBuffer bs)) (fromBytes bs)
106+
in S (FromBytes (StaticSymBuffer bs)) (fromBytes bs)
107107
_ -> sw256 $ sShiftRight b' a'
108108

109109
-- | Operations over static symbolic memory (list of symbolic bytes)
@@ -154,7 +154,8 @@ truncpad' n m = case m of
154154
Nothing -> StaticSymBuffer $ takeStatic n (xs .++ literal (replicate n 0))
155155

156156
swordAt :: Int -> [SWord 8] -> SymWord
157-
swordAt i bs = sw256 . fromBytes $ truncpad 32 $ drop i bs
157+
swordAt i bs = let b = truncpad 32 $ drop i bs
158+
in S (FromBytes (StaticSymBuffer b)) (fromBytes b)
158159

159160
swordAt' :: SymWord -> SList (WordN 8) -> SymWord
160161
swordAt' i@(S _ i') bs =
@@ -213,29 +214,6 @@ readByteOrZero'' i bs =
213214
(bs .!! (sFromIntegral i))
214215
(literal 0)
215216

216-
-- Generates a ridiculously large set of constraints (roughly 25k) when
217-
-- the index is symbolic, but it still seems (kind of) manageable
218-
-- for the solvers.
219-
readSWordWithBound :: SWord 32 -> Buffer -> SWord 32 -> SymWord
220-
readSWordWithBound ind (SymbolicBuffer xs) bound = case (num <$> fromSized <$> unliteral ind, num <$> fromSized <$> unliteral bound) of
221-
(Just i, Just b) ->
222-
let bs = truncpad 32 $ drop i (take b xs)
223-
in S (FromBytes (SymbolicBuffer bs)) (fromBytes bs)
224-
_ ->
225-
let boundedList = [ite (i .<= bound) x 0 | (x, i) <- zip xs [1..]]
226-
in sw256 . fromBytes $ [select' boundedList 0 (ind + j) | j <- [0..31]]
227-
228-
readSWordWithBound ind (ConcreteBuffer xs) bound =
229-
case fromSized <$> unliteral ind of
230-
Nothing -> readSWordWithBound ind (SymbolicBuffer (litBytes xs)) bound
231-
Just x' ->
232-
-- INVARIANT: bound should always be length xs for concrete bytes
233-
-- so we should be able to safely ignore it here
234-
litWord $ Concrete.readMemoryWord (num x') xs
235-
236-
readMemoryWord' :: Word -> [SWord 8] -> SymWord
237-
readMemoryWord' (C _ i) m = sw256 $ fromBytes $ truncpad 32 (drop (num i) m)
238-
239217
-- pad up to 1000 bytes
240218
sslice :: SymWord -> SymWord -> SList (WordN 8) -> SList (WordN 8)
241219
sslice (S _ o) (S _ l) bs = case (unliteral $ SL.length bs, unliteral (o + l)) of
@@ -405,8 +383,13 @@ select' xs err ind = walk xs ind err
405383
-- for the solvers.
406384
readStaticWordWithBound :: SWord 32 -> ([SWord 8], SWord 32) -> SymWord
407385
readStaticWordWithBound ind (xs, bound) =
408-
let boundedList = [ite (i .<= bound) x 0 | (x, i) <- zip xs [1..]]
409-
in sw256 . fromBytes $ [select' boundedList 0 (ind + j) | j <- [0..31]]
386+
case (num <$> fromSized <$> unliteral ind, num <$> fromSized <$> unliteral bound) of
387+
(Just i, Just b) ->
388+
let bs = truncpad 32 $ drop i (take b xs)
389+
in S (FromBytes (StaticSymBuffer bs)) (fromBytes bs)
390+
_ ->
391+
let boundedList = [ite (i .<= bound) x 0 | (x, i) <- zip xs [1..]]
392+
in sw256 $ fromBytes [select' boundedList 0 (ind + j) | j <- [0..31]]
410393

411394
-- | Custom instances for SymWord, many of which have direct
412395
-- analogues for concrete words defined in Concrete.hs

src/hevm/src/EVM/Types.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import Data.Aeson (FromJSONKey (..), FromJSONKeyFunction (..))
1414
#endif
1515

1616
import Data.SBV
17+
import Data.SBV.List ((.++))
18+
import qualified Data.SBV.List as SL
1719
import Data.Kind
1820
import Data.Monoid ((<>))
1921
import Data.Bifunctor (first)

0 commit comments

Comments
 (0)