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

Fix signers IInteroperable.ToStackItem #3221

Merged
merged 4 commits into from
May 10, 2024
Merged

Fix signers IInteroperable.ToStackItem #3221

merged 4 commits into from
May 10, 2024

Conversation

shargon
Copy link
Member

@shargon shargon commented May 9, 2024

Close #3034

@shargon shargon changed the title Fix signers IInteroperable.ToStackItem Fix signers IInteroperable.ToStackItem May 9, 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.

Looks good

@cschuchardt88 cschuchardt88 mentioned this pull request May 9, 2024
Comment on lines +199 to +202
Scopes.HasFlag(WitnessScope.CustomContracts) ? new VM.Types.Array(referenceCounter, AllowedContracts.Select(u => new VM.Types.ByteString(u.ToArray()))) : new VM.Types.Array(referenceCounter),
Scopes.HasFlag(WitnessScope.CustomGroups) ? new VM.Types.Array(referenceCounter, AllowedGroups.Select(u => new VM.Types.ByteString(u.ToArray()))) : new VM.Types.Array(referenceCounter),
Scopes.HasFlag(WitnessScope.WitnessRules) ? new VM.Types.Array(referenceCounter, Rules.Select(u => u.ToStackItem(referenceCounter))) : new VM.Types.Array(referenceCounter)
]);
Copy link
Member

@cschuchardt88 cschuchardt88 May 9, 2024

Choose a reason for hiding this comment

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

Suggested change
Scopes.HasFlag(WitnessScope.CustomContracts) ? new VM.Types.Array(referenceCounter, AllowedContracts.Select(u => new VM.Types.ByteString(u.ToArray()))) : new VM.Types.Array(referenceCounter),
Scopes.HasFlag(WitnessScope.CustomGroups) ? new VM.Types.Array(referenceCounter, AllowedGroups.Select(u => new VM.Types.ByteString(u.ToArray()))) : new VM.Types.Array(referenceCounter),
Scopes.HasFlag(WitnessScope.WitnessRules) ? new VM.Types.Array(referenceCounter, Rules.Select(u => u.ToStackItem(referenceCounter))) : new VM.Types.Array(referenceCounter)
]);
AllowedContracts != null ? new VM.Types.Array(referenceCounter, AllowedContracts.Select(u => new VM.Types.ByteString(u.ToArray()))) : new VM.Types.Array(referenceCounter),
AllowedGroups != null ? new VM.Types.Array(referenceCounter, AllowedGroups.Select(u => new VM.Types.ByteString(u.ToArray()))) : new VM.Types.Array(referenceCounter),
Rules != null ? new VM.Types.Array(referenceCounter, Rules.Select(u => u.ToStackItem(referenceCounter))) : new VM.Types.Array(referenceCounter)
]);

The crash is happening because AllowedContracts, AllowedGroups and Rules is null, and doing .Select() will still cause a crash with those flags set. Take in count ApplicationEngine.Run and Dynamic Scripts.

Copy link
Member

Choose a reason for hiding this comment

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

@shargon @roman-khimov @AnnaShaleva
This should work now.

Copy link
Member Author

Choose a reason for hiding this comment

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

The flags are used in other serializable methods, so we should fix the flags if are wrong in cli

Copy link
Member

@cschuchardt88 cschuchardt88 May 9, 2024

Choose a reason for hiding this comment

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

Are you able to do Rules?.Select()? For example new VM.Types.Array(referenceCounter, Rules?.Select(u => u.ToStackItem(referenceCounter)))

But look at Call Stack->NullException

   at System.Linq.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument)
   at System.Linq.Enumerable.Select[TSource,TResult](IEnumerable`1 source, Func`2 selector)
   at Neo.Network.P2P.Payloads.Signer.Neo.SmartContract.IInteroperable.ToStackItem(ReferenceCounter referenceCounter)
   at Neo.SmartContract.ApplicationEngine.Convert(Object value)
   at Neo.SmartContract.ApplicationEngine.<Convert>b__95_0(Object p)

@NGDAdmin NGDAdmin merged commit d713d2b into master May 10, 2024
5 of 6 checks passed
@NGDAdmin NGDAdmin deleted the core-fix-signers-2 branch May 10, 2024 02:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

System_Runtime_CurrentSigners LInq ArgumentNullException in ApplicationEngine
7 participants