Skip to content

Commit

Permalink
nns: disallow conflicting records on register
Browse files Browse the repository at this point in the history
Require no records '*.domain' to be present when registering domain.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
  • Loading branch information
fyrchik committed Dec 2, 2021
1 parent d10da89 commit f25296b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
11 changes: 11 additions & 0 deletions nns/nns_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,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) {
Expand Down
10 changes: 10 additions & 0 deletions tests/nns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,17 @@ func TestNNSRegisterMulti(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)
Expand Down

0 comments on commit f25296b

Please sign in to comment.