[#150] container: allow only alphabet calls in `Delete`

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
enable-notary-in-public-chains
Evgenii Stratonikov 2021-10-19 10:59:40 +03:00 committed by Alex Vanin
parent e5c5cc30c0
commit 0ef906fb03
2 changed files with 39 additions and 19 deletions

View File

@ -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...)

View File

@ -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{}),
}))
}