caller must be validated exactly once
This commit is contained in:
parent
e65d293ba4
commit
5900d765fd
@ -74,7 +74,7 @@ func (ta *testActor) Exports() []interface{} {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ta *testActor) Constructor(rt runtime.Runtime, params *adt.EmptyValue) *adt.EmptyValue {
|
func (ta *testActor) Constructor(rt runtime.Runtime, params *adt.EmptyValue) *adt.EmptyValue {
|
||||||
|
rt.ValidateImmediateCallerAcceptAny()
|
||||||
rt.State().Create(&testActorState{11})
|
rt.State().Create(&testActorState{11})
|
||||||
fmt.Println("NEW ACTOR ADDRESS IS: ", rt.Message().Receiver())
|
fmt.Println("NEW ACTOR ADDRESS IS: ", rt.Message().Receiver())
|
||||||
|
|
||||||
@ -82,6 +82,7 @@ func (ta *testActor) Constructor(rt runtime.Runtime, params *adt.EmptyValue) *ad
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ta *testActor) TestMethod(rt runtime.Runtime, params *adt.EmptyValue) *adt.EmptyValue {
|
func (ta *testActor) TestMethod(rt runtime.Runtime, params *adt.EmptyValue) *adt.EmptyValue {
|
||||||
|
rt.ValidateImmediateCallerAcceptAny()
|
||||||
var st testActorState
|
var st testActorState
|
||||||
rt.State().Readonly(&st)
|
rt.State().Readonly(&st)
|
||||||
|
|
||||||
|
@ -53,6 +53,7 @@ type Runtime struct {
|
|||||||
internalExecutions []*types.ExecutionResult
|
internalExecutions []*types.ExecutionResult
|
||||||
numActorsCreated uint64
|
numActorsCreated uint64
|
||||||
allowInternal bool
|
allowInternal bool
|
||||||
|
callerValidated bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rt *Runtime) TotalFilCircSupply() abi.TokenAmount {
|
func (rt *Runtime) TotalFilCircSupply() abi.TokenAmount {
|
||||||
@ -141,6 +142,11 @@ func (rs *Runtime) shimCall(f func() interface{}) (rval []byte, aerr aerrors.Act
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
ret := f()
|
ret := f()
|
||||||
|
|
||||||
|
if !rs.callerValidated {
|
||||||
|
rs.Abortf(exitcode.SysErrorIllegalActor, "Caller MUST be validated during method execution")
|
||||||
|
}
|
||||||
|
|
||||||
switch ret := ret.(type) {
|
switch ret := ret.(type) {
|
||||||
case []byte:
|
case []byte:
|
||||||
return ret, nil
|
return ret, nil
|
||||||
@ -164,6 +170,7 @@ func (rs *Runtime) Message() vmr.Message {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (rs *Runtime) ValidateImmediateCallerAcceptAny() {
|
func (rs *Runtime) ValidateImmediateCallerAcceptAny() {
|
||||||
|
rs.abortIfAlreadyValidated()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -267,6 +274,7 @@ func (rs *Runtime) StartSpan(name string) vmr.TraceSpan {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (rt *Runtime) ValidateImmediateCallerIs(as ...address.Address) {
|
func (rt *Runtime) ValidateImmediateCallerIs(as ...address.Address) {
|
||||||
|
rt.abortIfAlreadyValidated()
|
||||||
imm := rt.Message().Caller()
|
imm := rt.Message().Caller()
|
||||||
|
|
||||||
for _, a := range as {
|
for _, a := range as {
|
||||||
@ -291,6 +299,7 @@ func (rs *Runtime) AbortStateMsg(msg string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (rt *Runtime) ValidateImmediateCallerType(ts ...cid.Cid) {
|
func (rt *Runtime) ValidateImmediateCallerType(ts ...cid.Cid) {
|
||||||
|
rt.abortIfAlreadyValidated()
|
||||||
callerCid, ok := rt.GetActorCodeCID(rt.Message().Caller())
|
callerCid, ok := rt.GetActorCodeCID(rt.Message().Caller())
|
||||||
if !ok {
|
if !ok {
|
||||||
panic(aerrors.Fatalf("failed to lookup code cid for caller"))
|
panic(aerrors.Fatalf("failed to lookup code cid for caller"))
|
||||||
@ -494,3 +503,10 @@ func (rt *Runtime) Pricelist() Pricelist {
|
|||||||
func (rt *Runtime) incrementNumActorsCreated() {
|
func (rt *Runtime) incrementNumActorsCreated() {
|
||||||
rt.numActorsCreated++
|
rt.numActorsCreated++
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (rt *Runtime) abortIfAlreadyValidated() {
|
||||||
|
if rt.callerValidated {
|
||||||
|
rt.Abortf(exitcode.SysErrorIllegalActor, "Method must validate caller identity exactly once")
|
||||||
|
}
|
||||||
|
rt.callerValidated = true
|
||||||
|
}
|
||||||
|
@ -101,6 +101,7 @@ func (vm *VM) makeRuntime(ctx context.Context, msg *types.Message, origin addres
|
|||||||
numActorsCreated: nac,
|
numActorsCreated: nac,
|
||||||
pricelist: PricelistByEpoch(vm.blockHeight),
|
pricelist: PricelistByEpoch(vm.blockHeight),
|
||||||
allowInternal: true,
|
allowInternal: true,
|
||||||
|
callerValidated: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
rt.cst = &cbor.BasicIpldStore{
|
rt.cst = &cbor.BasicIpldStore{
|
||||||
|
Loading…
Reference in New Issue
Block a user