@@ -412,6 +412,7 @@ func (s *NoChainIDSignature) Write(writer io.Writer) error {
412412 if checkpointSize > 7 {
413413 return fmt .Errorf ("checkpoint size %d exceeds maximum of 7 bytes" , checkpointSize )
414414 }
415+
415416 if thresholdSize == 0 {
416417 thresholdSize = 1
417418 }
@@ -575,32 +576,26 @@ func (s ChainedSignature) Data() ([]byte, error) {
575576}
576577
577578func (s ChainedSignature ) Write (writer io.Writer ) error {
578- // Default flag
579579 flag := byte (0x01 )
580580
581- // Check the last signature for Checkpointer, if the slice is not empty
582581 if len (s ) > 0 {
583582 lastSig := s [len (s )- 1 ]
584- // Type assertion to concrete types
585583 if regSig , ok := lastSig .(* RegularSignature ); ok {
586- // Access Checkpointer through the embedded Signature struct
587584 if regSig .Signature .Checkpointer != (common.Address {}) {
588- flag |= 0x40 // Set bit [6] if Checkpointer is present
585+ flag |= 0x40
589586 }
590587 } else if noChainSig , ok := lastSig .(* NoChainIDSignature ); ok {
591588 if noChainSig .Signature .Checkpointer != (common.Address {}) {
592- flag |= 0x40 // Set bit [6] if Checkpointer is present
589+ flag |= 0x40
593590 }
594591 }
595592 }
596593
597- // Write the flag
598594 _ , err := writer .Write ([]byte {flag })
599595 if err != nil {
600596 return fmt .Errorf ("unable to write chained signature type: %w" , err )
601597 }
602598
603- // Write Checkpointer data if present
604599 if len (s ) > 0 {
605600 lastSig := s [len (s )- 1 ]
606601 if regSig , ok := lastSig .(* RegularSignature ); ok && regSig .Signature .Checkpointer != (common.Address {}) {
@@ -632,7 +627,6 @@ func (s ChainedSignature) Write(writer io.Writer) error {
632627 }
633628 }
634629
635- // Write all subsignatures
636630 for i , subsignature := range s {
637631 data , err := subsignature .Data ()
638632 if err != nil {
@@ -911,7 +905,6 @@ func (l *signatureTreeSignatureHashLeaf) reduceImageHash() (core.ImageHash, erro
911905func (l * signatureTreeSignatureHashLeaf ) write (writer io.Writer ) error {
912906 var flag byte
913907 var weightBytes []byte
914-
915908 flag = FLAG_SIGNATURE_HASH << 4
916909
917910 if l .Weight > 0 && l .Weight <= 15 {
@@ -938,7 +931,6 @@ func (l *signatureTreeSignatureHashLeaf) write(writer io.Writer) error {
938931 }
939932
940933 s := l .YParityAndS
941-
942934 if l .V % 2 == 0 {
943935 s [0 ] |= 0x80
944936 }
@@ -1001,27 +993,30 @@ func (l *signatureTreeAddressLeaf) reduceImageHash() (core.ImageHash, error) {
1001993func (l * signatureTreeAddressLeaf ) write (writer io.Writer ) error {
1002994 flag := byte (FLAG_ADDRESS << 4 )
1003995 var weightBytes []byte
996+
1004997 if l .Weight > 0 && l .Weight <= 15 {
1005998 flag |= l .Weight
1006- } else if l .Weight <= 255 {
1007- weightBytes = []byte {l .Weight }
1008999 } else {
1009- return fmt . Errorf ( "weight too large: %d" , l .Weight )
1000+ weightBytes = [] byte { l .Weight }
10101001 }
1002+
10111003 _ , err := writer .Write ([]byte {flag })
10121004 if err != nil {
10131005 return fmt .Errorf ("unable to write address leaf type: %w" , err )
10141006 }
1007+
10151008 if len (weightBytes ) > 0 {
10161009 _ , err = writer .Write (weightBytes )
10171010 if err != nil {
10181011 return fmt .Errorf ("unable to write dynamic weight: %w" , err )
10191012 }
10201013 }
1014+
10211015 _ , err = writer .Write (l .Address .Bytes ())
10221016 if err != nil {
10231017 return fmt .Errorf ("unable to write address: %w" , err )
10241018 }
1019+
10251020 return nil
10261021}
10271022
@@ -1204,10 +1199,12 @@ func (l signatureTreeNodeLeaf) write(writer io.Writer) error {
12041199 if err != nil {
12051200 return fmt .Errorf ("unable to write node leaf type: %w" , err )
12061201 }
1202+
12071203 _ , err = writer .Write (l .Bytes ())
12081204 if err != nil {
12091205 return fmt .Errorf ("unable to write node hash: %w" , err )
12101206 }
1207+
12111208 return nil
12121209}
12131210
@@ -1258,13 +1255,16 @@ func (l signatureTreeSubdigestLeaf) reduceImageHash() (core.ImageHash, error) {
12581255
12591256func (l signatureTreeSubdigestLeaf ) write (writer io.Writer ) error {
12601257 _ , err := writer .Write ([]byte {FLAG_SUBDIGEST << 4 })
1258+
12611259 if err != nil {
12621260 return fmt .Errorf ("unable to write subdigest leaf type: %w" , err )
12631261 }
1262+
12641263 _ , err = writer .Write (l .Bytes ())
12651264 if err != nil {
12661265 return fmt .Errorf ("unable to write subdigest: %w" , err )
12671266 }
1267+
12681268 return nil
12691269}
12701270
@@ -1372,20 +1372,16 @@ func (l *signatureTreeNestedLeaf) write(writer io.Writer) error {
13721372 var weightBytes []byte
13731373 if l .Weight <= 3 && l .Weight > 0 {
13741374 flag |= (l .Weight << 2 )
1375- } else if l .Weight <= 255 {
1376- weightBytes = []byte {l .Weight }
13771375 } else {
1378- return fmt . Errorf ( "weight too large: %d" , l .Weight )
1376+ weightBytes = [] byte { l .Weight }
13791377 }
13801378
13811379 var thresholdBytes []byte
13821380 if l .Threshold <= 3 && l .Threshold > 0 {
13831381 flag |= byte (l .Threshold )
1384- } else if l . Threshold <= 65535 {
1382+ } else {
13851383 thresholdBytes = make ([]byte , 2 )
13861384 binary .BigEndian .PutUint16 (thresholdBytes , l .Threshold )
1387- } else {
1388- return fmt .Errorf ("threshold too large: %d" , l .Threshold )
13891385 }
13901386
13911387 _ , err := writer .Write ([]byte {flag })
@@ -1490,33 +1486,35 @@ func (l *signatureTreeSignatureEthSignLeaf) reduceImageHash() (core.ImageHash, e
14901486func (l * signatureTreeSignatureEthSignLeaf ) write (writer io.Writer ) error {
14911487 flag := byte (FLAG_SIGNATURE_ETH_SIGN << 4 )
14921488 var weightBytes []byte
1489+
14931490 if l .Weight > 0 && l .Weight <= 15 {
14941491 flag |= l .Weight
1495- } else if l .Weight <= 255 {
1496- weightBytes = []byte {l .Weight }
14971492 } else {
1498- return fmt . Errorf ( "weight too large: %d" , l .Weight )
1493+ weightBytes = [] byte { l .Weight }
14991494 }
1495+
15001496 _ , err := writer .Write ([]byte {flag })
15011497 if err != nil {
15021498 return fmt .Errorf ("unable to write eth sign leaf type: %w" , err )
15031499 }
1500+
15041501 if len (weightBytes ) > 0 {
15051502 _ , err = writer .Write (weightBytes )
15061503 if err != nil {
15071504 return fmt .Errorf ("unable to write dynamic weight: %w" , err )
15081505 }
15091506 }
1507+
15101508 _ , err = writer .Write (l .R [:])
15111509 if err != nil {
15121510 return fmt .Errorf ("unable to write R: %w" , err )
15131511 }
1512+
15141513 s := l .YParityAndS
15151514 if l .V % 2 == 0 {
15161515 s [0 ] |= 0x80
1517- } else {
1518- s [0 ] &= 0x7f
15191516 }
1517+
15201518 _ , err = writer .Write (s [:])
15211519 if err != nil {
15221520 return fmt .Errorf ("unable to write YParityAndS: %w" , err )
@@ -1565,10 +1563,12 @@ func (l *signatureTreeAnyAddressSubdigestLeaf) write(writer io.Writer) error {
15651563 if err != nil {
15661564 return fmt .Errorf ("unable to write any address subdigest leaf type: %w" , err )
15671565 }
1566+
15681567 _ , err = writer .Write (l .Subdigest .Bytes ())
15691568 if err != nil {
15701569 return fmt .Errorf ("unable to write subdigest: %w" , err )
15711570 }
1571+
15721572 return nil
15731573}
15741574
0 commit comments