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 Optimization] Detect reference counter miscalculation. #3325

Closed
wants to merge 16 commits into from

Conversation

Jim8y
Copy link
Contributor

@Jim8y Jim8y commented Jun 11, 2024

Description

This pr checks the stackitems being pushed to the stack only contains items that are on the stack.

Why is this problem?

We can literarily create stackitems at anywhere in the execition engine and push it to the evaluation stack, it is highly possible that we construct compound type stackitems that also contain compound type, then when we push it to the stack, only the first demension subitem will be added to the reference counter, the second/higher demonsion subitems will be ignored.

Fixes # (issue)

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?

  • TestInvalidReferenceStackItem

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

@Hecate2
Copy link
Contributor

Hecate2 commented Jun 11, 2024

if (!subItem.OnStack) is often triggered. The subitems are exactly not OnStack.

Copy link
Member

@shargon shargon left a comment

Choose a reason for hiding this comment

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

How can this happens in a real environment?

tests/Neo.VM.Tests/UT_EvaluationStack.cs Show resolved Hide resolved
@Hecate2
Copy link
Contributor

Hecate2 commented Jun 11, 2024

Now the tests can be passed, but I think nothing is really checked

@Jim8y
Copy link
Contributor Author

Jim8y commented Jun 11, 2024

How can this happens in a real environment?

will add ut tests, still working on it.

Jim8y added 3 commits June 11, 2024 21:01
…ack-item

* 'check-stack-item' of github.com:Jim8y/neo:
  fix all tests
  skip `if (!subItem.OnStack)`
  use ReferenceEqualityComparer for CompoundType

# Conflicts:
#	src/Neo.VM/EvaluationStack.cs
@Jim8y Jim8y changed the title [Neo VM Optimization] Check stack item on compound type [Neo VM Optimization] Detect any type of reference counter miscalculation. Jun 12, 2024
@Jim8y Jim8y changed the title [Neo VM Optimization] Detect any type of reference counter miscalculation. [Neo VM Optimization] Detect reference counter miscalculation. Jun 12, 2024
Copy link
Member

@vncoelho vncoelho left a comment

Choose a reason for hiding this comment

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

Too much HF and do not solve,as we discussed.
Do not merge for now.

@Jim8y
Copy link
Contributor Author

Jim8y commented Jun 15, 2024

With #3334 this is unnecesssary anymore

@Jim8y Jim8y closed this Jun 15, 2024
@Jim8y Jim8y deleted the check-stack-item branch June 15, 2024 13:46
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.

5 participants