Skip to content

Commit

Permalink
Skip FIO analysis on data continuation
Browse files Browse the repository at this point in the history
  • Loading branch information
axic committed May 17, 2021
1 parent dca60e1 commit 29607e9
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions codetrie/codetrie.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package codetrie
import (
"encoding/binary"
"errors"
"fmt"
"math"

sszlib "github.com/ferranbt/fastssz"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}

Expand All @@ -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
Expand Down

0 comments on commit 29607e9

Please sign in to comment.