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

[Neo VM Bug] Fix negative counter issue #3327

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

shargon
Copy link
Member

@shargon shargon commented Jun 11, 2024

Code of this PR contains a @Jim8y's work

Description

This pr fixes the negative reference counter issue.

Fixes #3328

Type of change

  • Optimization (the change is only an optimization)
  • Style (the change is only a code style for better maintenance or standard purpose)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

  • TestNegativeReferenceCounter

Test Configuration:

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@shargon shargon requested a review from Jim8y June 11, 2024 07:56
@shargon shargon added the bug Used to tag confirmed bugs label Jun 11, 2024
@shargon shargon marked this pull request as ready for review June 11, 2024 08:01
@Jim8y
Copy link
Contributor

Jim8y commented Jun 11, 2024

Can you please explain your solution?

foreach (StackItem subitem in compound.SubItems)
{
if (component.Contains(subitem)) continue;
if (!NeedTrack(subitem)) continue;
subitem.ObjectReferences!.Remove(compound);
references_count--;
Copy link
Contributor

Choose a reason for hiding this comment

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

this ensures that it can be properly removed, but i think there is also problem of adding reference.

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you have an example?

Copy link
Member

@cschuchardt88 cschuchardt88 Jun 16, 2024

Choose a reason for hiding this comment

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

I believe if it goes negative it means the item was never met from previous one StackItem. You can use the CachedComponents to see.

Jim8y
Jim8y previously approved these changes Jun 11, 2024
@AnnaShaleva
Copy link
Member

I need some more time to check the compatibility with NeoGo, and this code should be symmetric to refs addition.

Comment on lines 121 to 123
if (!NeedTrack(subitem)) continue;
subitem.ObjectReferences!.Remove(compound);
references_count--;
Copy link
Member

Choose a reason for hiding this comment

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

I'd expect references removal to be symmetric wrt references addition. And currently it's asymmetric because there's if (!NeedTrack(subitem)) continue; a few lines above; and during references addition we always increment refcounter irrespective of NeedTrack:

references_count++;
if (!NeedTrack(item)) return;

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, maybe we need to move the line before that if

Copy link
Member Author

Choose a reason for hiding this comment

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

It fails if is symmetric, we get a negative counter

Copy link
Member

Choose a reason for hiding this comment

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

The thing that I'm worried about is that we should find the reason why symmetric approach doesn't work. Right now I don't completely understand it.

@Jim8y
Copy link
Contributor

Jim8y commented Aug 10, 2024

@shargon any plan about this pr?

@shargon
Copy link
Member Author

shargon commented Aug 11, 2024

@shargon any plan about this pr?

I think that the fix is good, but now with your PR it can be closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Used to tag confirmed bugs waiting for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

How to handle [possible] negative VM refcounter
5 participants