From 0ef906fb03d31ea94a3b333aceeb0fca07184efb Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Tue, 19 Oct 2021 10:59:40 +0300 Subject: [PATCH] [#150] container: allow only alphabet calls in `Delete` Signed-off-by: Evgenii Stratonikov --- container/container_contract.go | 30 +++++++++++------------------- tests/container_test.go | 28 ++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 19 deletions(-) diff --git a/container/container_contract.go b/container/container_contract.go index 4ce5776..37112ac 100644 --- a/container/container_contract.go +++ b/container/container_contract.go @@ -295,27 +295,14 @@ func Delete(containerID []byte, signature interop.Signature, token []byte) { return } - var ( // for invocation collection without notary - alphabet []common.IRNode - nodeKey []byte - alphabetCall bool - ) - if notaryDisabled { - alphabet = common.AlphabetNodes() - nodeKey = common.InnerRingInvoker(alphabet) - alphabetCall = len(nodeKey) != 0 - } else { - multiaddr := common.AlphabetAddress() - alphabetCall = runtime.CheckWitness(multiaddr) - } + alphabet := common.AlphabetNodes() + nodeKey := common.InnerRingInvoker(alphabet) + if len(nodeKey) == 0 { + runtime.Notify("containerDelete", containerID, signature, token) + return + } - if !alphabetCall { - runtime.Notify("containerDelete", containerID, signature, token) - return - } - - if notaryDisabled { threshold := len(alphabet)*2/3 + 1 id := common.InvokeID([]interface{}{containerID, signature}, []byte("delete")) @@ -325,6 +312,11 @@ func Delete(containerID []byte, signature interop.Signature, token []byte) { } common.RemoveVotes(ctx, id) + } else { + multiaddr := common.AlphabetAddress() + if !runtime.CheckWitness(multiaddr) { + panic("delete: alphabet witness check failed") + } } key := append([]byte(nnsHasAliasKey), containerID...) diff --git a/tests/container_test.go b/tests/container_test.go index dcce848..2b77ce7 100644 --- a/tests/container_test.go +++ b/tests/container_test.go @@ -144,3 +144,31 @@ func TestContainerPut(t *testing.T) { }) }) } + +func TestContainerDelete(t *testing.T) { + bc := NewChain(t) + h, balanceHash := prepareContainerContract(t, bc) + + acc := NewAccount(t, bc) + c := dummyContainer(acc) + + balanceMint(t, bc, acc, balanceHash, containerFee*1, []byte{}) + tx := PrepareInvoke(t, bc, CommitteeAcc, h, "put", + c.value, c.sig, c.pub, c.token) + AddBlockCheckHalt(t, bc, tx) + + tx = PrepareInvoke(t, bc, acc, h, "delete", c.id[:], c.sig, c.token) + AddBlock(t, bc, tx) + CheckFault(t, bc, tx.Hash(), "delete: alphabet witness check failed") + + tx = PrepareInvoke(t, bc, CommitteeAcc, h, "delete", c.id[:], c.sig, c.token) + AddBlockCheckHalt(t, bc, tx) + + tx = PrepareInvoke(t, bc, acc, h, "get", c.id[:]) + CheckTestInvoke(t, bc, tx, stackitem.NewStruct([]stackitem.Item{ + stackitem.NewBuffer([]byte{}), + stackitem.NewBuffer([]byte{}), + stackitem.NewBuffer([]byte{}), + stackitem.NewBuffer([]byte{}), + })) +}