@@ -565,21 +565,32 @@ func get_committee_index_one*(bits: AttestationCommitteeBits): Opt[CommitteeInde
565
565
566
566
proc compute_on_chain_aggregate* (
567
567
network_aggregates: openArray [electra.Attestation]) : Opt[electra.Attestation] =
568
- # aggregates = sorted(network_aggregates, key=lambda a: get_committee_indices(a.committee_bits)[0])
569
- let aggregates = network_aggregates.sortedByIt(it.committee_bits.get_committee_index_one().expect(" just one" ))
570
-
571
- let data = aggregates[0 ].data
572
-
573
- var agg: AggregateSignature
574
- var committee_bits: AttestationCommitteeBits
568
+ let
569
+ aggregates = network_aggregates.sortedByIt(
570
+ it.committee_bits.get_committee_index_one().expect(" just one" ))
571
+ data = aggregates[0 ].data
575
572
576
- var totalLen = 0
573
+ var
574
+ agg: AggregateSignature
575
+ committee_bits: AttestationCommitteeBits
576
+ prev_committee_index: Opt[CommitteeIndex]
577
+ totalLen = 0
577
578
for i, a in aggregates:
579
+ let committee_index = ? get_committee_index_one(a.committee_bits)
580
+ if prev_committee_index.isNone:
581
+ prev_committee_index = Opt.some committee_index
582
+ elif committee_index.distinctBase <= prev_committee_index.get.distinctBase:
583
+ continue
584
+ prev_committee_index = Opt.some committee_index
585
+
578
586
totalLen += a.aggregation_bits.len
579
587
580
- var aggregation_bits = ElectraCommitteeValidatorsBits.init(totalLen)
581
- var pos = 0
582
- var prev_committee_index: Opt[CommitteeIndex]
588
+ prev_committee_index.reset()
589
+
590
+ var
591
+ aggregation_bits = ElectraCommitteeValidatorsBits.init(totalLen)
592
+ pos = 0
593
+ filledLen = 0
583
594
for i, a in aggregates:
584
595
let
585
596
committee_index = ? get_committee_index_one(a.committee_bits)
@@ -594,6 +605,7 @@ proc compute_on_chain_aggregate*(
594
605
for b in a.aggregation_bits:
595
606
aggregation_bits[pos] = b
596
607
pos += 1
608
+ filledLen += a.aggregation_bits.len
597
609
598
610
let sig = ? a.signature.load() # Expensive
599
611
if first:
@@ -603,6 +615,8 @@ proc compute_on_chain_aggregate*(
603
615
604
616
committee_bits[int (committee_index)] = true
605
617
618
+ doAssert totalLen == filledLen
619
+
606
620
let signature = agg.finish()
607
621
608
622
ok electra.Attestation(
0 commit comments