diff --git a/alphabet/alphabet_contract.go b/alphabet/alphabet_contract.go index b8bdd12..72aebe8 100644 --- a/alphabet/alphabet_contract.go +++ b/alphabet/alphabet_contract.go @@ -178,8 +178,7 @@ func Vote(epoch int, candidates []interop.PublicKey) { index := index(ctx) name := name(ctx) - multiaddr := common.AlphabetAddress() - common.CheckAlphabetWitness(multiaddr) + common.CheckAlphabetWitness() curEpoch := currentEpoch(ctx) if epoch != curEpoch { diff --git a/balance/balance_contract.go b/balance/balance_contract.go index 8993585..3859c6e 100644 --- a/balance/balance_contract.go +++ b/balance/balance_contract.go @@ -144,8 +144,7 @@ func Transfer(from, to interop.Hash160, amount int, data interface{}) bool { func TransferX(from, to interop.Hash160, amount int, details []byte) { ctx := storage.GetContext() - multiaddr := common.AlphabetAddress() - common.CheckAlphabetWitness(multiaddr) + common.CheckAlphabetWitness() result := token.transfer(ctx, from, to, amount, true, details) if !result { @@ -166,8 +165,7 @@ func TransferX(from, to interop.Hash160, amount int, details []byte) { func Lock(txDetails []byte, from, to interop.Hash160, amount, until int) { ctx := storage.GetContext() - multiaddr := common.AlphabetAddress() - common.CheckAlphabetWitness(multiaddr) + common.CheckAlphabetWitness() details := common.LockTransferDetails(txDetails) @@ -197,8 +195,7 @@ func Lock(txDetails []byte, from, to interop.Hash160, amount, until int) { func NewEpoch(epochNum int) { ctx := storage.GetContext() - multiaddr := common.AlphabetAddress() - common.CheckAlphabetWitness(multiaddr) + common.CheckAlphabetWitness() it := storage.Find(ctx, []byte{}, storage.KeysOnly) for iterator.Next(it) { @@ -232,8 +229,7 @@ func NewEpoch(epochNum int) { func Mint(to interop.Hash160, amount int, txDetails []byte) { ctx := storage.GetContext() - multiaddr := common.AlphabetAddress() - common.CheckAlphabetWitness(multiaddr) + common.CheckAlphabetWitness() details := common.MintTransferDetails(txDetails) @@ -263,8 +259,7 @@ func Mint(to interop.Hash160, amount int, txDetails []byte) { func Burn(from interop.Hash160, amount int, txDetails []byte) { ctx := storage.GetContext() - multiaddr := common.AlphabetAddress() - common.CheckAlphabetWitness(multiaddr) + common.CheckAlphabetWitness() details := common.BurnTransferDetails(txDetails) diff --git a/common/witness.go b/common/witness.go index 9169b0b..ba2b9c6 100644 --- a/common/witness.go +++ b/common/witness.go @@ -16,8 +16,8 @@ var ( // CheckAlphabetWitness checks witness of the passed caller. // It panics with ErrAlphabetWitnessFailed message on fail. -func CheckAlphabetWitness(caller []byte) { - checkWitnessWithPanic(caller, ErrAlphabetWitnessFailed) +func CheckAlphabetWitness() { + checkWitnessWithPanic(AlphabetAddress(), ErrAlphabetWitnessFailed) } // CheckOwnerWitness checks witness of the passed caller. diff --git a/container/container_contract.go b/container/container_contract.go index 03cb65a..9a600d1 100644 --- a/container/container_contract.go +++ b/container/container_contract.go @@ -234,8 +234,7 @@ func PutNamed(container []byte, signature interop.Signature, panic("insufficient balance to create container") } - multiaddr := common.AlphabetAddress() - common.CheckAlphabetWitness(multiaddr) + common.CheckAlphabetWitness() // todo: check if new container with unique container id details := common.ContainerFeeTransferDetails(containerID) @@ -320,8 +319,7 @@ func Delete(containerID []byte, signature interop.Signature, token []byte) { return } - multiaddr := common.AlphabetAddress() - common.CheckAlphabetWitness(multiaddr) + common.CheckAlphabetWitness() key := append([]byte(nnsHasAliasKey), containerID...) domain := storage.Get(ctx, key).(string) @@ -433,8 +431,7 @@ func SetEACL(eACL []byte, signature interop.Signature, publicKey interop.PublicK panic(NotFoundError) } - multiaddr := common.AlphabetAddress() - common.CheckAlphabetWitness(multiaddr) + common.CheckAlphabetWitness() rule := ExtendedACL{ value: eACL, @@ -567,8 +564,7 @@ func IterateContainerSizes(epoch int) iterator.Iterator { func NewEpoch(epochNum int) { ctx := storage.GetContext() - multiaddr := common.AlphabetAddress() - common.CheckAlphabetWitness(multiaddr) + common.CheckAlphabetWitness() cleanupContainers(ctx, epochNum) } @@ -576,8 +572,7 @@ func NewEpoch(epochNum int) { // StartContainerEstimation method produces StartEstimation notification. // It can be invoked only by Alphabet nodes of the Inner Ring. func StartContainerEstimation(epoch int) { - multiaddr := common.AlphabetAddress() - common.CheckAlphabetWitness(multiaddr) + common.CheckAlphabetWitness() runtime.Notify("StartEstimation", epoch) runtime.Log("notification has been produced") @@ -586,8 +581,7 @@ func StartContainerEstimation(epoch int) { // StopContainerEstimation method produces StopEstimation notification. // It can be invoked only by Alphabet nodes of the Inner Ring. func StopContainerEstimation(epoch int) { - multiaddr := common.AlphabetAddress() - common.CheckAlphabetWitness(multiaddr) + common.CheckAlphabetWitness() runtime.Notify("StopEstimation", epoch) runtime.Log("notification has been produced") diff --git a/frostfs/frostfs_contract.go b/frostfs/frostfs_contract.go index e7ea5ab..f902d30 100644 --- a/frostfs/frostfs_contract.go +++ b/frostfs/frostfs_contract.go @@ -105,7 +105,9 @@ func Update(script []byte, manifest []byte, data interface{}) { alphabetKeys := roles.GetDesignatedByRole(roles.NeoFSAlphabet, uint32(blockHeight+1)) alphabetCommittee := common.Multiaddress(alphabetKeys, true) - common.CheckAlphabetWitness(alphabetCommittee) + if !runtime.CheckWitness(alphabetCommittee) { + panic(common.ErrAlphabetWitnessFailed) + } contract.Call(interop.Hash160(management.Hash), "update", contract.All, script, manifest, common.AppendVersion(data)) @@ -265,8 +267,7 @@ func Withdraw(user interop.Hash160, amount int) { // // This method produces Cheque notification to burn assets in sidechain. func Cheque(id []byte, user interop.Hash160, amount int, lockAcc []byte) { - multiaddr := AlphabetAddress() - common.CheckAlphabetWitness(multiaddr) + common.CheckAlphabetWitness() from := runtime.GetExecutingScriptHash() @@ -331,8 +332,7 @@ func Config(key []byte) interface{} { func SetConfig(id, key, val []byte) { ctx := storage.GetContext() - multiaddr := AlphabetAddress() - common.CheckAlphabetWitness(multiaddr) + common.CheckAlphabetWitness() setConfig(ctx, key, val) diff --git a/frostfsid/frostfsid_contract.go b/frostfsid/frostfsid_contract.go index 79fb0d5..58d6fbc 100644 --- a/frostfsid/frostfsid_contract.go +++ b/frostfsid/frostfsid_contract.go @@ -86,8 +86,7 @@ func AddKey(owner []byte, keys []interop.PublicKey) { ctx := storage.GetContext() - multiaddr := common.AlphabetAddress() - common.CheckAlphabetWitness(multiaddr) + common.CheckAlphabetWitness() ownerKey := append([]byte{ownerKeysPrefix}, owner...) for i := range keys { diff --git a/netmap/netmap_contract.go b/netmap/netmap_contract.go index 8601093..150c461 100644 --- a/netmap/netmap_contract.go +++ b/netmap/netmap_contract.go @@ -140,7 +140,7 @@ func Update(script []byte, manifest []byte, data interface{}) { func AddPeerIR(nodeInfo []byte) { ctx := storage.GetContext() - common.CheckAlphabetWitness(common.AlphabetAddress()) + common.CheckAlphabetWitness() publicKey := nodeInfo[2:35] // V2 format: offset:2, len:33 @@ -213,7 +213,7 @@ func UpdateState(state NodeState, publicKey interop.PublicKey) { ctx := storage.GetContext() common.CheckWitness(publicKey) - common.CheckAlphabetWitness(common.AlphabetAddress()) + common.CheckAlphabetWitness() updateCandidateState(ctx, publicKey, state) } @@ -227,7 +227,7 @@ func UpdateState(state NodeState, publicKey interop.PublicKey) { func UpdateStateIR(state NodeState, publicKey interop.PublicKey) { ctx := storage.GetContext() - common.CheckAlphabetWitness(common.AlphabetAddress()) + common.CheckAlphabetWitness() updateCandidateState(ctx, publicKey, state) } @@ -244,8 +244,7 @@ func UpdateStateIR(state NodeState, publicKey interop.PublicKey) { func NewEpoch(epochNum int) { ctx := storage.GetContext() - multiaddr := common.AlphabetAddress() - common.CheckAlphabetWitness(multiaddr) + common.CheckAlphabetWitness() currentEpoch := storage.Get(ctx, snapshotEpoch).(int) if epochNum <= currentEpoch { @@ -343,7 +342,7 @@ func getSnapshotCount(ctx storage.Context) int { // // Count MUST NOT be negative. func UpdateSnapshotCount(count int) { - common.CheckAlphabetWitness(common.AlphabetAddress()) + common.CheckAlphabetWitness() if count < 0 { panic("count must be positive") } @@ -443,8 +442,7 @@ func Config(key []byte) interface{} { func SetConfig(id, key, val []byte) { ctx := storage.GetContext() - multiaddr := common.AlphabetAddress() - common.CheckAlphabetWitness(multiaddr) + common.CheckAlphabetWitness() setConfig(ctx, key, val) diff --git a/subnet/subnet_contract.go b/subnet/subnet_contract.go index fdd3f74..c7bbd32 100644 --- a/subnet/subnet_contract.go +++ b/subnet/subnet_contract.go @@ -88,8 +88,7 @@ func Put(id []byte, ownerKey interop.PublicKey, info []byte) { common.CheckOwnerWitness(ownerKey) - multiaddr := common.AlphabetAddress() - common.CheckAlphabetWitness(multiaddr) + common.CheckAlphabetWitness() storage.Put(ctx, stKey, ownerKey) stKey[0] = infoPrefix