@@ -140,7 +140,7 @@ checkCases (Act _ contracts) solver' smttimeout debug = do
140140type ModelCtx = Reader Model
141141
142142mkBounds :: TypedExp -> Int -> [Exp ABoolean ]
143- mkBounds (TExp SInteger _ e) b = [LEQ nowhere (LitInt nowhere 0 ) e, LT nowhere e (LitInt nowhere $ toInteger b)]
143+ mkBounds (TExp ( TInteger _ _) e) b = [LEQ nowhere (LitInt nowhere 0 ) e, LT nowhere e (LitInt nowhere $ toInteger b)]
144144mkBounds _ _ = error " Internal Error: Expected Integral Index"
145145
146146mkRefBounds :: Ref a -> [Exp ABoolean ]
@@ -150,7 +150,7 @@ mkRefBounds (SField _ ref _ _) = mkRefBounds ref
150150mkRefBounds _ = []
151151
152152mkStorageBounds :: Location -> [Exp ABoolean ]
153- mkStorageBounds (Loc _ _ (Item _ _ ref)) = mkRefBounds ref
153+ mkStorageBounds (Loc _ _ (Item _ ref)) = mkRefBounds ref
154154
155155-- TODO: There are locs that don't need to be checked, e.g. assignment locs cannot be out of bounds
156156mkConstrArrayBoundsQuery :: Constructor -> (Id , [Location ], SMTExp , SolverInstance -> IO Model )
@@ -224,7 +224,7 @@ checkArrayBounds (Act _ contracts) solver' smttimeout debug =
224224 errorMsg str = render (pretty str <> line) >> exitFailure
225225
226226checkBound :: TypedExp -> Int -> ModelCtx Bool
227- checkBound (TExp SInteger _ e) b =
227+ checkBound (TExp ( TInteger _ _) e) b =
228228 [ (0 <= toInteger idx) && (toInteger idx < toInteger b) | idx <- modelEval e ]
229229checkBound _ _ = error " Internal Error: Expected Integer indices"
230230
@@ -235,7 +235,7 @@ checkRefBounds (SField _ ref _ _) = checkRefBounds ref
235235checkRefBounds _ = pure True
236236
237237checkLocationBounds :: Location -> ModelCtx DocAnsi
238- checkLocationBounds (Loc _ _ item@ (Item _ _ ref)) = do
238+ checkLocationBounds (Loc _ _ item@ (Item _ ref)) = do
239239 cond <- checkRefBounds ref
240240 if cond then pure $ string " "
241241 else do
@@ -245,7 +245,7 @@ checkLocationBounds (Loc _ _ item@(Item _ _ ref)) = do
245245 (AlexPn _ l c) = posnFromRef ref
246246
247247printIdx :: TypedExp -> Int -> ModelCtx DocAnsi
248- printIdx te@ (TExp SInteger _ e) b = do
248+ printIdx te@ (TExp ( TInteger _ _) e) b = do
249249 idx <- modelEval e
250250 if (toInteger idx < toInteger b) && (0 <= toInteger idx)
251251 then pure $ string " [" <> string (prettyTypedExp te) <> string " ]"
@@ -271,7 +271,7 @@ printOutOfBoundsRef (SVar _ _ id') = pure $ string id'
271271printOutOfBoundsRef (CVar _ _ id') = pure $ string id'
272272
273273printOutOfBoundsItem :: TItem a k -> ModelCtx DocAnsi
274- printOutOfBoundsItem (Item _ _ ref) = printOutOfBoundsRef ref
274+ printOutOfBoundsItem (Item _ ref) = printOutOfBoundsRef ref
275275
276276
277277--- ** No rewrite aliasing ** ---
@@ -356,16 +356,16 @@ checkAliasing (l1, l2) = do
356356 ixs2 = ixsFromLocation l2
357357
358358compareIdx :: TypedExp -> TypedExp -> ModelCtx Bool
359- compareIdx (TExp SInteger Atomic e1) (TExp SInteger Atomic e2) =
359+ compareIdx (TExp ( TInteger _ _) e1) (TExp ( TInteger _ _) e2) =
360360 [ a == b | a <- modelEval e1, b <- modelEval e2 ]
361- compareIdx (TExp SBoolean Atomic e1) (TExp SBoolean Atomic e2) =
361+ compareIdx (TExp TBoolean e1) (TExp TBoolean e2) =
362362 [ a == b | a <- modelEval e1, b <- modelEval e2 ]
363- compareIdx (TExp SByteStr Atomic e1) (TExp SByteStr Atomic e2) =
363+ compareIdx (TExp TByteStr e1) (TExp TByteStr e2) =
364364 [ a == b | a <- modelEval e1, b <- modelEval e2 ]
365365compareIdx _ _ = pure False
366366
367367printAliased :: TypedExp -> ModelCtx DocAnsi
368- printAliased te@ (TExp SInteger _ e) = do
368+ printAliased te@ (TExp ( TInteger _ _) e) = do
369369 e' <- modelEval e
370370 pure $ string " [(" <> string (prettyTypedExp te) <> string " ) = " <> string (show e') <> string " ]"
371371printAliased _ = error " Internal Error: Expected Integer indices"
@@ -381,29 +381,31 @@ printAliasedRef (SVar _ _ id') = pure $ string id'
381381printAliasedRef (CVar _ _ id') = pure $ string id'
382382
383383printAliasedLoc :: Location -> ModelCtx DocAnsi
384- printAliasedLoc (Loc _ _ (Item _ _ ref)) = do
384+ printAliasedLoc (Loc _ _ (Item _ ref)) = do
385385 r <- printAliasedRef ref
386386 pure $ string " Line " <> string (show l) <> string " Column " <> string (show c) <> string " : " <> r
387387 where
388388 (AlexPn _ l c ) = posnFromRef ref
389389
390- modelExpand :: SType (AArray a ) -> Exp (AArray a ) -> ModelCtx [Exp (Base (AArray a ))]
391- modelExpand (SSArray SInteger ) (Array _ l) = pure l
392- modelExpand (SSArray SBoolean ) (Array _ l) = pure l
393- modelExpand (SSArray SByteStr ) (Array _ l) = pure l
394- modelExpand (SSArray SContract ) (Array _ l) = pure l
395- modelExpand (SSArray s@ (SSArray _)) (Array _ l) = concat <$> mapM (modelExpand s) l
390+ modelExpand :: TValueType (AArray a ) -> Exp (AArray a ) -> ModelCtx [Exp (Base (AArray a ))]
391+ modelExpand (TArray _ (TInteger _ _)) (Array _ l) = pure l
392+ modelExpand (TArray _ TAddress ) (Array _ l) = pure l
393+ modelExpand (TArray _ TBoolean ) (Array _ l) = pure l
394+ modelExpand (TArray _ TByteStr ) (Array _ l) = pure l
395+ modelExpand (TArray _ (TContract _)) (Array _ l) = pure l
396+ modelExpand (TArray _ (TStruct _)) (Array _ l) = pure l
397+ modelExpand (TArray _ t@ (TArray _ _)) (Array _ l) = concat <$> mapM (modelExpand t) l
396398modelExpand typ (VarRef _ whn SStorage item) = do
397399 model <- ask
398400 case lookup (_Loc SStorage item) $ if whn == Pre then _mprestate model else _mpoststate model of
399- Just (TExp sType _ e') -> case testEquality typ sType of
401+ Just (TExp sType e') -> case testEquality typ sType of
400402 Just Refl -> pure $ expandArrayExpr sType e'
401403 _ -> error " modelEval: Storage Location given does not match type"
402404 _ -> error $ " modelEval: Storage Location not found in model" <> show item
403405modelExpand typ (VarRef _ _ SCalldata item) = do
404406 model <- ask
405407 case lookup (_Loc SCalldata item) $ _mcalllocs model of
406- Just (TExp sType _ e') -> case testEquality typ sType of
408+ Just (TExp sType e') -> case testEquality typ sType of
407409 Just Refl -> pure $ expandArrayExpr sType e'
408410 _ -> error " modelEval: Storage Location given does not match type"
409411 _ -> error $ " modelEval: Storage Location not found in model" <> show item
@@ -436,23 +438,30 @@ modelEval e = case e of
436438 UIntMin _ a -> pure $ uintmin a
437439 UIntMax _ a -> pure $ uintmax a
438440
439- Eq _ SInteger x y -> [ x' == y' | x' <- modelEval x, y' <- modelEval y]
440- Eq _ SBoolean x y -> [ x' == y' | x' <- modelEval x, y' <- modelEval y]
441- Eq _ SByteStr x y -> [ x' == y' | x' <- modelEval x, y' <- modelEval y]
442- Eq p s@ (SSArray _) a b -> do
441+ Eq _ (TInteger _ _) x y -> [ x' == y' | x' <- modelEval x, y' <- modelEval y]
442+ Eq _ TAddress x y -> [ x' == y' | x' <- modelEval x, y' <- modelEval y]
443+ Eq _ TBoolean x y -> [ x' == y' | x' <- modelEval x, y' <- modelEval y]
444+ Eq _ TByteStr x y -> [ x' == y' | x' <- modelEval x, y' <- modelEval y]
445+ Eq _ (TStruct _) _ _ -> error " modelEval: TODO: Structs"
446+ Eq _ (TContract _) _ _ -> error " modelEval: TODO: Structs"
447+ Eq p s@ (TArray _ _) a b -> do
443448 a' <- modelExpand s a
444449 b' <- modelExpand s b
445- let s' = flattenSType s
450+ let s' = fst $ flattenValueType s
446451 eqs = (uncurry $ Eq p s') <$> zip a' b'
447452 expanded = foldr (And nowhere) (LitBool nowhere True ) eqs
448453 modelEval expanded
449- NEq _ SInteger x y -> [ x' /= y' | x' <- modelEval x, y' <- modelEval y]
450- NEq _ SBoolean x y -> [ x' /= y' | x' <- modelEval x, y' <- modelEval y]
451- NEq _ SByteStr x y -> [ x' /= y' | x' <- modelEval x, y' <- modelEval y]
452- NEq p s@ (SSArray _) a b -> do
454+
455+ NEq _ (TInteger _ _) x y -> [ x' /= y' | x' <- modelEval x, y' <- modelEval y]
456+ NEq _ TAddress x y -> [ x' /= y' | x' <- modelEval x, y' <- modelEval y]
457+ NEq _ TBoolean x y -> [ x' /= y' | x' <- modelEval x, y' <- modelEval y]
458+ NEq _ TByteStr x y -> [ x' /= y' | x' <- modelEval x, y' <- modelEval y]
459+ NEq _ (TStruct _) _ _ -> error " modelEval: TODO: Structs"
460+ NEq _ (TContract _) _ _ -> error " modelEval: TODO: Structs"
461+ NEq p s@ (TArray _ _) a b -> do
453462 a' <- modelExpand s a
454463 b' <- modelExpand s b
455- let s' = flattenSType s
464+ let s' = fst $ flattenValueType s
456465 eqs = (uncurry $ NEq p s') <$> zip a' b'
457466 expanded = foldr (Or nowhere) (LitBool nowhere False ) eqs
458467 modelEval expanded
@@ -463,10 +472,10 @@ modelEval e = case e of
463472 SSArray SType -> mapM modelEval l
464473
465474 Create _ _ _ -> error " modelEval of contracts not supported"
466- VarRef _ whn SStorage item -> do
475+ VarRef _ whn SStorage item@ ( Item vt _) -> do
467476 model <- ask
468477 case lookup (_Loc SStorage item) $ if whn == Pre then _mprestate model else _mpoststate model of
469- Just (TExp sType _ e') -> case testEquality (sing @ a ) sType of
478+ Just (TExp vType e') -> case testEquality vt vType of
470479 Just Refl -> case e' of
471480 (LitInt _ i) -> pure i
472481 (LitBool _ b) -> pure b
@@ -475,10 +484,10 @@ modelEval e = case e of
475484 _ -> error " modelEval: Model did not return a literal"
476485 _ -> error " modelEval: Storage Location given does not match type"
477486 _ -> error $ " modelEval: Storage Location not found in model" <> show item
478- VarRef _ _ SCalldata item -> do
487+ VarRef _ _ SCalldata item@ ( Item vt _) -> do
479488 model <- ask
480489 case lookup (_Loc SCalldata item) $ _mcalllocs model of
481- Just (TExp sType _ e') -> case testEquality (sing @ a ) sType of
490+ Just (TExp vType e') -> case testEquality vt vType of
482491 Just Refl -> case e' of
483492 (LitInt _ i) -> pure i
484493 (LitBool _ b) -> pure b
@@ -491,7 +500,7 @@ modelEval e = case e of
491500 IntEnv _ env -> do
492501 model <- ask
493502 case lookup env $ _menvironment model of
494- Just (TExp sType _ e') -> case testEquality (sing @ a ) sType of
503+ Just (TExp sType e') -> case testEquality (sing @ a ) (toSType sType) of
495504 Just Refl -> case e' of
496505 (LitInt _ i) -> pure i
497506 _ -> error " modelEval: Model did not return an Integer literal"
0 commit comments