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

SMTChecker: Relax assertions regarding sort compatibility when creating expressions #14980

Merged
merged 4 commits into from Apr 12, 2024

Conversation

blishko
Copy link
Contributor

@blishko blishko commented Apr 3, 2024

This finishes the work started by #14180, which relaxed most of the assertions related to checking compatibility of sorts to allow mixing signed and unsigned Int sorts.

This PR has two parts:

  1. Introduces a helper method that expresses the intent of the check and replaces if-then-else branches with this method call.
  2. Relaxes one more assertion: in creating array store expression, we are checking if the array's domain sort and access index sort are compatible instead of equal.

Fixes #14792.

matheusaaguiar
matheusaaguiar previously approved these changes Apr 9, 2024
Copy link
Collaborator

@matheusaaguiar matheusaaguiar left a comment

Choose a reason for hiding this comment

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

LGTM, but I think maybe we could improve test coverage?

mapping(int => int) v1;
mapping(int => uint) v2;
mapping(uint => int) v3;
mapping(uint => uint) v4;
Copy link
Collaborator

Choose a reason for hiding this comment

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

What about mixing other types like mapping(bytes14 => int) and mapping(uint => bytes14)?
Also, I was looking at #14840 and noticed that in that in

mapping(bool => int240) internal v1;
v1 is declared and not used. Although this is already merged I was wondering about that.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I wanted to suggest a more meaningful name to this test too.
Maybe mapping_integer_signedness_compatibility/deletion ... I just think we should not continue the trend of just numbering these tests which contain mappings :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Still regarding the tests, could we also add tests involving arrays, i.e, int[] x, uint[10] y or does that makes no sense here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, I was looking at #14840 and noticed that in that in

mapping(bool => int240) internal v1;

v1 is declared and not used. Although this is already merged I was wondering about that.

The example in #14791 was crashing with this kind of mapping just being declared, but not used. So I kept it in the test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will rename the test, I agree that it should named properly.

What about mixing other types like mapping(bytes14 => int) and mapping(uint => bytes14)?

I can add more of these mappings, did not think of bytes. The problem was in the type of the domain vs the type of the index. I believe the type of the range should not actually matter.

Still regarding the tests, could we also add tests involving arrays, i.e, int[] x, uint[10] y or does that makes no sense here?

You mean declaring such arrays and then trying to access/delete some element?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I can add more of these mappings, did not think of bytes. The problem was in the type of the domain vs the type of the index. I believe the type of the range should not actually matter.

Ok.

You mean declaring such arrays and then trying to access/delete some element?

Yes, but I am not sure if that makes sense in the context of the problem here.

The helper method makes clear the intent clear and should be more
readable than if-then-else branches with smtAssertions.
Moreover, some of the if-conditions were not checking the right thing.
@blishko
Copy link
Contributor Author

blishko commented Apr 12, 2024

@matheusaaguiar , I renamed the test, added a mapping with bytes and an array. Also added a changelog entry.

Do you think we can merge this?

@blishko blishko force-pushed the smt-int-sorts-compatibility branch from 255a630 to 0c831e0 Compare April 12, 2024 08:47
Copy link
Collaborator

@matheusaaguiar matheusaaguiar left a comment

Choose a reason for hiding this comment

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

Approved.
We could squash commits, but that's more aesthetics than a requirement.

@blishko blishko merged commit 6c7e686 into develop Apr 12, 2024
73 checks passed
@blishko blishko deleted the smt-int-sorts-compatibility branch April 12, 2024 14:27
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.

SMT logic error for mapping index access with a string literal
2 participants