From 7ba5d50fd417d57b290479e950dffbbb44a88e5d Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Wed, 10 Mar 2021 17:01:57 +0300 Subject: [PATCH] [#59] proxy: Check committee address in Verify function For committee operations in side chain we can't use 5\7 multi address, instead we should use 4\7 for this case. Signed-off-by: Alex Vanin --- common/ir.go | 15 +++++++++++++++ netmap/config.yml | 2 +- netmap/netmap_contract.go | 12 ++++++++++-- proxy/proxy_contract.go | 7 ++++++- 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/common/ir.go b/common/ir.go index acb0877..f621fd7 100644 --- a/common/ir.go +++ b/common/ir.go @@ -10,6 +10,7 @@ import ( const ( irListMethod = "innerRingList" multiaddrMethod = "multiaddress" + committeeMethod = "committee" ) type IRNode struct { @@ -56,3 +57,17 @@ func InnerRingMultiAddressViaStorage(ctx storage.Context, key interface{}) []byt func InnerRingMultiAddress(sc interop.Hash160) []byte { return contract.Call(sc, multiaddrMethod, contract.ReadOnly).([]byte) } + +// CommitteeMultiAddressViaStorage returns multiaddress of committee public +// keys by invoking netmap contract, which scripthash stored in the contract +// storage by the key `key`. +func CommitteeMultiAddressViaStorage(ctx storage.Context, key interface{}) []byte { + sc := storage.Get(ctx, key).(interop.Hash160) + return CommitteeMultiAddress(sc) +} + +// CommitteeMultiAddress returns multiaddress of committee public keys by +// invoking netmap contract. +func CommitteeMultiAddress(sc interop.Hash160) []byte { + return contract.Call(sc, committeeMethod, contract.ReadOnly).([]byte) +} diff --git a/netmap/config.yml b/netmap/config.yml index 085c003..a107eb6 100644 --- a/netmap/config.yml +++ b/netmap/config.yml @@ -1,5 +1,5 @@ name: "NeoFS Netmap" -safemethods: ["innerRingList", "multiaddress", "epoch", "netmap", "snapshot", "snapshotByEpoch", "config", "listConfig", "version"] +safemethods: ["innerRingList", "multiaddress", "committee", "epoch", "netmap", "snapshot", "snapshotByEpoch", "config", "listConfig", "version"] events: - name: AddPeer parameters: diff --git a/netmap/netmap_contract.go b/netmap/netmap_contract.go index c4fa5b5..293834f 100644 --- a/netmap/netmap_contract.go +++ b/netmap/netmap_contract.go @@ -103,7 +103,12 @@ func InnerRingList() []common.IRNode { func Multiaddress() []byte { ctx := storage.GetReadOnlyContext() - return multiaddress(getIRNodes(ctx)) + return multiaddress(getIRNodes(ctx), false) +} + +func Committee() []byte { + ctx := storage.GetReadOnlyContext() + return multiaddress(getIRNodes(ctx), true) } func UpdateInnerRing(keys []interop.PublicKey) bool { @@ -420,8 +425,11 @@ func setConfig(ctx storage.Context, key, val interface{}) { storage.Put(ctx, storageKey, val) } -func multiaddress(n []common.IRNode) []byte { +func multiaddress(n []common.IRNode, committee bool) []byte { threshold := len(n)/3*2 + 1 + if committee { + threshold = len(n)/2 + 1 + } var result = []byte{0x10 + uint8(threshold)} // m value = 5 diff --git a/proxy/proxy_contract.go b/proxy/proxy_contract.go index a6d8695..c1c626b 100644 --- a/proxy/proxy_contract.go +++ b/proxy/proxy_contract.go @@ -57,7 +57,12 @@ func Verify() bool { ctx := storage.GetReadOnlyContext() sig := common.InnerRingMultiAddressViaStorage(ctx, netmapContractKey) - return runtime.CheckWitness(sig) + if !runtime.CheckWitness(sig) { + sig = common.CommitteeMultiAddressViaStorage(ctx, netmapContractKey) + return runtime.CheckWitness(sig) + } + + return true } func Version() int {