From d5b1c0e429679432c35109476d5d77f041f427a5 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Thu, 15 Sep 2022 22:27:09 +0300 Subject: [PATCH] nns: check for conflicting records on domain registration Port https://github.com/nspcc-dev/neofs-contract/pull/175/commits/f25296b17a4dcaca50855c40d44a42bbcf0bb6a1. --- examples/nft-nd-nns/nns.go | 11 +++++++++++ examples/nft-nd-nns/nns_test.go | 10 ++++++++++ 2 files changed, 21 insertions(+) diff --git a/examples/nft-nd-nns/nns.go b/examples/nft-nd-nns/nns.go index c3b04931b..f3e09d950 100644 --- a/examples/nft-nd-nns/nns.go +++ b/examples/nft-nd-nns/nns.go @@ -272,6 +272,17 @@ func Register(name string, owner interop.Hash160, email string, refresh, retry, nsBytes := storage.Get(ctx, append([]byte{prefixName}, parentKey...)) ns := std.Deserialize(nsBytes.([]byte)).(NameState) ns.checkAdmin() + + parentRecKey := append([]byte{prefixRecord}, parentKey...) + it := storage.Find(ctx, parentRecKey, storage.ValuesOnly|storage.DeserializeValues) + suffix := []byte(name) + for iterator.Next(it) { + r := iterator.Value(it).(RecordState) + ind := std.MemorySearchLastIndex([]byte(r.Name), suffix, len(r.Name)) + if ind > 0 && ind+len(suffix) == len(r.Name) { + panic("parent domain has conflicting records: " + r.Name) + } + } } if !isValid(owner) { diff --git a/examples/nft-nd-nns/nns_test.go b/examples/nft-nd-nns/nns_test.go index 1441baa2b..09e96a46f 100644 --- a/examples/nft-nd-nns/nns_test.go +++ b/examples/nft-nd-nns/nns_test.go @@ -623,7 +623,17 @@ func TestNNSRegisterArbitraryLevelDomain(t *testing.T) { args = newArgs("mainnet.fs.neo.com", acc2) c2.InvokeFail(t, "not witnessed by admin", "register", args...) + c1.Invoke(t, stackitem.Null{}, "addRecord", + "something.mainnet.fs.neo.com", int64(nns.A), "1.2.3.4") + c1.Invoke(t, stackitem.Null{}, "addRecord", + "another.fs.neo.com", int64(nns.A), "4.3.2.1") + c2 = c.WithSigners(acc, acc2) + c2.InvokeFail(t, "parent domain has conflicting records: something.mainnet.fs.neo.com", + "register", args...) + + c1.Invoke(t, stackitem.Null{}, "deleteRecords", + "something.mainnet.fs.neo.com", int64(nns.A)) c2.Invoke(t, true, "register", args...) c2 = c.WithSigners(acc2)