Skip to content

Conversation

@Jim8y
Copy link
Contributor

@Jim8y Jim8y commented Dec 12, 2025

This pull request enhances the safety and correctness of array, buffer, and byte string index handling in the Neo VM by improving overflow and underflow checks and ensuring consistent type usage for indices. It also adds new test cases to verify these edge conditions.

Improvements to index validation and safety:

  • Updated index validation logic in HasKey for VMArray, Buffer, and ByteString to check both lower and upper bounds using appropriate engine limits, preventing overflow and underflow errors. [1] [2]
  • Standardized index handling in PickItem, SetItem, and Remove methods to use BigInteger for indices and explicitly cast to int only when accessing collections, improving type safety and clarity. [1] [2] [3] [4] [5]

Testing improvements:

  • Added new test cases in HASKEY.json to verify correct FAULT behavior when array indices overflow or underflow, ensuring these edge cases are properly handled.

ajara87
ajara87 previously approved these changes Dec 12, 2025
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.

This require a Hardfork, and new Jump table

shargon
shargon previously approved these changes Dec 12, 2025
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.

@Jim8y could you create the jump table in neo repository?

@shargon shargon dismissed stale reviews from ajara87 and themself via 872c249 December 12, 2025 11:04
shargon
shargon previously approved these changes Dec 12, 2025
erikzhang
erikzhang previously approved these changes Dec 12, 2025
ajara87
ajara87 previously approved these changes Dec 12, 2025
@roman-khimov
Copy link
Contributor

Why is it better than OverflowException? Realistically proper indexes are from 0 to 2047, so any code passing MaxInt32+N is broken in about the same way code passing -1 is.

@erikzhang
Copy link
Member

Why is it better than OverflowException? Realistically proper indexes are from 0 to 2047, so any code passing MaxInt32+N is broken in about the same way code passing -1 is.

You are right. I'll fix it.

@erikzhang erikzhang dismissed stale reviews from ajara87, shargon, and themself via 340cb1a December 13, 2025 03:20
@shargon
Copy link
Member

shargon commented Dec 15, 2025

Require neo-project/neo#4381

Copy link
Contributor

@roman-khimov roman-khimov left a comment

Choose a reason for hiding this comment

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

Wish there are more tests for it (that would spot the difference in behavior), but ok logically.

@Jim8y
Copy link
Contributor Author

Jim8y commented Dec 17, 2025

Wish there are more tests for it (that would spot the difference in behavior), but ok logically.

Hi Roman @roman-khimov , do you have any idea how could we use test or anything that can formally define and verify the behavior of vm, i think it would be much better if we can use some kind of spec to formally and strictly define the behavior such that we can automatically discover any incompatiable issues if any.

@roman-khimov
Copy link
Contributor

Practically current JSON-based tests are very nice to me, at least they're easy to reuse for different VM implementations. Formal spec or model is a different story.

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.

8 participants