diff --git a/pkg/core/mpt/extension.go b/pkg/core/mpt/extension.go index 026201655..7cb0bb7f0 100644 --- a/pkg/core/mpt/extension.go +++ b/pkg/core/mpt/extension.go @@ -11,8 +11,14 @@ import ( "github.com/nspcc-dev/neo-go/pkg/util" ) -// MaxKeyLength is the max length of the extension node key. -const MaxKeyLength = (storage.MaxStorageKeyLen + 4) * 2 +const ( + // maxPathLength is the max length of the extension node key. + maxPathLength = (storage.MaxStorageKeyLen + 4) * 2 + + // MaxKeyLength is the max length of the key to put in trie + // before transforming to nibbles. + MaxKeyLength = maxPathLength / 2 +) // ExtensionNode represents MPT's extension node. type ExtensionNode struct { @@ -48,7 +54,7 @@ func (e *ExtensionNode) Bytes() []byte { // DecodeBinary implements io.Serializable. func (e *ExtensionNode) DecodeBinary(r *io.BinReader) { sz := r.ReadVarUint() - if sz > MaxKeyLength { + if sz > maxPathLength { r.Err = fmt.Errorf("extension node key is too big: %d", sz) return } diff --git a/pkg/core/mpt/node.go b/pkg/core/mpt/node.go index 2d2c42807..5f8aed265 100644 --- a/pkg/core/mpt/node.go +++ b/pkg/core/mpt/node.go @@ -96,7 +96,7 @@ func (n *NodeObject) UnmarshalJSON(data []byte) error { key, err := unmarshalHex(keyRaw) if err != nil { return err - } else if len(key) > MaxKeyLength { + } else if len(key) > maxPathLength { return errors.New("extension key is too big") } diff --git a/pkg/core/mpt/node_test.go b/pkg/core/mpt/node_test.go index 74c0247a2..0af0509a9 100644 --- a/pkg/core/mpt/node_test.go +++ b/pkg/core/mpt/node_test.go @@ -61,7 +61,7 @@ func TestNode_Serializable(t *testing.T) { t.Run("WithType", getTestFuncEncode(true, &NodeObject{e}, new(NodeObject))) }) t.Run("BigKey", getTestFuncEncode(false, - NewExtensionNode(random.Bytes(MaxKeyLength+1), NewLeafNode(random.Bytes(10))), new(ExtensionNode))) + NewExtensionNode(random.Bytes(maxPathLength+1), NewLeafNode(random.Bytes(10))), new(ExtensionNode))) }) t.Run("Branch", func(t *testing.T) { diff --git a/pkg/core/mpt/trie_test.go b/pkg/core/mpt/trie_test.go index bbb3b9828..405c501dc 100644 --- a/pkg/core/mpt/trie_test.go +++ b/pkg/core/mpt/trie_test.go @@ -161,7 +161,7 @@ func TestTrie_PutInvalid(t *testing.T) { key, value := []byte("key"), []byte("value") // big key - require.Error(t, tr.Put(make([]byte, MaxKeyLength+1), value)) + require.Error(t, tr.Put(make([]byte, maxPathLength+1), value)) // big value require.Error(t, tr.Put(key, make([]byte, MaxValueLength+1)))