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 1 commit 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

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.

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
@blishko blishko enabled auto-merge August 7, 2025 06:47
@cameel cameel disabled auto-merge August 7, 2025 15:08
@cameel
Copy link
Member

cameel commented Aug 7, 2025

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?

Well, we do have boost tests and do sometimes use unit tests for stuff we cannot reach with code snippets, but I agree - this one is not a case where I'd add one. It does not seem worth the effort. I pointed it out as a general precaution to the contributor, but if you checked the code and think it's fine, I trust your judgement here.

BTW, I disabled automerge because it got stuck and also because the commits need squashing first. This is a single change, it does not need 4 commits. Especially there should be no merge commits in there, those make history just unreadable.

@blishko
Copy link
Contributor

blishko commented Aug 7, 2025

I agree. @radik878 can you squash the commits?

@radik878
Copy link
Author

radik878 commented Aug 7, 2025

I agree. @radik878 can you squash the commits?

Tough to say, 'Unable to squash. Squashing replays all commits up to the last one required for the squash. A merge commit cannot exist among those commits.'
This error and I don't know what to do with this

@cameel
Copy link
Member

cameel commented Aug 7, 2025

@blishko
Copy link
Contributor

blishko commented Aug 8, 2025

You basically need to remove the merge commit, then you will be able to squash your three commits.
Do you need help with that?

@radik878
Copy link
Author

radik878 commented Aug 8, 2025

You basically need to remove the merge commit, then you will be able to squash your three commits. Do you need help with that?

I tried but i don't know. Github desktop doesn't let me remove merge commit

@blishko
Copy link
Contributor

blishko commented Aug 8, 2025

Let me see if I can do something on my side.

It's a good idea to learn git directly (not relying solely on GitHub), it's a very useful skill!

@radik878
Copy link
Author

radik878 commented Aug 8, 2025

Let me see if I can do something on my side.

It's a good idea to learn git directly (not relying solely on GitHub), it's a very useful skill!

It's really a good idea, I am convinced of this once again.

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