From 5a1acc4a07142f6d9de198f40d4dca136df98d34 Mon Sep 17 00:00:00 2001 From: Marius van der Wijden Date: Fri, 6 Sep 2024 12:21:30 +0200 Subject: [PATCH] core/vm: no more recursive errors --- core/vm/eof.go | 7 +++++-- core/vm/validate.go | 6 ++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/core/vm/eof.go b/core/vm/eof.go index c1375c7d88..c8c87930e2 100644 --- a/core/vm/eof.go +++ b/core/vm/eof.go @@ -89,7 +89,7 @@ type Container struct { ContainerSections []*Container ContainerCode [][]byte Data []byte - DataSize int // might be less than len(Data) + DataSize int // might be more than len(Data) } // FunctionMetadata is an EOF function signature. @@ -292,7 +292,10 @@ func (c *Container) unmarshalSubContainer(b []byte, isInitcode bool, topLevel bo c := new(Container) end := min(idx+size, len(b)) if err := c.unmarshalSubContainer(b[idx:end], isInitcode, false); err != nil { - return fmt.Errorf("%w for section %d", err, i) + if topLevel { + return fmt.Errorf("%w in sub container %d", err, i) + } + return err } container = append(container, c) containerCode = append(containerCode, b[idx:end]) diff --git a/core/vm/validate.go b/core/vm/validate.go index f86d336b43..11987f677e 100644 --- a/core/vm/validate.go +++ b/core/vm/validate.go @@ -120,9 +120,15 @@ func validateCode(code []byte, section int, container *Container, jt *JumpTable, if arg >= len(container.Types) { return nil, fmt.Errorf("%w: arg %d, last %d, pos %d", ErrInvalidSectionArgument, arg, len(container.Types), i) } + // TODO check if that is actually a problem + // JUMPF operand must point to a code section with equal or fewer number of outputs as the section in which it resides, or to a section with 0x80 as outputs (non-returning) + if container.Types[arg].Output > container.Types[section].Output { + return nil, fmt.Errorf("%w: arg %d, last %d, pos %d", ErrInvalidSectionArgument, arg, len(container.Types), i) + } visitedCode[arg] = struct{}{} case op == DATALOADN: arg, _ := parseUint16(code[i+1:]) + // TODO why are we checking this? We should just pad if arg+32 > len(container.Data) { return nil, fmt.Errorf("%w: arg %d, last %d, pos %d", ErrInvalidDataloadNArgument, arg, len(container.Data), i) }