Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DRAFT] Preliminary dynamic ABI types #565

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/EVM/SymExec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ symAbiArg name = \case
Comp . V.toList . V.imap (\(T.pack . show -> i) tp -> symAbiArg (name <> "-a-" <> i) tp) $ (V.replicate sz tps)
AbiTupleType tps ->
Comp . V.toList . V.imap (\(T.pack . show -> i) tp -> symAbiArg (name <> "-t-" <> i) tp) $ tps
AbiBytesDynamicType -> do
let arr = (AbstractBuf ("db-" <> name))
sz = BufLength arr
Dy [PEq (Expr.eq (Lit 1) (Lit 1)) (Lit 0x1)] sz arr
t -> internalError $ "TODO: symbolic abi encoding for " <> show t
where
v = Var name
Expand Down Expand Up @@ -168,6 +172,7 @@ cdLen = go (Lit 4)
(hd:tl) -> case hd of
St _ _ -> go (Expr.add acc (Lit 32)) tl
Comp xs | all isSt xs -> go acc (xs <> tl)
Dy _ sz _ -> go (Expr.add acc sz) tl
_ -> internalError "unsupported"

writeSelector :: Expr Buf -> Text -> Expr Buf
Expand All @@ -186,9 +191,9 @@ combineFragments fragments base = go (Lit 4) fragments (base, [])
case f of
-- static fragments get written as a word in place
St p w -> go (Expr.add idx (Lit 32)) rest (Expr.writeWord idx w buf, p <> ps)
Dy p sz buf2 -> go (Expr.add idx sz) rest (Expr.copySlice (Lit 0) idx sz buf buf2, p <> ps)
-- compound fragments that contain only static fragments get written in place
Comp xs | all isSt xs -> go idx (xs <> rest) (buf,ps)
-- dynamic fragments are not yet supported... :/
s -> internalError $ "unsupported cd fragment: " <> show s

isSt :: CalldataFragment -> Bool
Expand Down
16 changes: 16 additions & 0 deletions test/test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2994,6 +2994,22 @@ tests = testGroup "hevm"
let sig = (Just (Sig "stuff(address)" [AbiAddressType]))
(_, [Qed _]) <- withSolvers Z3 1 Nothing $ \s -> checkAssert s defaultPanicCodes c sig [] defaultVeriOpts
putStrLnM $ "Basic tstore check passed"
, test "dynamic-calldata" $ do
Just c <- solcRuntime "C"
[i|
contract C {
uint x;
uint y;
function fun(bytes calldata a) external{
require(x != 0);
require(y != 0);
assert (x == y);
}
}
|]
let sig = (Just (Sig "fun(bytes)" [AbiBytesDynamicType]))
(_, [(Cex _)]) <- withSolvers Z3 1 Nothing $ \s -> checkAssert s [0x01] c sig [] defaultVeriOpts
putStrLnM "Expected counterexample found"
]
, testGroup "concr-fuzz"
[ testFuzz "fuzz-complicated-mul" $ do
Expand Down
Loading