Skip to content

Commit 44feade

Browse files
committed
Add more complext layout and fix bugs
1 parent b79ad8d commit 44feade

File tree

3 files changed

+81
-8
lines changed

3 files changed

+81
-8
lines changed

src/Act/HEVM.hs

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
285297
createContract :: Monad m => ContractMap -> ContractMap -> EVM.Expr EVM.EAddr -> Exp AInteger -> ActT m ContractMap
286298
createContract 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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
constructor of A
2+
interface constructor()
3+
4+
iff
5+
6+
CALLVALUE == 0
7+
8+
creates
9+
10+
uint128 x := 11
11+
bool flag := true
12+
uint32 u := 17
13+
uint8 z := 3
14+
uint128 y := 42
15+
uint256 i := 128
16+
17+
behaviour foo of A
18+
interface foo()
19+
20+
iff
21+
22+
CALLVALUE == 0
23+
24+
storage
25+
26+
x => y
27+
y => x
28+
z => 11
29+
flag => not flag
30+
31+
returns 1
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
contract A {
2+
uint128 x;
3+
bool flag;
4+
uint32 u;
5+
uint8 z;
6+
uint128 y;
7+
uint256 i;
8+
9+
constructor() {
10+
x = 11;
11+
flag = true;
12+
u = 17;
13+
z = 3;
14+
y = 42;
15+
i = 128;
16+
}
17+
18+
function foo() external returns (uint) {
19+
20+
uint128 tmp = x;
21+
22+
x = y;
23+
y = tmp;
24+
z = 11;
25+
flag = !flag;
26+
27+
return 1;
28+
}
29+
}

0 commit comments

Comments
 (0)