From 29607e93b399d15b46d457d625fb00820cb6bd24 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 17 May 2021 18:27:17 +0100 Subject: [PATCH] Skip FIO analysis on data continuation --- codetrie/codetrie.go | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/codetrie/codetrie.go b/codetrie/codetrie.go index 2999890c3234..5216b41ea18b 100644 --- a/codetrie/codetrie.go +++ b/codetrie/codetrie.go @@ -3,6 +3,7 @@ package codetrie import ( "encoding/binary" "errors" + "fmt" "math" sszlib "github.com/ferranbt/fastssz" @@ -32,13 +33,17 @@ type CodeTrie interface { GetTree() (*sszlib.Node, error) } +const ( + FIOUnset = 0xff +) + type Chunk struct { fio uint8 // firstInstructionOffset code []byte } func NewChunk() *Chunk { - return &Chunk{fio: 0, code: nil} + return &Chunk{fio: FIOUnset, code: nil} } func (c *Chunk) Serialize() []byte { @@ -203,11 +208,21 @@ func Chunkify(code []byte, chunkSize uint) []*Chunk { if i == numChunks-1 { endIdx = uint(len(code)) } - chunks[i] = &Chunk{fio: 0, code: code[startIdx:endIdx]} + chunks[i] = &Chunk{fio: FIOUnset, code: code[startIdx:endIdx]} } setFIO(chunks) + // Sanity check that all chunks were processed + for i, _ := range chunks { + if i == len(chunks)-1 { + break + } + if chunks[i].fio == FIOUnset { + panic(fmt.Sprintf("Chunk %d has unprocessed FIO", i)) + } + } + return chunks } @@ -223,6 +238,11 @@ func setFIO(chunks []*Chunk) { break } + // This chunk was already processed (it is a data chunk continuation) + if chunks[i].fio != FIOUnset { + continue + } + for j, op := range chunk.code { opcode := OpCode(op) // Push is the only opcode with immediate