-
Notifications
You must be signed in to change notification settings - Fork 62
Maps and Arrays cannot match + masking rewrite rule #756
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
base: main
Are you sure you want to change the base?
Conversation
575ee3b
to
c211e17
Compare
c211e17
to
bde48c6
Compare
Update changelog
bde48c6
to
33af861
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
I am going to trust you with all this map + array business :)
The rewrite rule is nice!
@@ -3953,8 +3976,7 @@ tests = testGroup "hevm" | |||
_ -> False | |||
assertBoolM "Did not find expected storage cex" testCex | |||
putStrLnM "expected counterexample found" | |||
, | |||
expectFail $ test "calling unique contracts (read from storage)" $ do | |||
, test "calling-unique-contracts--read-from-storage" $ do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain what changed here?
What exactly is this test checking?
What was happening before and what is happening now?
@@ -161,6 +161,7 @@ getMultiSol smt2@(SMT2 cmds cexvars _) multiSol r inst availableInstances fileCo | |||
writeChan r Nothing | |||
Right _ -> do | |||
sat <- liftIO $ sendLine inst "(check-sat)" | |||
when conf.dumpQueries $ liftIO $ writeSMT2File smt2 (show fileCounter <> "-origquery") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be in a separate PR?
-- Masking as as per Solidity bit-packing of e.g. function parameters | ||
go (And (Lit mask1) (Or (And (Lit mask2) _) x)) | (mask1 .&. mask2 == 0) | ||
= And (Lit mask1) x | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
Do we get this pattern also in optimized bytecode? Or only unoptimized?
Meaning, is this maybe some optimization that solc should be doing but is not?
(MappingSlot idA _, ArraySlotWithOffs idB (Lit offs)) | isMap' idA, isArray idB, offs < 1000 -> go slot prev | ||
(Keccak idA, ArraySlotWithOffs idB (Lit offs)) | isMap idA, isArray idB, offs < 1000 -> go slot prev | ||
(ArraySlotWithOffs idA (Lit offs), Keccak idB) | isArray idA, isMap idB, offs < 1000 -> go slot prev | ||
(ArraySlotWithOffs idA (Lit offs), MappingSlot idB _) | isArray idA, isMap' idB, offs < 1000 -> go slot prev |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the magic number 1000
?
Description
When either the Array offset is low or 0, Maps and Arrays cannot clash. Furthermore, I added one more rewrite rule that allows us to deal with Solidity argument packing.
I added a test for the masking rewrite rule. It also happens to fix an issue we had in one of our tests, so that has been enabled as well (should have had
ignoreTest
, notexpectFail
, now it's enabled)Checklist