Skip to content

Commit

Permalink
Bugfix: Runtime's Receiver() should only return ID addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
arajasek committed Sep 6, 2020
1 parent 6bdd433 commit c6a9d5a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
18 changes: 9 additions & 9 deletions chain/vm/mkactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
12 changes: 11 additions & 1 deletion chain/vm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
}
Expand Down

0 comments on commit c6a9d5a

Please sign in to comment.