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

New CopySlice rule that helps to avoid symbolic copyslice in case of overapproximation #667

Merged
merged 10 commits into from
Feb 20, 2025

Conversation

msooseth
Copy link
Collaborator

@msooseth msooseth commented Feb 18, 2025

Description

This allows us to skip the symbolic copyslice. Basically it's copying over a EMPTY concretebuf values that have been copied from an abstractbuf and ONLY those values. So the result is just the abstractbuf! This helps a lot in avoiding sybmolic copyslice.

Checklist

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

@msooseth msooseth changed the title Adding test to check when staticcall is NOT overapproximated [DRAFT] Adding test to check when staticcall is NOT overapproximated, and NOT partial, NOT unknown/error Feb 18, 2025
@msooseth msooseth force-pushed the no-overapprox-when-good-test branch 2 times, most recently from e7e12a9 to c76eaa2 Compare February 18, 2025 18:44
@msooseth msooseth changed the title [DRAFT] Adding test to check when staticcall is NOT overapproximated, and NOT partial, NOT unknown/error New CopySlice rule that helps to avoid symbolic copyslice in case of overapproximation Feb 18, 2025
@msooseth msooseth force-pushed the no-overapprox-when-good-test branch 2 times, most recently from 4c2ee69 to ce5edb7 Compare February 19, 2025 12:06
@msooseth msooseth force-pushed the no-overapprox-when-good-test branch from ce5edb7 to a0c1517 Compare February 19, 2025 12:12
@msooseth msooseth marked this pull request as ready for review February 19, 2025 12:15
@msooseth msooseth requested a review from blishko February 19, 2025 12:15
-- go (CopySlice (Lit 0) (Lit 0) (BufLength (AbstractBuf k1))
-- (CopySlice (Lit 0) (Lit 0) (BufLength (AbstractBuf k2)) (AbstractBuf k3) _)
-- (ConcreteBuf "")) | k1 == k2 && k2 == k3 = (AbstractBuf k1)
, test "overapproximates-undeployed-contract" $ do
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this test be merged with the previous one?
It is doing the same work, no?
Only checks on the result are different.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, they are different, weirdly enough! The one above actually works without the simplifications. But this one does not. It's because Target was not deployed in this case, so it's abstracted over. Since we are not running a forge test, we don't have a setUp() and nothing is set up, so mm is actually not deployed. Weird, but true.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see now.
Yeah, that's pretty weird.
The state variable mm is never assigned.
Won't the variable have always value 0? Shouldn't we that call mm.get is always trying to call function on address 0?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh good point, it is trying to call address 0. But there is nothing at 0, so it overapproximates. Which is OK in this case, I think. Although we could emit a warning for call to address zero. Let me create an issue to track this. Would be hepful to emit a warning probably. It can happen, but in this case, we can't really do much about it. However, it is likely unintended.

In the meanwhile, I'm merging, with a note that this is address 0, and the contract is obviously not deployed there...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documented here: #671

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last note, sorry for distracting you.
But, if we know the call is to zero address, we know that it will revert, no?

I don't know if I understand correctly how EVM works, but the call will lead to revert, so the assertion will not be reached, no?
It seems to me from your description that the counterexamples show how the assertion can be reached, but these are spurious, no?

Let me know if I am misunderstanding something.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, good point. This is getting to be bigger than I wanted... can we merge this and document that as part of #671 ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's getting to be too much to keep in mind and work on at the same time...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK!

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.

Looks good!

I just wonder about that test...

@msooseth
Copy link
Collaborator Author

Thanks for the review! Let me think about my idea to track that zero address as an issue to be addressed separately and then we can hopefully merge this :)

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.

LGTM!

@msooseth msooseth merged commit dd8c479 into main Feb 20, 2025
9 checks passed
@msooseth msooseth deleted the no-overapprox-when-good-test branch February 20, 2025 14:44
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