From 9edd35cefef85c784de6f069e99f553b85a68bef Mon Sep 17 00:00:00 2001 From: Danno Ferrin Date: Fri, 2 Aug 2024 07:39:58 -0600 Subject: [PATCH] Apply new container mode validations Apply new rules prohibiting STOP/RETURN in initcode and RETURNCONTRACT in runtime mode. For fuzzing, consider all input data to be runtime code. --- core/vm/eof.go | 2 +- core/vm/validate.go | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) 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)