@@ -248,26 +248,35 @@ applyUpdate readMap writeMap (Update typ (Item _ _ ref) e) = do
248248 (addr, offset, size) <- refOffset readMap ref
249249 let (contract, cid) = fromMaybe (error $ " Internal error: contract not found\n " <> show e) $ M. lookup caddr' writeMap
250250 case typ of
251- SInteger -> case e of
252- Create _ _ _ -> do
251+ SInteger | isCreate e -> do
253252 fresh <- getFreshIncr
254253 let freshAddr = EVM. SymAddr $ " freshSymAddr" <> (T. pack $ show fresh)
255254 writeMap' <- localCaddr freshAddr $ createContract readMap writeMap freshAddr e
256255 pure $ M. insert caddr' (updateNonce (updateStorage (EVM. SStore addr (EVM. WAddr freshAddr)) contract), cid) writeMap'
257- _ -> do
256+ SByteStr -> error " Bytestrings not supported"
257+ SInteger -> do
258258 e' <- toExpr readMap e
259259
260260 let negmask = ((2 ^ (8 * size) - 1 ) `shiftL` (offset * 8 )) `xor` MAX_UINT
261261
262262 let shift v = EVM. Mul v (EVM. Lit (2 ^ (8 * offset)))
263263 let prevValue = readStorage addr contract
264264 let e'' = simplify $ EVM. Or (shift e') (EVM. And prevValue (EVM. Lit negmask))
265-
265+ traceM " update "
266+ traceShowM e''
266267 pure $ M. insert caddr' (updateStorage (EVM. SStore addr e'') contract, cid) writeMap
267268 SBoolean -> do
268- e' <- toExpr readMap e
269- pure $ M. insert caddr' (updateStorage (EVM. SStore addr e') contract, cid) writeMap
270- SByteStr -> error " Bytestrings not supported"
269+ e' <- toExpr readMap e
270+
271+ let negmask = ((2 ^ (8 * size) - 1 ) `shiftL` (offset * 8 )) `xor` MAX_UINT
272+
273+ let shift v = EVM. Mul v (EVM. Lit (2 ^ (8 * offset)))
274+ let prevValue = readStorage addr contract
275+ let e'' = simplify $ EVM. Or (shift e') (EVM. And prevValue (EVM. Lit negmask))
276+ traceM " update "
277+ traceShowM e''
278+ pure $ M. insert caddr' (updateStorage (EVM. SStore addr e'') contract, cid) writeMap
279+
271280 where
272281 updateStorage :: (EVM. Expr EVM. Storage -> EVM. Expr EVM. Storage ) -> EVM. Expr EVM. EContract -> EVM. Expr EVM. EContract
273282 updateStorage updfun (EVM. C code storage tstorage bal nonce) = EVM. C code (updfun storage) tstorage bal nonce
@@ -282,6 +291,9 @@ applyUpdate readMap writeMap (Update typ (Item _ _ ref) e) = do
282291 updateNonce c@ (EVM. C _ _ _ _ Nothing ) = c
283292 updateNonce (EVM. GVar _) = error " Internal error: contract cannot be a global variable"
284293
294+ isCreate (Create _ _ _) = True
295+ isCreate _ = False
296+
285297createContract :: Monad m => ContractMap -> ContractMap -> EVM. Expr EVM. EAddr -> Exp AInteger -> ActT m ContractMap
286298createContract readMap writeMap freshAddr (Create _ cid args) = do
287299 codemap <- getCodemap
@@ -541,7 +553,7 @@ toExpr cmap = liftM stripMods . go
541553 (Impl _ e1 e2) -> op2 (EVM. Or . EVM. Not ) e1 e2
542554 (Neg _ e1) -> do
543555 e1' <- toExpr cmap e1
544- pure $ EVM. Not e1'
556+ pure $ EVM. IsZero e1' -- XXX why EVM.Not fails here?
545557 (Act. LT _ e1 e2) -> op2 EVM. LT e1 e2
546558 (LEQ _ e1 e2) -> op2 EVM. LEq e1 e2
547559 (GEQ _ e1 e2) -> op2 EVM. GEq e1 e2
@@ -587,6 +599,7 @@ toExpr cmap = liftM stripMods . go
587599 (NEq _ _ _ _) -> error " unsupported"
588600
589601 (TEntry _ _ _ (Item SInteger _ ref)) -> refToExp cmap ref
602+ (TEntry _ _ _ (Item SBoolean _ ref)) -> refToExp cmap ref
590603
591604 e@ (ITE _ _ _ _) -> error $ " Internal error: expecting flat expression. got: " <> show e
592605
0 commit comments