From c6a9d5a444ac7dd4b30ac30735fa40189e582a12 Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Sun, 6 Sep 2020 03:48:45 -0400 Subject: [PATCH] Bugfix: Runtime's Receiver() should only return ID addresses --- chain/vm/mkactor.go | 18 +++++++++--------- chain/vm/vm.go | 12 +++++++++++- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/chain/vm/mkactor.go b/chain/vm/mkactor.go index ef4382df169..77ee09a4fdb 100644 --- a/chain/vm/mkactor.go +++ b/chain/vm/mkactor.go @@ -29,41 +29,41 @@ func init() { var EmptyObjectCid cid.Cid // TryCreateAccountActor creates account actors from only BLS/SECP256K1 addresses. -func TryCreateAccountActor(rt *Runtime, addr address.Address) (*types.Actor, aerrors.ActorError) { +func TryCreateAccountActor(rt *Runtime, addr address.Address) (*types.Actor, address.Address, aerrors.ActorError) { if err := rt.chargeGasSafe(PricelistByEpoch(rt.height).OnCreateActor()); err != nil { - return nil, err + return nil, address.Undef, err } addrID, err := rt.state.RegisterNewAddress(addr) if err != nil { - return nil, aerrors.Escalate(err, "registering actor address") + return nil, address.Undef, aerrors.Escalate(err, "registering actor address") } act, aerr := makeActor(addr) if aerr != nil { - return nil, aerr + return nil, address.Undef, aerr } if err := rt.state.SetActor(addrID, act); err != nil { - return nil, aerrors.Escalate(err, "creating new actor failed") + return nil, address.Undef, aerrors.Escalate(err, "creating new actor failed") } p, err := actors.SerializeParams(&addr) if err != nil { - return nil, aerrors.Escalate(err, "couldn't serialize params for actor construction") + return nil, address.Undef, aerrors.Escalate(err, "couldn't serialize params for actor construction") } // call constructor on account _, aerr = rt.internalSend(builtin.SystemActorAddr, addrID, builtin.MethodsAccount.Constructor, big.Zero(), p) if aerr != nil { - return nil, aerrors.Wrap(aerr, "failed to invoke account constructor") + return nil, address.Undef, aerrors.Wrap(aerr, "failed to invoke account constructor") } act, err = rt.state.GetActor(addrID) if err != nil { - return nil, aerrors.Escalate(err, "loading newly created actor failed") + return nil, address.Undef, aerrors.Escalate(err, "loading newly created actor failed") } - return act, nil + return act, addrID, nil } func makeActor(addr address.Address) (*types.Actor, aerrors.ActorError) { diff --git a/chain/vm/vm.go b/chain/vm/vm.go index f51cbff2938..cf730745d53 100644 --- a/chain/vm/vm.go +++ b/chain/vm/vm.go @@ -126,6 +126,9 @@ func (vm *VM) makeRuntime(ctx context.Context, msg *types.Message, origin addres rt.Abortf(exitcode.SysErrInvalidReceiver, "resolve msg.From address failed") } vmm.From = resF + resT, _ := rt.ResolveAddress(msg.To) + // may be set to undef if recipient doesn't exist yet + vmm.To = resT rt.vmsg = &vmm return rt @@ -240,11 +243,18 @@ func (vm *VM) send(ctx context.Context, msg *types.Message, parent *Runtime, toActor, err := st.GetActor(msg.To) if err != nil { if xerrors.Is(err, types.ErrActorNotFound) { - a, err := TryCreateAccountActor(rt, msg.To) + a, aid, err := TryCreateAccountActor(rt, msg.To) if err != nil { return nil, aerrors.Wrapf(err, "could not create account") } toActor = a + nmsg := types.Message{ + To: aid, + From: rt.vmsg.Caller(), + Value: rt.vmsg.ValueReceived(), + } + + rt.vmsg = &nmsg } else { return nil, aerrors.Escalate(err, "getting actor") }