@@ -66,12 +66,12 @@ func isEOFVersion1(code []byte) bool {
6666
6767// Container is an EOF container object.
6868type Container struct {
69- types []* functionMetadata
70- code [][]byte
71- sections []* Container
72- containerCode [][]byte
73- data []byte
74- dataSize int // might be more than len(data)
69+ types []* functionMetadata
70+ codeSections [][]byte
71+ subContainers []* Container
72+ subContainerCodes [][]byte
73+ data []byte
74+ dataSize int // might be more than len(data)
7575}
7676
7777// functionMetadata is an EOF function signature.
@@ -92,15 +92,15 @@ func (c *Container) MarshalBinary() []byte {
9292 b = append (b , kindTypes )
9393 b = binary .BigEndian .AppendUint16 (b , uint16 (len (c .types )* 4 ))
9494 b = append (b , kindCode )
95- b = binary .BigEndian .AppendUint16 (b , uint16 (len (c .code )))
96- for _ , code := range c .code {
97- b = binary .BigEndian .AppendUint16 (b , uint16 (len (code )))
95+ b = binary .BigEndian .AppendUint16 (b , uint16 (len (c .codeSections )))
96+ for _ , codeSection := range c .codeSections {
97+ b = binary .BigEndian .AppendUint16 (b , uint16 (len (codeSection )))
9898 }
9999 var encodedContainer [][]byte
100- if len (c .sections ) != 0 {
100+ if len (c .subContainers ) != 0 {
101101 b = append (b , kindContainer )
102- b = binary .BigEndian .AppendUint16 (b , uint16 (len (c .sections )))
103- for _ , section := range c .sections {
102+ b = binary .BigEndian .AppendUint16 (b , uint16 (len (c .subContainers )))
103+ for _ , section := range c .subContainers {
104104 encoded := section .MarshalBinary ()
105105 b = binary .BigEndian .AppendUint16 (b , uint16 (len (encoded )))
106106 encodedContainer = append (encodedContainer , encoded )
@@ -114,7 +114,7 @@ func (c *Container) MarshalBinary() []byte {
114114 for _ , ty := range c .types {
115115 b = append (b , []byte {ty .inputs , ty .outputs , byte (ty .maxStackHeight >> 8 ), byte (ty .maxStackHeight & 0x00ff )}... )
116116 }
117- for _ , code := range c .code {
117+ for _ , code := range c .codeSections {
118118 b = append (b , code ... )
119119 }
120120 for _ , section := range encodedContainer {
@@ -228,7 +228,7 @@ func (c *Container) unmarshalSubContainer(b []byte, isInitcode bool, topLevel bo
228228
229229 // Parse types section.
230230 idx := offsetTerminator + 1
231- var types []* functionMetadata
231+ var types = make ( []* functionMetadata , 0 , typesSize / 4 )
232232 for i := 0 ; i < typesSize / 4 ; i ++ {
233233 sig := & functionMetadata {
234234 inputs : b [idx + i * 4 ],
@@ -253,45 +253,44 @@ func (c *Container) unmarshalSubContainer(b []byte, isInitcode bool, topLevel bo
253253
254254 // Parse code sections.
255255 idx += typesSize
256- code := make ([][]byte , len (codeSizes ))
256+ codeSections := make ([][]byte , len (codeSizes ))
257257 for i , size := range codeSizes {
258258 if size == 0 {
259259 return fmt .Errorf ("%w for section %d: size must not be 0" , ErrInvalidCodeSize , i )
260260 }
261- code [i ] = b [idx : idx + size ]
261+ codeSections [i ] = b [idx : idx + size ]
262262 idx += size
263263 }
264- c .code = code
265-
264+ c .codeSections = codeSections
266265 // Parse the optional container sizes.
267266 if len (containerSizes ) != 0 {
268267 if len (containerSizes ) > maxContainerSections {
269268 return fmt .Errorf ("%w number of container section exceed: %v: have %v" , ErrInvalidContainerSectionSize , maxContainerSections , len (containerSizes ))
270269 }
271- containerCode := make ([][]byte , 0 , len (containerSizes ))
272- container := make ([]* Container , 0 , len (containerSizes ))
270+ subContainerCodes := make ([][]byte , 0 , len (containerSizes ))
271+ subContainers := make ([]* Container , 0 , len (containerSizes ))
273272 for i , size := range containerSizes {
274273 if size == 0 || idx + size > len (b ) {
275274 return fmt .Errorf ("%w for section %d: size must not be 0" , ErrInvalidContainerSectionSize , i )
276275 }
277- c := new (Container )
276+ subC := new (Container )
278277 end := min (idx + size , len (b ))
279- if err := c .unmarshalSubContainer (b [idx :end ], isInitcode , false ); err != nil {
278+ if err := subC .unmarshalSubContainer (b [idx :end ], isInitcode , false ); err != nil {
280279 if topLevel {
281280 return fmt .Errorf ("%w in sub container %d" , err , i )
282281 }
283282 return err
284283 }
285- container = append (container , c )
286- containerCode = append (containerCode , b [idx :end ])
284+ subContainers = append (subContainers , subC )
285+ subContainerCodes = append (subContainerCodes , b [idx :end ])
287286
288287 idx += size
289288 }
290- c .sections = container
291- c .containerCode = containerCode
289+ c .subContainers = subContainers
290+ c .subContainerCodes = subContainerCodes
292291 }
293292
294- // Parse data section.
293+ //Parse data section.
295294 end := len (b )
296295 if ! isInitcode {
297296 end = min (idx + dataSize , len (b ))
@@ -327,7 +326,7 @@ func (c *Container) validateSubContainer(jt *JumpTable, refBy int) error {
327326 // should not mean 2 and 3 should be visited twice
328327 var (
329328 index = toVisit [0 ]
330- code = c .code [index ]
329+ code = c .codeSections [index ]
331330 )
332331 if _ , ok := visited [index ]; ! ok {
333332 res , err := validateCode (code , index , c , jt , refBy == refByEOFCreate )
@@ -359,10 +358,10 @@ func (c *Container) validateSubContainer(jt *JumpTable, refBy int) error {
359358 toVisit = toVisit [1 :]
360359 }
361360 // Make sure every code section is visited at least once.
362- if len (visited ) != len (c .code ) {
361+ if len (visited ) != len (c .codeSections ) {
363362 return ErrUnreachableCode
364363 }
365- for idx , container := range c .sections {
364+ for idx , container := range c .subContainers {
366365 reference , ok := subContainerVisited [idx ]
367366 if ! ok {
368367 return ErrOrphanedSubcontainer
@@ -444,14 +443,14 @@ func (c *Container) String() string {
444443 result += fmt .Sprintf ("KindType: %02x\n " , kindTypes )
445444 result += fmt .Sprintf ("TypesSize: %04x\n " , len (c .types )* 4 )
446445 result += fmt .Sprintf ("KindCode: %02x\n " , kindCode )
447- result += fmt .Sprintf ("CodeSize: %04x\n " , len (c .code ))
448- for i , code := range c .code {
446+ result += fmt .Sprintf ("CodeSize: %04x\n " , len (c .codeSections ))
447+ for i , code := range c .codeSections {
449448 result += fmt .Sprintf ("Code %v length: %04x\n " , i , len (code ))
450449 }
451- if len (c .sections ) != 0 {
450+ if len (c .subContainers ) != 0 {
452451 result += fmt .Sprintf ("KindContainer: %02x\n " , kindContainer )
453- result += fmt .Sprintf ("ContainerSize: %04x\n " , len (c .sections ))
454- for i , section := range c .sections {
452+ result += fmt .Sprintf ("ContainerSize: %04x\n " , len (c .subContainers ))
453+ for i , section := range c .subContainers {
455454 result += fmt .Sprintf ("Container %v length: %04x\n " , i , len (section .MarshalBinary ()))
456455 }
457456 }
@@ -464,10 +463,10 @@ func (c *Container) String() string {
464463 for i , typ := range c .types {
465464 result += fmt .Sprintf ("Type %v: %v\n " , i , hex .EncodeToString ([]byte {typ .inputs , typ .outputs , byte (typ .maxStackHeight >> 8 ), byte (typ .maxStackHeight & 0x00ff )}))
466465 }
467- for i , code := range c .code {
466+ for i , code := range c .codeSections {
468467 result += fmt .Sprintf ("Code %v: %v\n " , i , hex .EncodeToString (code ))
469468 }
470- for i , section := range c .sections {
469+ for i , section := range c .subContainers {
471470 result += fmt .Sprintf ("Section %v: %v\n " , i , hex .EncodeToString (section .MarshalBinary ()))
472471 }
473472 result += fmt .Sprintf ("Data: %v\n " , hex .EncodeToString (c .data ))
0 commit comments