Skip to content
Open
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
23 changes: 23 additions & 0 deletions codetrie/codetrie.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var (
versionValue = []byte{0x00}
codeLengthKey = []byte{0xff, 0xfe}
codeHashKey = []byte{0xff, 0xff}
swarmIdent = []byte{0xa1, 0x65, 0x62, 0x7a, 0x7a, 0x72} // a165 bzzr
)

type Trie interface {
Expand Down Expand Up @@ -217,19 +218,41 @@ func setFIO(chunks []*Chunk) {
}

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

for i, chunk := range chunks {
if i == len(chunks)-1 {
break
}

pushDataLeft := 0
for j, op := range chunk.code {

if swarmMatch == len(swarmIdent) {
continue // skip bytes corresponding to swarm metadata
}

if op == swarmIdent[swarmMatch] || (swarmMatch == 0 && op == 0xa2) {
swarmMatch += 1
} else {
swarmMatch = 0
}

if uint8(j) < chunk.fio { // FIO already set in previous chunk analysis
continue
}
if pushDataLeft > 0 { // current byte corresponds to PUSH data
pushDataLeft -= 1
continue
}

opcode := OpCode(op)
// Push is the only opcode with immediate
if !opcode.IsPush() {
continue
}
size := getPushSize(opcode)
pushDataLeft = size
// Fits within chunk
if j+size < chunkSize {
continue
Expand Down