Skip to content

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

msooseth
Copy link
Collaborator

@msooseth msooseth commented May 26, 2025

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, not expectFail, now it's enabled)

Checklist

  • tested locally
  • added automated tests
  • updated the docs
  • updated the changelog

@msooseth msooseth force-pushed the array-map-cannot-clash branch 3 times, most recently from 575ee3b to c211e17 Compare May 31, 2025 10:47
@msooseth msooseth changed the title [DRAFT] Maps and Arrays cannot match [DRAFT] Maps and Arrays cannot match + masking rewrite rule May 31, 2025
@msooseth msooseth force-pushed the array-map-cannot-clash branch from c211e17 to bde48c6 Compare May 31, 2025 10:50
@msooseth msooseth force-pushed the array-map-cannot-clash branch from bde48c6 to 33af861 Compare May 31, 2025 10:58
@msooseth msooseth marked this pull request as ready for review May 31, 2025 10:59
@msooseth msooseth changed the title [DRAFT] Maps and Arrays cannot match + masking rewrite rule Maps and Arrays cannot match + masking rewrite rule May 31, 2025
Copy link
Collaborator

@blishko blishko left a 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
Copy link
Collaborator

@blishko blishko Jun 1, 2025

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")
Copy link
Collaborator

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?

Comment on lines +1091 to +1094
-- 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

Copy link
Collaborator

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?

Comment on lines +661 to +664
(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
Copy link
Collaborator

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants