11use crate :: attestation_verification:: Error ;
2- use types:: { Attestation , AttestationElectra , BitList , BitVector , EthSpec , SingleAttestation } ;
2+ use types:: {
3+ Attestation , AttestationBase , AttestationElectra , BitList , BitVector , EthSpec , ForkName ,
4+ SingleAttestation ,
5+ } ;
36
47pub fn single_attestation_to_attestation < E : EthSpec > (
58 single_attestation : & SingleAttestation ,
69 committee : & [ usize ] ,
10+ fork_name : ForkName ,
711) -> Result < Attestation < E > , Error > {
812 let attester_index = single_attestation. attester_index ;
913 let committee_index = single_attestation. committee_index ;
@@ -24,23 +28,33 @@ pub fn single_attestation_to_attestation<E: EthSpec>(
2428 slot,
2529 } ) ?;
2630
27- let mut committee_bits: BitVector < E :: MaxCommitteesPerSlot > = BitVector :: default ( ) ;
28- committee_bits
29- . set ( committee_index as usize , true )
30- . map_err ( |e| Error :: Invalid ( e. into ( ) ) ) ?;
31+ if fork_name. electra_enabled ( ) {
32+ let mut committee_bits: BitVector < E :: MaxCommitteesPerSlot > = BitVector :: default ( ) ;
33+ committee_bits
34+ . set ( committee_index as usize , true )
35+ . map_err ( |e| Error :: Invalid ( e. into ( ) ) ) ?;
3136
32- let mut aggregation_bits =
33- BitList :: with_capacity ( committee. len ( ) ) . map_err ( |e| Error :: Invalid ( e. into ( ) ) ) ?;
34- aggregation_bits
35- . set ( aggregation_bit, true )
36- . map_err ( |e| Error :: Invalid ( e. into ( ) ) ) ?;
37-
38- // TODO(electra): consider eventually allowing conversion to non-Electra attestations as well
39- // to maintain invertability (`Attestation` -> `SingleAttestation` -> `Attestation`).
40- Ok ( Attestation :: Electra ( AttestationElectra {
41- aggregation_bits,
42- committee_bits,
43- data : single_attestation. data . clone ( ) ,
44- signature : single_attestation. signature . clone ( ) ,
45- } ) )
37+ let mut aggregation_bits =
38+ BitList :: with_capacity ( committee. len ( ) ) . map_err ( |e| Error :: Invalid ( e. into ( ) ) ) ?;
39+ aggregation_bits
40+ . set ( aggregation_bit, true )
41+ . map_err ( |e| Error :: Invalid ( e. into ( ) ) ) ?;
42+ Ok ( Attestation :: Electra ( AttestationElectra {
43+ aggregation_bits,
44+ committee_bits,
45+ data : single_attestation. data . clone ( ) ,
46+ signature : single_attestation. signature . clone ( ) ,
47+ } ) )
48+ } else {
49+ let mut aggregation_bits =
50+ BitList :: with_capacity ( committee. len ( ) ) . map_err ( |e| Error :: Invalid ( e. into ( ) ) ) ?;
51+ aggregation_bits
52+ . set ( aggregation_bit, true )
53+ . map_err ( |e| Error :: Invalid ( e. into ( ) ) ) ?;
54+ Ok ( Attestation :: Base ( AttestationBase {
55+ aggregation_bits,
56+ data : single_attestation. data . clone ( ) ,
57+ signature : single_attestation. signature . clone ( ) ,
58+ } ) )
59+ }
4660}
0 commit comments