Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip FIO analysis on data continuation #4

Open
wants to merge 6 commits into
base: cm/chunk-size
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions codetrie/codetrie.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,18 +212,25 @@ func Chunkify(code []byte, chunkSize uint) []*Chunk {
}

func setFIO(chunks []*Chunk) {
// Abort if there is only one chunk
if len(chunks) < 2 {
return
}

chunkSize := len(chunks[0].code)

for i, chunk := range chunks {
// Skip last chunk (as there's no chunk following)
if i == len(chunks)-1 {
break
}

for j, op := range chunk.code {
// Skip bytes part of a data
if j < int(chunks[i].fio) {
continue
}

opcode := OpCode(op)
// Push is the only opcode with immediate
if !opcode.IsPush() {
Expand All @@ -239,20 +246,19 @@ func setFIO(chunks []*Chunk) {
// If chunkSize < 32, then data could span multiple chunks.
// restData is number of data bytes in next chunks.
restData := (j + size + 1) - chunkSize
spanningChunks := int(math.Ceil(float64(restData) / float64(chunkSize)))
// Mostly happens in case of Solidity metadata at
// the end of code.
if i+spanningChunks >= len(chunks) {
continue
}
k := 1
for restData > chunkSize {
chunks[i+k].fio = uint8(chunkSize)
// We may be trying to access non-existing chunks in case of truncated or invalid code
if (i+k) <= len(chunks)-1 {
chunks[i+k].fio = uint8(chunkSize)
}
k++
restData -= chunkSize
}
if restData > 0 {
chunks[i+k].fio = uint8(restData)
if (i+k) <= len(chunks)-1 {
chunks[i+k].fio = uint8(restData)
}
}
}
}
Expand Down
Loading