@@ -3,6 +3,7 @@ package codetrie
3
3
import (
4
4
"encoding/binary"
5
5
"errors"
6
+ "fmt"
6
7
"math"
7
8
8
9
sszlib "github.com/ferranbt/fastssz"
@@ -32,13 +33,17 @@ type CodeTrie interface {
32
33
GetTree () (* sszlib.Node , error )
33
34
}
34
35
36
+ const (
37
+ FIOUnset = 0xff
38
+ )
39
+
35
40
type Chunk struct {
36
41
fio uint8 // firstInstructionOffset
37
42
code []byte
38
43
}
39
44
40
45
func NewChunk () * Chunk {
41
- return & Chunk {fio : 0 , code : nil }
46
+ return & Chunk {fio : FIOUnset , code : nil }
42
47
}
43
48
44
49
func (c * Chunk ) Serialize () []byte {
@@ -203,11 +208,21 @@ func Chunkify(code []byte, chunkSize uint) []*Chunk {
203
208
if i == numChunks - 1 {
204
209
endIdx = uint (len (code ))
205
210
}
206
- chunks [i ] = & Chunk {fio : 0 , code : code [startIdx :endIdx ]}
211
+ chunks [i ] = & Chunk {fio : FIOUnset , code : code [startIdx :endIdx ]}
207
212
}
208
213
209
214
setFIO (chunks )
210
215
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
+
211
226
return chunks
212
227
}
213
228
@@ -223,6 +238,11 @@ func setFIO(chunks []*Chunk) {
223
238
break
224
239
}
225
240
241
+ // This chunk was already processed (it is a data chunk continuation)
242
+ if chunks [i ].fio != FIOUnset {
243
+ continue
244
+ }
245
+
226
246
for j , op := range chunk .code {
227
247
opcode := OpCode (op )
228
248
// Push is the only opcode with immediate
0 commit comments