Skip to content

[SMTChecker] Fix comparison of CHCVerificationTarget for proper std::set ordering #16147

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 4 commits into
base: develop
Choose a base branch
from

Conversation

radik878
Copy link

@radik878 radik878 commented Aug 5, 2025

What was changed

  • Moved comparison logic from SafeTargetsCompare struct to CHCVerificationTarget::operator<
  • Removed the SafeTargetsCompare struct completely
  • Fixed a bug where == was used instead of < in the comparison operator
  • Updated std::set<CHCVerificationTarget, SafeTargetsCompare> to use default std::set<CHCVerificationTarget>

Copy link

github-actions bot commented Aug 5, 2025

Thank you for your contribution to the Solidity compiler! A team member will follow up shortly.

If you haven't read our contributing guidelines and our review checklist before, please do it now, this makes the reviewing process and accepting your contribution smoother.

If you have any questions or need our help, feel free to post them in the PR or talk to us directly on the #solidity-dev channel on Matrix.

@cameel cameel changed the title Fix typo in SafeTargetsCompare operator for proper std::set ordering Replace equality with less than in SafeTargetsCompare operator for proper std::set ordering Aug 5, 2025
@cameel cameel added the smt label Aug 5, 2025
@cameel cameel requested a review from blishko August 5, 2025 14:11
blishko
blishko previously approved these changes Aug 6, 2025
Copy link
Contributor

@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.

LGMT!

Thanks for finding this out!
I am fine with merging this, but I will look into it further, because CHCVerificationTarget also provides operator<, which, however, works completely differently, which is weird.
I don't think we need both.

@blishko
Copy link
Contributor

blishko commented Aug 6, 2025

It looks like the operator< on CHCVerificationTarget is not really used now.
I think we should just replace the implementation of the operator with the fixed implementation of SafeTargetsCompare and then delete SafeTargetsCompare.

@radik878
Copy link
Author

radik878 commented Aug 6, 2025

It looks like the operator< on CHCVerificationTarget is not really used now. I think we should just replace the implementation of the operator with the fixed implementation of SafeTargetsCompare and then delete SafeTargetsCompare.

Did i make changes correctly?

@cameel
Copy link
Member

cameel commented Aug 6, 2025

Just two general notes:

  • The current state of the PR seems to be actually changing the behavior of the operator slightly, but no tests needed to be updated. That's always suspicious. Either we're missing test coverage or the code is not actually running.
  • Please remember to update the PR/commit description if you change what the PR is about. Currently it still says it's doing what you originally tried to do, which is very misleading.

Copy link
Contributor

@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.

Yes, this is what I meant.

I've just noticed that there was an extra space, can you fix that as well?
Also, can you rebase your branch? I believe that should fix the external tests in CI.

@blishko
Copy link
Contributor

blishko commented Aug 6, 2025

  • The current state of the PR seems to be actually changing the behavior of the operator slightly, but no tests needed to be updated. That's always suspicious. Either we're missing test coverage or the code is not actually running.

My understanding is that this only affects the order of verification targets proved safe.
If I remember correctly, we usually just count them and report the count to the user.
I'll have to think about a way to design a test for this.

  • Please remember to update the PR/commit description if you change what the PR is about. Currently it still says it's doing what you originally tried to do, which is very misleading.

I agree, please update the description.

@blishko
Copy link
Contributor

blishko commented Aug 6, 2025

@cameel, I have checked the codebase and it turns out that the problematic piece of code (one fixed in this PR) is indeed never reached at the moment.

In current codebase the comparison is only used in std::map<ASTNode const*, std::set<CHCVerificationTarget>, smt::EncodingContext::IdCompare> m_safeTargets, in the value, which is a set of CHCVerificationTarget, where the verification targets are sorted.
However, we only add two targets to the same set if they are associated with the same ASTNode, which is the key in the m_safeTargets map.
So we only have compare two targets if they have the same errorNode, which is exactly the if-condition of the comparison.

Thus currently, the bug was never triggered, but it was indeed a hidden bug in the implementation.

My conclusion is that other than a unit test, we are not able to test the changed place in the code, and we don't have unit tests, right?
So, I would merge this PR, after it is rebased and description updated, as is.

@radik878
Copy link
Author

radik878 commented Aug 6, 2025

@cameel, I have checked the codebase and it turns out that the problematic piece of code (one fixed in this PR) is indeed never reached at the moment.

In current codebase the comparison is only used in std::map<ASTNode const*, std::set<CHCVerificationTarget>, smt::EncodingContext::IdCompare> m_safeTargets, in the value, which is a set of CHCVerificationTarget, where the verification targets are sorted. However, we only add two targets to the same set if they are associated with the same ASTNode, which is the key in the m_safeTargets map. So we only have compare two targets if they have the same errorNode, which is exactly the if-condition of the comparison.

Thus currently, the bug was never triggered, but it was indeed a hidden bug in the implementation.

My conclusion is that other than a unit test, we are not able to test the changed place in the code, and we don't have unit tests, right? So, I would merge this PR, after it is rebased and description updated, as is.

updated description

Copy link
Contributor

@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.

Thanks!

@blishko blishko changed the title Replace equality with less than in SafeTargetsCompare operator for proper std::set ordering [SMTChecker] Fix comparison of CHCVerificationTarget for proper std::set ordering Aug 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants