Panic if runtime's Message has non-ID caller or receiver

This commit is contained in:
Aayush Rajasekaran 2020-09-23 22:45:53 -04:00
parent b71b743420
commit 757aa1039f
2 changed files with 31 additions and 7 deletions

View File

@ -27,8 +27,30 @@ import (
"github.com/filecoin-project/lotus/chain/types"
)
type Message struct {
msg types.Message
}
func (m *Message) Caller() address.Address {
if m.msg.From.Protocol() != address.ID {
panic("runtime message has a non-ID caller")
}
return m.msg.From
}
func (m *Message) Receiver() address.Address {
if m.msg.To != address.Undef && m.msg.To.Protocol() != address.ID {
panic("runtime message has a non-ID receiver")
}
return m.msg.To
}
func (m *Message) ValueReceived() abi.TokenAmount {
return m.msg.Value
}
type Runtime struct {
types.Message
Message
rt0.Syscalls
ctx context.Context

View File

@ -134,7 +134,7 @@ func (vm *VM) makeRuntime(ctx context.Context, msg *types.Message, origin addres
resT, _ := rt.ResolveAddress(msg.To)
// may be set to undef if recipient doesn't exist yet
vmm.To = resT
rt.Message = vmm
rt.Message = Message{msg: vmm}
return rt
}
@ -265,13 +265,15 @@ func (vm *VM) send(ctx context.Context, msg *types.Message, parent *Runtime,
return nil, aerrors.Wrapf(err, "could not create account")
}
toActor = a
nmsg := types.Message{
To: aid,
From: rt.vmsg.Caller(),
Value: rt.vmsg.ValueReceived(),
nmsg := Message{
msg: types.Message{
To: aid,
From: rt.Message.Caller(),
Value: rt.Message.ValueReceived(),
},
}
rt.vmsg = &nmsg
rt.Message = nmsg
} else {
return nil, aerrors.Escalate(err, "getting actor")
}