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

Ensure System.Runtime.GetNotifications can't break MaxStackSize constraint #3485

Merged
merged 3 commits into from
Jun 11, 2024

Commits on Jun 11, 2024

  1. stackitem: extend Make() with []string

    Allow []string to be converted to stackitem.Item.
    
    Signed-off-by: Anna Shaleva <[email protected]>
    AnnaShaleva committed Jun 11, 2024
    Configuration menu
    Copy the full SHA
    55fa123 View commit details
    Browse the repository at this point in the history
  2. core: ensure System.Runtime.GetNotifications can't break MaxStackSize

    This test ensures that NeoGo node doesn't have the DeepCopy problem
    described in neo-project/neo#3300 and fixed in
    neo-project/neo#3301. This problem leads to the
    fact that Notifications items are not being properly refcounted by C#
    node which leads to possibility to build an enormously large object on
    stack. Go node doesn't have this problem.
    
    The reason (at least, as I understand it) is in the fact that C# node
    performs objects refcounting inside the DeepCopy even if the object
    itself is not yet on stack. I.e. System.Runtime.Notify handler
    immediately adds references to the notification argumetns inside
    DeepCopy:
    https://github.com/neo-project/neo/blob/b1d27f0189861167b8005a7e40e6d8500fb48cc4/src/Neo.VM/Types/Array.cs#L108
    https://github.com/neo-project/neo/blob/b1d27f0189861167b8005a7e40e6d8500fb48cc4/src/Neo.VM/Types/Array.cs#L75
    
    Whereas Go node just performs the honest DeepCopy without references counting:
    https://github.com/nspcc-dev/neo-go/blob/b66cea5cccbcc8446312b012e29aaf2d1837430a/pkg/vm/stackitem/item.go#L1223
    
    Going further, C# node clears refs for notification arguments (for array
    and underlying array items). System.Runtime.GetNotifications pushes the
    notificaiton args array back on stack and increments counter only for
    the external array, not for its arguments. Which results in negative
    refcounter once notificaiton is removed from the stack. The fix itself
    (https://github.com/Jim8y/neo/blob/f471c0542ddd8f527478fbdcda76a3ab9194b958/src/Neo/SmartContract/NotifyEventArgs.cs#L84)
    doesn't need to be ported to NeoGo because Go node adds object to the
    refcounter only at the moment when it's being pushed to stack by
    System.Runtime.GetNotifications handler. This object is treated as new
    object since it was deepcopied earlier by System.Runtime.Notify handler:
    https://github.com/nspcc-dev/neo-go/blob/b66cea5cccbcc8446312b012e29aaf2d1837430a/pkg/vm/stack.go#L178.
    
    Thus, no functoinal changes from the NeoGo side. And we won't
    intentionally break our node to follow C# pre-Domovoi invalid behaviour.
    
    Close #3484, close #3482.
    
    Signed-off-by: Anna Shaleva <[email protected]>
    AnnaShaleva committed Jun 11, 2024
    Configuration menu
    Copy the full SHA
    effba1f View commit details
    Browse the repository at this point in the history
  3. vm: improve stack size related errors

    No functional changes, just add more details to the error.
    
    Signed-off-by: Anna Shaleva <[email protected]>
    AnnaShaleva committed Jun 11, 2024
    Configuration menu
    Copy the full SHA
    d156cea View commit details
    Browse the repository at this point in the history