diff --git a/core/vm/eof.go b/core/vm/eof.go index 48414716a1..51bf2a8ef0 100644 --- a/core/vm/eof.go +++ b/core/vm/eof.go @@ -338,7 +338,7 @@ func (c *Container) validateSubContainer(jt *JumpTable, isInitCode bool, refBy i code = c.Code[index] ) if _, ok := visited[index]; !ok { - res, err := validateCode(code, index, c, jt, isInitCode) + res, err := validateCode(code, index, c, jt, isInitCode || refBy == RefByEOFCreate) if err != nil { return err } diff --git a/core/vm/validate.go b/core/vm/validate.go index 7cb0b0600a..434751b171 100644 --- a/core/vm/validate.go +++ b/core/vm/validate.go @@ -127,6 +127,9 @@ func validateCode(code []byte, section int, container *Container, jt *JumpTable, return nil, fmt.Errorf("%w: arg %d, last %d, pos %d", ErrInvalidDataloadNArgument, arg, len(container.Data), i) } case op == RETURNCONTRACT: + if !isInitCode { + return nil, ErrIncompatibleContainerKind + } arg := int(code[i+1]) if arg >= len(container.ContainerSections) { return nil, fmt.Errorf("%w: arg %d, last %d, pos %d", ErrUnreachableCode, arg, len(container.ContainerSections), i)