From 670c74610b2907ad642b98467d83f8b15893e789 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Fri, 12 Apr 2024 19:18:46 +0300 Subject: [PATCH] [#xxxx] policy: Hash entity name to support large namespaces Namespace is a part of entity name, so it should be hashed in order to fit neo-go storage key. Signed-off-by: Alex Vanin --- policy/policy_contract.go | 4 ++++ tests/policy_test.go | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/policy/policy_contract.go b/policy/policy_contract.go index 39bb0ce..9d84eeb 100644 --- a/policy/policy_contract.go +++ b/policy/policy_contract.go @@ -4,6 +4,7 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-contract/common" "github.com/nspcc-dev/neo-go/pkg/interop" "github.com/nspcc-dev/neo-go/pkg/interop/iterator" + "github.com/nspcc-dev/neo-go/pkg/interop/native/crypto" "github.com/nspcc-dev/neo-go/pkg/interop/native/management" "github.com/nspcc-dev/neo-go/pkg/interop/runtime" "github.com/nspcc-dev/neo-go/pkg/interop/storage" @@ -107,6 +108,9 @@ func storageKey(prefix Kind, counter int, name []byte) []byte { } func mapKey(kind Kind, name []byte) []byte { + if len(name) > 0 { + name = crypto.Sha256(name) + } return append([]byte{mappingKeyPrefix, byte(kind)}, name...) } diff --git a/tests/policy_test.go b/tests/policy_test.go index 6690a1a..e7fd489 100644 --- a/tests/policy_test.go +++ b/tests/policy_test.go @@ -2,6 +2,7 @@ package tests import ( "bytes" + "crypto/sha256" "path" "testing" @@ -185,8 +186,9 @@ func checkTargets(t *testing.T, e *neotest.ContractInvoker, kind byte, expected require.Equal(t, len(expected), len(targets)) for i := range expected { + exp := sha256.Sum256(expected[i]) bytesTargets, err := targets[i].TryBytes() require.NoError(t, err) - require.Equal(t, expected[i], bytesTargets) + require.Equal(t, exp[:], bytesTargets) } }