From 378e69c0154cb7861c3875e24dfa0c310b955906 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Mon, 20 Sep 2021 18:05:49 +0300 Subject: [PATCH] [#107] common: Check committee witness for contract update Signed-off-by: Alex Vanin --- common/ir.go | 13 +++++++------ common/update.go | 18 +++--------------- 2 files changed, 10 insertions(+), 21 deletions(-) diff --git a/common/ir.go b/common/ir.go index 86f50b5..6fc050e 100644 --- a/common/ir.go +++ b/common/ir.go @@ -55,6 +55,12 @@ func AlphabetAddress() []byte { return Multiaddress(alphabet, false) } +// CommitteeAddress returns multi address of committee. +func CommitteeAddress() []byte { + committee := neo.GetCommittee() + return Multiaddress(committee, true) +} + // Multiaddress returns default multi signature account address for N keys. // If committee set to true, then it is `M = N/2+1` committee account. func Multiaddress(n []interop.PublicKey, committee bool) []byte { @@ -63,12 +69,7 @@ func Multiaddress(n []interop.PublicKey, committee bool) []byte { threshold = len(n)/2 + 1 } - keys := []interop.PublicKey{} - for _, key := range n { - keys = append(keys, key) - } - - return contract.CreateMultisigAccount(threshold, keys) + return contract.CreateMultisigAccount(threshold, n) } func keysToNodes(list []interop.PublicKey) []IRNode { diff --git a/common/update.go b/common/update.go index 7b9a054..8a865c1 100644 --- a/common/update.go +++ b/common/update.go @@ -1,22 +1,10 @@ package common import ( - "github.com/nspcc-dev/neo-go/pkg/interop" "github.com/nspcc-dev/neo-go/pkg/interop/runtime" - "github.com/nspcc-dev/neo-go/pkg/interop/storage" ) -const OwnerKey = "contractOwner" - -// HasUpdateAccess returns true if contract can be initialized, re-initialized -// or migrated. -func HasUpdateAccess(ctx storage.Context) bool { - data := storage.Get(ctx, OwnerKey) - if data == nil { // contract has not been initialized yet, return true - return true - } - - owner := data.(interop.Hash160) - - return runtime.CheckWitness(owner) +// HasUpdateAccess returns true if contract can be updated. +func HasUpdateAccess() bool { + return runtime.CheckWitness(CommitteeAddress()) }