Skip to content

Commit

Permalink
fix bug in translation
Browse files Browse the repository at this point in the history
  • Loading branch information
zoep committed Jan 17, 2025
1 parent e3b2209 commit b79ad8d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/Act/HEVM.hs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ applyUpdate readMap writeMap (Update typ (Item _ _ ref) e) = do
fresh <- getFreshIncr
let freshAddr = EVM.SymAddr $ "freshSymAddr" <> (T.pack $ show fresh)
writeMap' <- localCaddr freshAddr $ createContract readMap writeMap freshAddr e
pure $ M.insert caddr' (updateNonce (updateStorage (EVM.SStore addr (EVM.WAddr freshAddr))contract), cid) writeMap'
pure $ M.insert caddr' (updateNonce (updateStorage (EVM.SStore addr (EVM.WAddr freshAddr)) contract), cid) writeMap'
_ -> do
e' <- toExpr readMap e

Expand Down Expand Up @@ -614,7 +614,7 @@ refToExp cmap r = do
(slot, offset, size) <- refOffset cmap r
let word = accessStorage cmap slot caddr
let mask = (2 ^ (8 * size) - 1) `shiftL` (offset * 8)
pure $ EVM.Div (EVM.And word (EVM.Lit mask)) (EVM.Lit (2 ^(8 * size)))
pure $ EVM.Div (EVM.And word (EVM.Lit mask)) (EVM.Lit (2 ^ (8 * offset)))

accessStorage :: ContractMap -> EVM.Expr EVM.EWord -> EVM.Expr EVM.EAddr -> EVM.Expr EVM.EWord
accessStorage cmap slot addr = case M.lookup addr cmap of
Expand Down
5 changes: 3 additions & 2 deletions tests/hevm/pass/layout1/layout1.act
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ iff

creates

uint128 x := 0
uint128 y := 0
uint128 x := 11
uint128 y := 42

behaviour swap of A
interface swap()
Expand All @@ -20,5 +20,6 @@ iff
storage

x => y
y => x

returns 1
8 changes: 5 additions & 3 deletions tests/hevm/pass/layout1/layout1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ contract A {
uint128 y;

constructor() {
x = 0;
y = 0;
x = 11;
y = 42;
}

function swap() external returns (uint) {

uint128 tmp = x;

x = y;
// y = x;
y = tmp;

return 1;
}
Expand Down

0 comments on commit b79ad8d

Please sign in to comment.