From ec0d0a51dbaa14867ee79a746e647bec17d5daa3 Mon Sep 17 00:00:00 2001 From: Jeromy Date: Tue, 24 Mar 2020 13:09:04 -0700 Subject: [PATCH] chain validation nil return values should be []byte{} --- chain/validation/applier.go | 13 +++++++++++-- chain/vm/invoker.go | 1 - go.mod | 2 +- go.sum | 2 ++ 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/chain/validation/applier.go b/chain/validation/applier.go index b13ac68f8..d5f5c39bc 100644 --- a/chain/validation/applier.go +++ b/chain/validation/applier.go @@ -46,6 +46,11 @@ func (a *Applier) ApplyMessage(eCtx *vtypes.ExecutionContext, state vstate.VMWra return vtypes.MessageReceipt{}, err } + rval := ret.Return + if rval == nil { + rval = []byte{} + } + st.stateRoot, err = lotusVM.Flush(ctx) if err != nil { return vtypes.MessageReceipt{}, err @@ -53,7 +58,7 @@ func (a *Applier) ApplyMessage(eCtx *vtypes.ExecutionContext, state vstate.VMWra mr := vtypes.MessageReceipt{ ExitCode: exitcode.ExitCode(ret.ExitCode), - ReturnValue: ret.Return, + ReturnValue: rval, GasUsed: big.NewInt(ret.GasUsed), } @@ -88,9 +93,13 @@ func (a *Applier) ApplyTipSetMessages(state vstate.VMWrapper, blocks []vtypes.Bl if msg.From == builtin.SystemActorAddr { return nil // ignore reward and cron calls } + rval := ret.Return + if rval == nil { + rval = []byte{} // chain validation tests expect empty arrays to not be nil... + } receipts = append(receipts, vtypes.MessageReceipt{ ExitCode: exitcode.ExitCode(ret.ExitCode), - ReturnValue: ret.Return, + ReturnValue: rval, GasUsed: big.NewInt(ret.GasUsed), }) diff --git a/chain/vm/invoker.go b/chain/vm/invoker.go index e5716740f..4d2b475f8 100644 --- a/chain/vm/invoker.go +++ b/chain/vm/invoker.go @@ -127,7 +127,6 @@ func (*invoker) transform(instance Invokee) (nativeCode, error) { o0 := t.Out(0) if !o0.Implements(reflect.TypeOf((*cbg.CBORMarshaler)(nil)).Elem()) { return nil, newErr("output needs to implement cgb.CBORMarshaler") - } } code := make(nativeCode, len(exports)) diff --git a/go.mod b/go.mod index f6b62393d..687aad074 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/coreos/go-systemd/v22 v22.0.0 github.com/davidlazar/go-crypto v0.0.0-20190912175916-7055855a373f // indirect github.com/docker/go-units v0.4.0 - github.com/filecoin-project/chain-validation v0.0.6-0.20200324001434-7c1ecd76e3eb + github.com/filecoin-project/chain-validation v0.0.6-0.20200324185232-f581621b7fbf github.com/filecoin-project/filecoin-ffi v0.0.0-20200304181354-4446ff8a1bb9 github.com/filecoin-project/go-address v0.0.2-0.20200218010043-eb9bb40ed5be github.com/filecoin-project/go-amt-ipld/v2 v2.0.1-0.20200131012142-05d80eeccc5e diff --git a/go.sum b/go.sum index 06866109a..48f4e62f9 100644 --- a/go.sum +++ b/go.sum @@ -99,6 +99,8 @@ github.com/fatih/color v1.8.0 h1:5bzFgL+oy7JITMTxUPJ00n7VxmYd/PdMp5mHFX40/RY= github.com/fatih/color v1.8.0/go.mod h1:3l45GVGkyrnYNl9HoIjnp2NnNWvh6hLAqD8yTfGjnw8= github.com/filecoin-project/chain-validation v0.0.6-0.20200324001434-7c1ecd76e3eb h1:tynvU1AYRXYAzRrMX6VZGYgUg3+/lweulbAyeZqET/I= github.com/filecoin-project/chain-validation v0.0.6-0.20200324001434-7c1ecd76e3eb/go.mod h1:YTLxUr6gOZpkUaXzLe7OZ4s1dpfJGp2FY/J2/K5DJqc= +github.com/filecoin-project/chain-validation v0.0.6-0.20200324185232-f581621b7fbf h1:GiCNQc9LuIrH2buA2T07FiM2WEMgUllJ/ET28cOQY7E= +github.com/filecoin-project/chain-validation v0.0.6-0.20200324185232-f581621b7fbf/go.mod h1:YTLxUr6gOZpkUaXzLe7OZ4s1dpfJGp2FY/J2/K5DJqc= github.com/filecoin-project/go-address v0.0.0-20200107215422-da8eea2842b5/go.mod h1:SAOwJoakQ8EPjwNIsiakIQKsoKdkcbx8U3IapgCg9R0= github.com/filecoin-project/go-address v0.0.2-0.20200218010043-eb9bb40ed5be h1:TooKBwR/g8jG0hZ3lqe9S5sy2vTUcLOZLlz3M5wGn2E= github.com/filecoin-project/go-address v0.0.2-0.20200218010043-eb9bb40ed5be/go.mod h1:SAOwJoakQ8EPjwNIsiakIQKsoKdkcbx8U3IapgCg9R0=