From dff88b63b2b46300c2efbf5dc44f271fba1a4ef1 Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Sun, 8 Nov 2020 19:58:10 -0500 Subject: [PATCH] fix: guard against self beneficiary when deleting actor --- chain/vm/runtime.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/chain/vm/runtime.go b/chain/vm/runtime.go index 5dc175726..c537441e8 100644 --- a/chain/vm/runtime.go +++ b/chain/vm/runtime.go @@ -266,7 +266,7 @@ func (rt *Runtime) CreateActor(codeID cid.Cid, address address.Address) { // DeleteActor deletes the executing actor from the state tree, transferring // any balance to beneficiary. -// Aborts if the beneficiary does not exist. +// Aborts if the beneficiary does not exist or is the calling actor. // May only be called by the actor itself. func (rt *Runtime) DeleteActor(beneficiary address.Address) { rt.chargeGas(rt.Pricelist().OnDeleteActor()) @@ -278,6 +278,9 @@ func (rt *Runtime) DeleteActor(beneficiary address.Address) { panic(aerrors.Fatalf("failed to get actor: %s", err)) } if !act.Balance.IsZero() { + if beneficiary == rt.Receiver() && rt.NetworkVersion() >= network.Version7 { + rt.Abortf(exitcode.SysErrorIllegalArgument, "benefactor cannot be beneficiary") + } // Transfer the executing actor's balance to the beneficiary if err := rt.vm.transfer(rt.Receiver(), beneficiary, act.Balance); err != nil { panic(aerrors.Fatalf("failed to transfer balance to beneficiary actor: %s", err))