@@ -16,6 +16,9 @@ use super::ConcatenationProof;
1616pub  enum  AggregateSignatureType  { 
1717    /// Concatenation proof system. 
1818Concatenation , 
19+     /// Future proof system. Not suitable for production. 
20+ #[ cfg( feature = "future_proof_system" ) ]  
21+     Future , 
1922} 
2023
2124impl  AggregateSignatureType  { 
@@ -25,6 +28,8 @@ impl AggregateSignatureType {
2528pub  fn  to_bytes_encoding_prefix ( & self )  -> u8  { 
2629        match  self  { 
2730            AggregateSignatureType :: Concatenation  => 0 , 
31+             #[ cfg( feature = "future_proof_system" ) ]  
32+             AggregateSignatureType :: Future  => 255 , 
2833        } 
2934    } 
3035
@@ -34,6 +39,8 @@ impl AggregateSignatureType {
3439pub  fn  from_bytes_encoding_prefix ( byte :  u8 )  -> Option < Self >  { 
3540        match  byte { 
3641            0  => Some ( AggregateSignatureType :: Concatenation ) , 
42+             #[ cfg( feature = "future_proof_system" ) ]  
43+             255  => Some ( AggregateSignatureType :: Future ) , 
3744            _ => None , 
3845        } 
3946    } 
@@ -45,6 +52,8 @@ impl<D: Clone + Digest + FixedOutput + Send + Sync> From<&AggregateSignature<D>>
4552    fn  from ( aggr_sig :  & AggregateSignature < D > )  -> Self  { 
4653        match  aggr_sig { 
4754            AggregateSignature :: Concatenation ( _)  => AggregateSignatureType :: Concatenation , 
55+             #[ cfg( feature = "future_proof_system" ) ]  
56+             AggregateSignature :: Future ( _)  => AggregateSignatureType :: Future , 
4857        } 
4958    } 
5059} 
@@ -53,6 +62,8 @@ impl Display for AggregateSignatureType {
5362    fn  fmt ( & self ,  f :  & mut  std:: fmt:: Formatter < ' _ > )  -> std:: fmt:: Result  { 
5463        match  self  { 
5564            AggregateSignatureType :: Concatenation  => write ! ( f,  "Concatenation" ) , 
65+             #[ cfg( feature = "future_proof_system" ) ]  
66+             AggregateSignatureType :: Future  => write ! ( f,  "Future" ) , 
5667        } 
5768    } 
5869} 
@@ -63,9 +74,16 @@ impl Display for AggregateSignatureType {
6374    serialize = "MerkleBatchPath<D>: Serialize" ,  
6475    deserialize = "MerkleBatchPath<D>: Deserialize<'de>"  
6576) ) ] 
66- #[ serde( untagged) ]  
6777pub  enum  AggregateSignature < D :  Clone  + Digest  + FixedOutput  + Send  + Sync >  { 
78+     /// A future proof system. 
79+ #[ cfg( feature = "future_proof_system" ) ]  
80+     Future ( ConcatenationProof < D > ) , 
81+ 
6882    /// Concatenation proof system. 
83+ // The 'untagged' attribute is required for backward compatibility. 
84+     // It implies that this variant is placed at the end of the enum. 
85+     // It will be removed when the support for JSON hex encoding is dropped in the calling crates. 
86+     #[ serde( untagged) ]  
6987    Concatenation ( ConcatenationProof < D > ) , 
7088} 
7189
@@ -78,8 +96,12 @@ impl<D: Clone + Digest + FixedOutput + Send + Sync> AggregateSignature<D> {
7896        parameters :  & Parameters , 
7997    )  -> Result < ( ) ,  StmAggregateSignatureError < D > >  { 
8098        match  self  { 
81-             AggregateSignature :: Concatenation ( stm_aggr_sig)  => { 
82-                 stm_aggr_sig. verify ( msg,  avk,  parameters) 
99+             AggregateSignature :: Concatenation ( concatenation_proof)  => { 
100+                 concatenation_proof. verify ( msg,  avk,  parameters) 
101+             } 
102+             #[ cfg( feature = "future_proof_system" ) ]  
103+             AggregateSignature :: Future ( concatenation_proof)  => { 
104+                 concatenation_proof. verify ( msg,  avk,  parameters) 
83105            } 
84106        } 
85107    } 
@@ -98,21 +120,55 @@ impl<D: Clone + Digest + FixedOutput + Send + Sync> AggregateSignature<D> {
98120            } ) ; 
99121        stm_signatures
100122            . into_iter ( ) 
101-             . try_for_each ( 
102-                 |( stm_aggr_sig_type,  stm_aggr_sigs) | match  stm_aggr_sig_type { 
103-                     AggregateSignatureType :: Concatenation  => ConcatenationProof :: batch_verify ( 
104-                         & stm_aggr_sigs
123+             . try_for_each ( |( aggregate_signature_type,  aggregate_signatures) | { 
124+                 match  aggregate_signature_type { 
125+                     AggregateSignatureType :: Concatenation  => { 
126+                         let  aggregate_signatures_length = aggregate_signatures. len ( ) ; 
127+                         let  concatenation_proofs = aggregate_signatures
105128                            . into_iter ( ) 
106129                            . filter_map ( |s| match  s { 
107-                                 Self :: Concatenation ( stm_aggr_sig)  => Some ( stm_aggr_sig) , 
130+                                 Self :: Concatenation ( concatenation_proof)  => { 
131+                                     Some ( concatenation_proof) 
132+                                 } 
133+                                 _ => None , 
108134                            } ) 
109-                             . collect :: < Vec < _ > > ( ) , 
110-                         msgs, 
111-                         avks, 
112-                         parameters, 
113-                     ) , 
114-                 } , 
115-             ) 
135+                             . collect :: < Vec < _ > > ( ) ; 
136+                         if  concatenation_proofs. len ( )  != aggregate_signatures_length { 
137+                             return  Err ( StmAggregateSignatureError :: BatchInvalid ) ; 
138+                         } 
139+ 
140+                         ConcatenationProof :: batch_verify ( 
141+                             & concatenation_proofs, 
142+                             msgs, 
143+                             avks, 
144+                             parameters, 
145+                         ) 
146+                     } 
147+                     #[ cfg( feature = "future_proof_system" ) ]  
148+                     AggregateSignatureType :: Future  => { 
149+                         let  aggregate_signatures_length = aggregate_signatures. len ( ) ; 
150+                         let  aggregate_signatures_filtered = aggregate_signatures
151+                             . into_iter ( ) 
152+                             . filter_map ( |s| match  s { 
153+                                 Self :: Concatenation ( concatenation_proof)  => { 
154+                                     Some ( concatenation_proof) 
155+                                 } 
156+                                 _ => None , 
157+                             } ) 
158+                             . collect :: < Vec < _ > > ( ) ; 
159+                         if  aggregate_signatures_filtered. len ( )  != aggregate_signatures_length { 
160+                             return  Err ( StmAggregateSignatureError :: BatchInvalid ) ; 
161+                         } 
162+ 
163+                         ConcatenationProof :: batch_verify ( 
164+                             & aggregate_signatures_filtered, 
165+                             msgs, 
166+                             avks, 
167+                             parameters, 
168+                         ) 
169+                     } 
170+                 } 
171+             } ) 
116172            . map_err ( |_| StmAggregateSignatureError :: BatchInvalid ) 
117173    } 
118174
@@ -127,6 +183,8 @@ impl<D: Clone + Digest + FixedOutput + Send + Sync> AggregateSignature<D> {
127183            AggregateSignature :: Concatenation ( concatenation_proof)  => { 
128184                concatenation_proof. to_bytes ( ) 
129185            } 
186+             #[ cfg( feature = "future_proof_system" ) ]  
187+             AggregateSignature :: Future ( concatenation_proof)  => concatenation_proof. to_bytes ( ) , 
130188        } ; 
131189        aggregate_signature_bytes. append ( & mut  proof_bytes) ; 
132190
@@ -143,22 +201,38 @@ impl<D: Clone + Digest + FixedOutput + Send + Sync> AggregateSignature<D> {
143201            AggregateSignatureType :: Concatenation  => Ok ( AggregateSignature :: Concatenation ( 
144202                ConcatenationProof :: from_bytes ( proof_bytes) ?, 
145203            ) ) , 
204+             #[ cfg( feature = "future_proof_system" ) ]  
205+             AggregateSignatureType :: Future  => Ok ( AggregateSignature :: Future ( 
206+                 ConcatenationProof :: from_bytes ( proof_bytes) ?, 
207+             ) ) , 
146208        } 
147209    } 
148210
149211    /// Extract the list of signatures. 
150212// TODO: transfer this function to the concatenation proof ? Some proofs might not fully carry this information 
151213    pub  fn  signatures ( & self )  -> Vec < SingleSignatureWithRegisteredParty >  { 
152214        match  self  { 
153-             AggregateSignature :: Concatenation ( stm_aggr_sig)  => stm_aggr_sig. signatures . clone ( ) , 
215+             AggregateSignature :: Concatenation ( concatenation_proof)  => { 
216+                 concatenation_proof. signatures . clone ( ) 
217+             } 
218+             #[ cfg( feature = "future_proof_system" ) ]  
219+             AggregateSignature :: Future ( concatenation_proof)  => { 
220+                 concatenation_proof. signatures . clone ( ) 
221+             } 
154222        } 
155223    } 
156224
157225    /// Extract the list of unique merkle tree nodes that covers path for all signatures. 
158226// TODO: transfer this function to the concatenation proof 
159227    pub  fn  batch_proof ( & self )  -> MerkleBatchPath < D >  { 
160228        match  self  { 
161-             AggregateSignature :: Concatenation ( stm_aggr_sig)  => stm_aggr_sig. batch_proof . clone ( ) , 
229+             AggregateSignature :: Concatenation ( concatenation_proof)  => { 
230+                 concatenation_proof. batch_proof . clone ( ) 
231+             } 
232+             #[ cfg( feature = "future_proof_system" ) ]  
233+             AggregateSignature :: Future ( concatenation_proof)  => { 
234+                 concatenation_proof. batch_proof . clone ( ) 
235+             } 
162236        } 
163237    } 
164238
@@ -167,8 +241,12 @@ impl<D: Clone + Digest + FixedOutput + Send + Sync> AggregateSignature<D> {
167241    #[ cfg( test) ]  
168242    pub ( crate )  fn  set_batch_proof ( & mut  self ,  batch_proof :  MerkleBatchPath < D > )  { 
169243        match  self  { 
170-             AggregateSignature :: Concatenation ( stm_aggr_sig)  => { 
171-                 stm_aggr_sig. batch_proof  = batch_proof
244+             AggregateSignature :: Concatenation ( concatenation_proof)  => { 
245+                 concatenation_proof. batch_proof  = batch_proof
246+             } 
247+             #[ cfg( feature = "future_proof_system" ) ]  
248+             AggregateSignature :: Future ( concatenation_proof)  => { 
249+                 concatenation_proof. batch_proof  = batch_proof
172250            } 
173251        } 
174252    } 
0 commit comments