Skip to content

Commit

Permalink
smartcontract: fix wildcard trusts deserialization
Browse files Browse the repository at this point in the history
If manifest trusts presented as Null stackitem, then they should be
treated as wildcard, not as restricted.

It's not the same problem as described and fixed in
neo-project/neo#2901 and
https://github.com/neo-project/neo/pull/2892/files, although these
two PRs are related.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
  • Loading branch information
AnnaShaleva committed Sep 25, 2023
1 parent eb571a1 commit 7ce0332
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions pkg/core/state/contract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ func TestContractStateToFromSI(t *testing.T) {
t.Run("Convertible", func(t *testing.T) {
contractDecoded := new(Contract)
testserdes.ToFromStackItem(t, contract, contractDecoded)

t.Run("preserve wildcard trusts", func(t *testing.T) {
contract.Manifest.Trusts.Value = nil
require.True(t, contract.Manifest.Trusts.IsWildcard())
actual := new(Contract)
item, err := contract.ToStackItem()
require.NoError(t, err)
require.NoError(t, actual.FromStackItem(item))
require.True(t, actual.Manifest.Trusts.IsWildcard())
})
})
t.Run("JSON", func(t *testing.T) {
contractDecoded := new(Contract)
Expand Down
2 changes: 1 addition & 1 deletion pkg/smartcontract/manifest/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ func (m *Manifest) FromStackItem(item stackitem.Item) error {
m.Permissions[i] = *p
}
if _, ok := str[6].(stackitem.Null); ok {
m.Trusts.Restrict()
m.Trusts = WildPermissionDescs{Value: nil} // wildcard by default
} else {
if str[6].Type() != stackitem.ArrayT {
return errors.New("invalid Trusts stackitem type")
Expand Down

0 comments on commit 7ce0332

Please sign in to comment.