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.
This commit is contained in:
Danno Ferrin 2024-08-02 07:39:58 -06:00 committed by Marius van der Wijden
parent 28db438a8e
commit 9edd35cefe
2 changed files with 4 additions and 1 deletions

View file

@ -338,7 +338,7 @@ func (c *Container) validateSubContainer(jt *JumpTable, isInitCode bool, refBy i
code = c.Code[index] code = c.Code[index]
) )
if _, ok := visited[index]; !ok { 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 { if err != nil {
return err return err
} }

View file

@ -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) return nil, fmt.Errorf("%w: arg %d, last %d, pos %d", ErrInvalidDataloadNArgument, arg, len(container.Data), i)
} }
case op == RETURNCONTRACT: case op == RETURNCONTRACT:
if !isInitCode {
return nil, ErrIncompatibleContainerKind
}
arg := int(code[i+1]) arg := int(code[i+1])
if arg >= len(container.ContainerSections) { if arg >= len(container.ContainerSections) {
return nil, fmt.Errorf("%w: arg %d, last %d, pos %d", ErrUnreachableCode, arg, len(container.ContainerSections), i) return nil, fmt.Errorf("%w: arg %d, last %d, pos %d", ErrUnreachableCode, arg, len(container.ContainerSections), i)