From 6d0c5d110cb33930321856b7482475a94a8896f2 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Mon, 20 Sep 2021 18:41:46 +0300 Subject: [PATCH] [#107] Remove contract owner argument at contract deploy Contract owner entity does exist anymore. Contract migration now managed by side chain committee which are Alphabet nodes of the Inner Ring. Signed-off-by: Alex Vanin --- alphabet/alphabet_contract.go | 24 ++++++++---------------- audit/audit_contract.go | 17 ++++------------- balance/balance_contract.go | 18 +++++------------- container/container_contract.go | 20 ++++++-------------- neofs/neofs_contract.go | 24 +++++++++++------------- neofsid/neofsid_contract.go | 18 +++++------------- netmap/netmap_contract.go | 23 +++++++---------------- processing/processing_contract.go | 20 +++++++++----------- proxy/proxy_contract.go | 16 ++++------------ reputation/reputation_contract.go | 16 +++------------- 10 files changed, 62 insertions(+), 134 deletions(-) diff --git a/alphabet/alphabet_contract.go b/alphabet/alphabet_contract.go index e481ea4..3ca29b0 100644 --- a/alphabet/alphabet_contract.go +++ b/alphabet/alphabet_contract.go @@ -39,24 +39,18 @@ func _deploy(data interface{}, isUpdate bool) { args := data.([]interface{}) notaryDisabled := args[0].(bool) - owner := args[1].(interop.Hash160) - addrNetmap := args[2].(interop.Hash160) - addrProxy := args[3].(interop.Hash160) - name := args[4].(string) - index := args[5].(int) - total := args[6].(int) + addrNetmap := args[1].(interop.Hash160) + addrProxy := args[2].(interop.Hash160) + name := args[3].(string) + index := args[4].(int) + total := args[5].(int) ctx := storage.GetContext() - if !common.HasUpdateAccess(ctx) { - panic("only owner can reinitialize contract") - } - if len(addrNetmap) != 20 || !notaryDisabled && len(addrProxy) != 20 { panic("incorrect length of contract script hash") } - storage.Put(ctx, common.OwnerKey, owner) storage.Put(ctx, netmapKey, addrNetmap) storage.Put(ctx, proxyKey, addrProxy) storage.Put(ctx, nameKey, name) @@ -74,12 +68,10 @@ func _deploy(data interface{}, isUpdate bool) { } // Update method updates contract source code and manifest. Can be invoked -// only by contract owner. +// only by committee. func Update(script []byte, manifest []byte, data interface{}) { - ctx := storage.GetReadOnlyContext() - - if !common.HasUpdateAccess(ctx) { - panic("only owner can update contract") + if !common.HasUpdateAccess() { + panic("only committee can update contract") } contract.Call(interop.Hash160(management.Hash), "update", contract.All, script, manifest, data) diff --git a/audit/audit_contract.go b/audit/audit_contract.go index 868d6c5..f19b1ba 100644 --- a/audit/audit_contract.go +++ b/audit/audit_contract.go @@ -48,20 +48,14 @@ func _deploy(data interface{}, isUpdate bool) { args := data.([]interface{}) notaryDisabled := args[0].(bool) - owner := args[1].(interop.Hash160) - addrNetmap := args[2].(interop.Hash160) + addrNetmap := args[1].(interop.Hash160) ctx := storage.GetContext() - if !common.HasUpdateAccess(ctx) { - panic("only owner can reinitialize contract") - } - if len(addrNetmap) != 20 { panic("init: incorrect length of contract script hash") } - storage.Put(ctx, common.OwnerKey, owner) storage.Put(ctx, netmapContractKey, addrNetmap) // initialize the way to collect signatures @@ -74,12 +68,10 @@ func _deploy(data interface{}, isUpdate bool) { } // Update method updates contract source code and manifest. Can be invoked -// only by contract owner. +// only by committee. func Update(script []byte, manifest []byte, data interface{}) { - ctx := storage.GetReadOnlyContext() - - if !common.HasUpdateAccess(ctx) { - panic("only owner can update contract") + if !common.HasUpdateAccess() { + panic("only committee can update contract") } contract.Call(interop.Hash160(management.Hash), "update", contract.All, script, manifest, data) @@ -186,7 +178,6 @@ func list(it iterator.Iterator) [][]byte { ignore := [][]byte{ []byte(netmapContractKey), - []byte(common.OwnerKey), []byte(notaryDisabledKey), } diff --git a/balance/balance_contract.go b/balance/balance_contract.go index 58d96f0..4ecc5fd 100644 --- a/balance/balance_contract.go +++ b/balance/balance_contract.go @@ -65,21 +65,15 @@ func _deploy(data interface{}, isUpdate bool) { args := data.([]interface{}) notaryDisabled := args[0].(bool) - owner := args[1].(interop.Hash160) - addrNetmap := args[2].(interop.Hash160) - addrContainer := args[3].(interop.Hash160) + addrNetmap := args[1].(interop.Hash160) + addrContainer := args[2].(interop.Hash160) ctx := storage.GetContext() - if !common.HasUpdateAccess(ctx) { - panic("only owner can reinitialize contract") - } - if len(addrNetmap) != 20 || len(addrContainer) != 20 { panic("init: incorrect length of contract script hash") } - storage.Put(ctx, common.OwnerKey, owner) storage.Put(ctx, netmapContractKey, addrNetmap) storage.Put(ctx, containerContractKey, addrContainer) @@ -94,12 +88,10 @@ func _deploy(data interface{}, isUpdate bool) { } // Update method updates contract source code and manifest. Can be invoked -// only by contract owner. +// only by committee. func Update(script []byte, manifest []byte, data interface{}) { - ctx := storage.GetReadOnlyContext() - - if !common.HasUpdateAccess(ctx) { - panic("only owner can update contract") + if !common.HasUpdateAccess() { + panic("only committee can update contract") } contract.Call(interop.Hash160(management.Hash), "update", contract.All, script, manifest, data) diff --git a/container/container_contract.go b/container/container_contract.go index 4fcb3d4..d49ec21 100644 --- a/container/container_contract.go +++ b/container/container_contract.go @@ -70,20 +70,14 @@ func _deploy(data interface{}, isUpdate bool) { args := data.([]interface{}) notaryDisabled := args[0].(bool) - owner := args[1].(interop.Hash160) - addrNetmap := args[2].(interop.Hash160) - addrBalance := args[3].(interop.Hash160) - addrID := args[4].(interop.Hash160) - - if !common.HasUpdateAccess(ctx) { - panic("only owner can reinitialize contract") - } + addrNetmap := args[1].(interop.Hash160) + addrBalance := args[2].(interop.Hash160) + addrID := args[3].(interop.Hash160) if len(addrNetmap) != 20 || len(addrBalance) != 20 || len(addrID) != 20 { panic("incorrect length of contract script hash") } - storage.Put(ctx, common.OwnerKey, owner) storage.Put(ctx, netmapContractKey, addrNetmap) storage.Put(ctx, balanceContractKey, addrBalance) storage.Put(ctx, neofsIDContractKey, addrID) @@ -99,12 +93,10 @@ func _deploy(data interface{}, isUpdate bool) { } // Update method updates contract source code and manifest. Can be invoked -// only by contract owner. +// only by committee. func Update(script []byte, manifest []byte, data interface{}) { - ctx := storage.GetReadOnlyContext() - - if !common.HasUpdateAccess(ctx) { - panic("only owner can update contract") + if !common.HasUpdateAccess() { + panic("only committee can update contract") } contract.Call(interop.Hash160(management.Hash), "update", contract.All, script, manifest, data) diff --git a/neofs/neofs_contract.go b/neofs/neofs_contract.go index da3b268..54ad5f2 100644 --- a/neofs/neofs_contract.go +++ b/neofs/neofs_contract.go @@ -6,7 +6,9 @@ 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/gas" + "github.com/nspcc-dev/neo-go/pkg/interop/native/ledger" "github.com/nspcc-dev/neo-go/pkg/interop/native/management" + "github.com/nspcc-dev/neo-go/pkg/interop/native/roles" "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" @@ -51,17 +53,12 @@ func _deploy(data interface{}, isUpdate bool) { args := data.([]interface{}) notaryDisabled := args[0].(bool) - owner := args[1].(interop.Hash160) - addrProc := args[2].(interop.Hash160) - keys := args[3].([]interop.PublicKey) - config := args[4].([][]byte) + addrProc := args[1].(interop.Hash160) + keys := args[2].([]interop.PublicKey) + config := args[3].([][]byte) ctx := storage.GetContext() - if !common.HasUpdateAccess(ctx) { - panic("only owner can reinitialize contract") - } - var irList []common.IRNode if len(keys) == 0 { @@ -84,7 +81,6 @@ func _deploy(data interface{}, isUpdate bool) { common.SetSerialized(ctx, alphabetKey, irList) common.SetSerialized(ctx, candidatesKey, []common.IRNode{}) - storage.Put(ctx, common.OwnerKey, owner) storage.Put(ctx, processingContractKey, addrProc) // initialize the way to collect signatures @@ -110,12 +106,14 @@ func _deploy(data interface{}, isUpdate bool) { } // Update method updates contract source code and manifest. Can be invoked -// only by contract owner. +// only by side chain committee. func Update(script []byte, manifest []byte, data interface{}) { - ctx := storage.GetReadOnlyContext() + blockHeight := ledger.CurrentIndex() + alphabetKeys := roles.GetDesignatedByRole(roles.NeoFSAlphabet, uint32(blockHeight)) + alphabetCommittee := common.Multiaddress(alphabetKeys, true) - if !common.HasUpdateAccess(ctx) { - panic("only owner can update contract") + if !runtime.CheckWitness(alphabetCommittee) { + panic("only side chain committee can update contract") } contract.Call(interop.Hash160(management.Hash), "update", contract.All, script, manifest, data) diff --git a/neofsid/neofsid_contract.go b/neofsid/neofsid_contract.go index 71c551c..c9691ac 100644 --- a/neofsid/neofsid_contract.go +++ b/neofsid/neofsid_contract.go @@ -30,21 +30,15 @@ func _deploy(data interface{}, isUpdate bool) { args := data.([]interface{}) notaryDisabled := args[0].(bool) - owner := args[1].(interop.Hash160) - addrNetmap := args[2].(interop.Hash160) - addrContainer := args[3].(interop.Hash160) + addrNetmap := args[1].(interop.Hash160) + addrContainer := args[2].(interop.Hash160) ctx := storage.GetContext() - if !common.HasUpdateAccess(ctx) { - panic("only owner can reinitialize contract") - } - if len(addrNetmap) != 20 || len(addrContainer) != 20 { panic("init: incorrect length of contract script hash") } - storage.Put(ctx, common.OwnerKey, owner) storage.Put(ctx, netmapContractKey, addrNetmap) storage.Put(ctx, containerContractKey, addrContainer) @@ -59,12 +53,10 @@ func _deploy(data interface{}, isUpdate bool) { } // Update method updates contract source code and manifest. Can be invoked -// only by contract owner. +// only by committee. func Update(script []byte, manifest []byte, data interface{}) { - ctx := storage.GetReadOnlyContext() - - if !common.HasUpdateAccess(ctx) { - panic("only owner can update contract") + if !common.HasUpdateAccess() { + panic("only committee can update contract") } contract.Call(interop.Hash160(management.Hash), "update", contract.All, script, manifest, data) diff --git a/netmap/netmap_contract.go b/netmap/netmap_contract.go index 63b6caf..7be60c1 100644 --- a/netmap/netmap_contract.go +++ b/netmap/netmap_contract.go @@ -67,22 +67,15 @@ func _deploy(data interface{}, isUpdate bool) { args := data.([]interface{}) notaryDisabled := args[0].(bool) - owner := args[1].(interop.Hash160) - addrBalance := args[2].(interop.Hash160) - addrContainer := args[3].(interop.Hash160) - keys := args[4].([]interop.PublicKey) - config := args[5].([][]byte) - - if !common.HasUpdateAccess(ctx) { - panic("only owner can reinitialize contract") - } + addrBalance := args[1].(interop.Hash160) + addrContainer := args[2].(interop.Hash160) + keys := args[3].([]interop.PublicKey) + config := args[4].([][]byte) if len(addrBalance) != 20 || len(addrContainer) != 20 { panic("init: incorrect length of contract script hash") } - storage.Put(ctx, common.OwnerKey, owner) - // epoch number is a little endian int, it doesn't need to be serialized storage.Put(ctx, snapshotEpoch, 0) storage.Put(ctx, snapshotBlockKey, 0) @@ -124,12 +117,10 @@ func _deploy(data interface{}, isUpdate bool) { } // Update method updates contract source code and manifest. Can be invoked -// only by contract owner. +// only by committee. func Update(script []byte, manifest []byte, data interface{}) { - ctx := storage.GetReadOnlyContext() - - if !common.HasUpdateAccess(ctx) { - panic("only owner can update contract") + if !common.HasUpdateAccess() { + panic("only committee can update contract") } contract.Call(interop.Hash160(management.Hash), "update", contract.All, script, manifest, data) diff --git a/processing/processing_contract.go b/processing/processing_contract.go index 1621672..ede8bba 100644 --- a/processing/processing_contract.go +++ b/processing/processing_contract.go @@ -4,7 +4,9 @@ import ( "github.com/nspcc-dev/neo-go/pkg/interop" "github.com/nspcc-dev/neo-go/pkg/interop/contract" "github.com/nspcc-dev/neo-go/pkg/interop/native/gas" + "github.com/nspcc-dev/neo-go/pkg/interop/native/ledger" "github.com/nspcc-dev/neo-go/pkg/interop/native/management" + "github.com/nspcc-dev/neo-go/pkg/interop/native/roles" "github.com/nspcc-dev/neo-go/pkg/interop/runtime" "github.com/nspcc-dev/neo-go/pkg/interop/storage" "github.com/nspcc-dev/neofs-contract/common" @@ -30,32 +32,28 @@ func _deploy(data interface{}, isUpdate bool) { } arr := data.([]interop.Hash160) - owner := arr[0] - addrNeoFS := arr[1] + addrNeoFS := arr[0] ctx := storage.GetContext() - if !common.HasUpdateAccess(ctx) { - panic("only owner can reinitialize contract") - } - if len(addrNeoFS) != 20 { panic("init: incorrect length of contract script hash") } - storage.Put(ctx, common.OwnerKey, owner) storage.Put(ctx, neofsContractKey, addrNeoFS) runtime.Log("processing contract initialized") } // Update method updates contract source code and manifest. Can be invoked -// only by contract owner. +// only by side chain committee. func Update(script []byte, manifest []byte, data interface{}) { - ctx := storage.GetReadOnlyContext() + blockHeight := ledger.CurrentIndex() + alphabetKeys := roles.GetDesignatedByRole(roles.NeoFSAlphabet, uint32(blockHeight)) + alphabetCommittee := common.Multiaddress(alphabetKeys, true) - if !common.HasUpdateAccess(ctx) { - panic("only owner can update contract") + if !runtime.CheckWitness(alphabetCommittee) { + panic("only side chain committee can update contract") } contract.Call(interop.Hash160(management.Hash), "update", contract.All, script, manifest, data) diff --git a/proxy/proxy_contract.go b/proxy/proxy_contract.go index c260f07..e9cc50b 100644 --- a/proxy/proxy_contract.go +++ b/proxy/proxy_contract.go @@ -29,32 +29,24 @@ func _deploy(data interface{}, isUpdate bool) { } args := data.([]interface{}) - owner := args[0].(interop.Hash160) - addrNetmap := args[1].(interop.Hash160) + addrNetmap := args[0].(interop.Hash160) ctx := storage.GetContext() - if !common.HasUpdateAccess(ctx) { - panic("only owner can reinitialize contract") - } - if len(addrNetmap) != 20 { panic("init: incorrect length of contract script hash") } - storage.Put(ctx, common.OwnerKey, owner) storage.Put(ctx, netmapContractKey, addrNetmap) runtime.Log("proxy contract initialized") } // Update method updates contract source code and manifest. Can be invoked -// only by contract owner. +// only by committee. func Update(script []byte, manifest []byte, data interface{}) { - ctx := storage.GetReadOnlyContext() - - if !common.HasUpdateAccess(ctx) { - panic("only owner can update contract") + if !common.HasUpdateAccess() { + panic("only committee can update contract") } contract.Call(interop.Hash160(management.Hash), "update", contract.All, script, manifest, data) diff --git a/reputation/reputation_contract.go b/reputation/reputation_contract.go index 9078965..9fe7c25 100644 --- a/reputation/reputation_contract.go +++ b/reputation/reputation_contract.go @@ -22,16 +22,9 @@ func _deploy(data interface{}, isUpdate bool) { args := data.([]interface{}) notaryDisabled := args[0].(bool) - owner := args[1].(interop.Hash160) ctx := storage.GetContext() - if !common.HasUpdateAccess(ctx) { - panic("only owner can reinitialize contract") - } - - storage.Put(ctx, common.OwnerKey, owner) - // initialize the way to collect signatures storage.Put(ctx, notaryDisabledKey, notaryDisabled) if notaryDisabled { @@ -43,12 +36,10 @@ func _deploy(data interface{}, isUpdate bool) { } // Update method updates contract source code and manifest. Can be invoked -// only by contract owner. +// only by committee. func Update(script []byte, manifest []byte, data interface{}) { - ctx := storage.GetReadOnlyContext() - - if !common.HasUpdateAccess(ctx) { - panic("only owner can update contract") + if !common.HasUpdateAccess() { + panic("only committee can update contract") } contract.Call(interop.Hash160(management.Hash), "update", contract.All, script, manifest, data) @@ -136,7 +127,6 @@ func ListByEpoch(epoch int) [][]byte { var result [][]byte ignore := [][]byte{ - []byte(common.OwnerKey), []byte(notaryDisabledKey), }