Skip to content

Commit 29607e9

Browse files
committed
Skip FIO analysis on data continuation
1 parent dca60e1 commit 29607e9

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

codetrie/codetrie.go

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package codetrie
33
import (
44
"encoding/binary"
55
"errors"
6+
"fmt"
67
"math"
78

89
sszlib "github.com/ferranbt/fastssz"
@@ -32,13 +33,17 @@ type CodeTrie interface {
3233
GetTree() (*sszlib.Node, error)
3334
}
3435

36+
const (
37+
FIOUnset = 0xff
38+
)
39+
3540
type Chunk struct {
3641
fio uint8 // firstInstructionOffset
3742
code []byte
3843
}
3944

4045
func NewChunk() *Chunk {
41-
return &Chunk{fio: 0, code: nil}
46+
return &Chunk{fio: FIOUnset, code: nil}
4247
}
4348

4449
func (c *Chunk) Serialize() []byte {
@@ -203,11 +208,21 @@ func Chunkify(code []byte, chunkSize uint) []*Chunk {
203208
if i == numChunks-1 {
204209
endIdx = uint(len(code))
205210
}
206-
chunks[i] = &Chunk{fio: 0, code: code[startIdx:endIdx]}
211+
chunks[i] = &Chunk{fio: FIOUnset, code: code[startIdx:endIdx]}
207212
}
208213

209214
setFIO(chunks)
210215

216+
// Sanity check that all chunks were processed
217+
for i, _ := range chunks {
218+
if i == len(chunks)-1 {
219+
break
220+
}
221+
if chunks[i].fio == FIOUnset {
222+
panic(fmt.Sprintf("Chunk %d has unprocessed FIO", i))
223+
}
224+
}
225+
211226
return chunks
212227
}
213228

@@ -223,6 +238,11 @@ func setFIO(chunks []*Chunk) {
223238
break
224239
}
225240

241+
// This chunk was already processed (it is a data chunk continuation)
242+
if chunks[i].fio != FIOUnset {
243+
continue
244+
}
245+
226246
for j, op := range chunk.code {
227247
opcode := OpCode(op)
228248
// Push is the only opcode with immediate

0 commit comments

Comments
 (0)