diff --git a/common/witness.go b/common/witness.go index ba2b9c6..f2e2c83 100644 --- a/common/witness.go +++ b/common/witness.go @@ -1,6 +1,10 @@ package common -import "github.com/nspcc-dev/neo-go/pkg/interop/runtime" +import ( + "github.com/nspcc-dev/neo-go/pkg/interop/contract" + "github.com/nspcc-dev/neo-go/pkg/interop/native/neo" + "github.com/nspcc-dev/neo-go/pkg/interop/runtime" +) var ( // ErrAlphabetWitnessFailed appears when the method must be @@ -37,3 +41,16 @@ func checkWitnessWithPanic(caller []byte, panicMsg string) { panic(panicMsg) } } + +// CheckCommittee panics if the script container is not signed by the committee. +func CheckCommittee() { + committee := neo.GetCommittee() + if committee == nil { + panic("failed to get committee") + } + l := len(committee) + committeeMultisig := contract.CreateMultisigAccount(l-(l-1)/2, committee) + if committeeMultisig == nil || !runtime.CheckWitness(committeeMultisig) { + panic("not witnessed by committee") + } +} diff --git a/nns/nns_contract.go b/nns/nns_contract.go index d4bc83b..3144bfb 100644 --- a/nns/nns_contract.go +++ b/nns/nns_contract.go @@ -15,7 +15,6 @@ import ( "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/native/neo" "github.com/nspcc-dev/neo-go/pkg/interop/native/std" "github.com/nspcc-dev/neo-go/pkg/interop/runtime" "github.com/nspcc-dev/neo-go/pkg/interop/storage" @@ -93,7 +92,7 @@ type RecordState struct { // Update updates NameService contract. func Update(nef []byte, manifest string, data any) { - checkCommittee() + common.CheckCommittee() // Calculating keys and serializing requires calling // std and crypto contracts. This can be helpful on update // thus we provide `AllowCall` to management.Update. @@ -219,7 +218,7 @@ func Roots() iterator.Iterator { // SetPrice sets the domain registration price. func SetPrice(price int64) { - checkCommittee() + common.CheckCommittee() if price < 0 || price > maxRegisterPrice { panic("The price is out of range.") } @@ -928,20 +927,7 @@ func isValid(address interop.Hash160) bool { // or if the owner does not have permission in FrostfsID. func checkCommitteeAndFrostfsID(ctx storage.Context, owner interop.Hash160) { if !checkFrostfsID(ctx, owner) { - checkCommittee() - } -} - -// checkCommittee panics if the script container is not signed by the committee. -func checkCommittee() { - committee := neo.GetCommittee() - if committee == nil { - panic("failed to get committee") - } - l := len(committee) - committeeMultisig := contract.CreateMultisigAccount(l-(l-1)/2, committee) - if committeeMultisig == nil || !runtime.CheckWitness(committeeMultisig) { - panic("not witnessed by committee") + common.CheckCommittee() } }