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 contract trust FromStackItem ContractPermissionDescriptor.Create(StackItem item) #2901

Merged
merged 4 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Neo/SmartContract/Manifest/ContractManifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void IInteroperable.FromStackItem(StackItem stackItem)
{
Null _ => WildcardContainer<ContractPermissionDescriptor>.CreateWildcard(),
// Array array when array.Any(p => ((ByteString)p).Size == 0) => WildcardContainer<ContractPermissionDescriptor>.CreateWildcard(),
Array array => WildcardContainer<ContractPermissionDescriptor>.Create(array.Select(p => new ContractPermissionDescriptor(p.GetSpan())).ToArray()),
Array array => WildcardContainer<ContractPermissionDescriptor>.Create(array.Select(ContractPermissionDescriptor.Create).ToArray()),
Comment on lines 83 to +84
Copy link
Contributor

Choose a reason for hiding this comment

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

Well i still recommand to have this logic: if any of the permission is any, then the permission is any:

                Array array when array.Any(p => p.Equals(StackItem.Null)) => WildcardContainer<ContractPermissionDescriptor>.CreateWildcard(),
                Array array => WildcardContainer<ContractPermissionDescriptor>.Create(array.Select(ContractPermissionDescriptor.Create).ToArray()),

_ => throw new ArgumentException(null, nameof(stackItem))
};
Extra = (JObject)JToken.Parse(@struct[7].GetSpan());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Neo.Cryptography.ECC;
using Neo.IO;
using Neo.Json;
using Neo.VM.Types;
using System;

namespace Neo.SmartContract.Manifest
Expand Down Expand Up @@ -66,6 +67,11 @@ internal ContractPermissionDescriptor(ReadOnlySpan<byte> span)
}
}

public static ContractPermissionDescriptor Create(StackItem item)
{
return item.Equals(StackItem.Null) ? CreateWildcard() : new ContractPermissionDescriptor(item.GetSpan());
}

/// <summary>
/// Creates a new instance of the <see cref="ContractPermissionDescriptor"/> class with the specified contract hash.
/// </summary>
Expand Down