@@ -16,6 +16,9 @@ use super::ConcatenationProof;
16
16
pub enum AggregateSignatureType {
17
17
/// Concatenation proof system.
18
18
Concatenation ,
19
+ /// Future proof system. Not suitable for production.
20
+ #[ cfg( feature = "future_proof_system" ) ]
21
+ Future ,
19
22
}
20
23
21
24
impl AggregateSignatureType {
@@ -25,6 +28,8 @@ impl AggregateSignatureType {
25
28
pub fn to_bytes_encoding_prefix ( & self ) -> u8 {
26
29
match self {
27
30
AggregateSignatureType :: Concatenation => 0 ,
31
+ #[ cfg( feature = "future_proof_system" ) ]
32
+ AggregateSignatureType :: Future => 255 ,
28
33
}
29
34
}
30
35
@@ -34,6 +39,8 @@ impl AggregateSignatureType {
34
39
pub fn from_bytes_encoding_prefix ( byte : u8 ) -> Option < Self > {
35
40
match byte {
36
41
0 => Some ( AggregateSignatureType :: Concatenation ) ,
42
+ #[ cfg( feature = "future_proof_system" ) ]
43
+ 255 => Some ( AggregateSignatureType :: Future ) ,
37
44
_ => None ,
38
45
}
39
46
}
@@ -45,6 +52,8 @@ impl<D: Clone + Digest + FixedOutput + Send + Sync> From<&AggregateSignature<D>>
45
52
fn from ( aggr_sig : & AggregateSignature < D > ) -> Self {
46
53
match aggr_sig {
47
54
AggregateSignature :: Concatenation ( _) => AggregateSignatureType :: Concatenation ,
55
+ #[ cfg( feature = "future_proof_system" ) ]
56
+ AggregateSignature :: Future ( _) => AggregateSignatureType :: Future ,
48
57
}
49
58
}
50
59
}
@@ -53,6 +62,8 @@ impl Display for AggregateSignatureType {
53
62
fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
54
63
match self {
55
64
AggregateSignatureType :: Concatenation => write ! ( f, "Concatenation" ) ,
65
+ #[ cfg( feature = "future_proof_system" ) ]
66
+ AggregateSignatureType :: Future => write ! ( f, "Future" ) ,
56
67
}
57
68
}
58
69
}
@@ -63,9 +74,16 @@ impl Display for AggregateSignatureType {
63
74
serialize = "MerkleBatchPath<D>: Serialize" ,
64
75
deserialize = "MerkleBatchPath<D>: Deserialize<'de>"
65
76
) ) ]
66
- #[ serde( untagged) ]
67
77
pub enum AggregateSignature < D : Clone + Digest + FixedOutput + Send + Sync > {
78
+ /// A future proof system.
79
+ #[ cfg( feature = "future_proof_system" ) ]
80
+ Future ( ConcatenationProof < D > ) ,
81
+
68
82
/// 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) ]
69
87
Concatenation ( ConcatenationProof < D > ) ,
70
88
}
71
89
@@ -78,8 +96,12 @@ impl<D: Clone + Digest + FixedOutput + Send + Sync> AggregateSignature<D> {
78
96
parameters : & Parameters ,
79
97
) -> Result < ( ) , StmAggregateSignatureError < D > > {
80
98
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)
83
105
}
84
106
}
85
107
}
@@ -98,21 +120,55 @@ impl<D: Clone + Digest + FixedOutput + Send + Sync> AggregateSignature<D> {
98
120
} ) ;
99
121
stm_signatures
100
122
. 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
105
128
. into_iter ( )
106
129
. 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 ,
108
134
} )
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
+ } )
116
172
. map_err ( |_| StmAggregateSignatureError :: BatchInvalid )
117
173
}
118
174
@@ -127,6 +183,8 @@ impl<D: Clone + Digest + FixedOutput + Send + Sync> AggregateSignature<D> {
127
183
AggregateSignature :: Concatenation ( concatenation_proof) => {
128
184
concatenation_proof. to_bytes ( )
129
185
}
186
+ #[ cfg( feature = "future_proof_system" ) ]
187
+ AggregateSignature :: Future ( concatenation_proof) => concatenation_proof. to_bytes ( ) ,
130
188
} ;
131
189
aggregate_signature_bytes. append ( & mut proof_bytes) ;
132
190
@@ -143,22 +201,38 @@ impl<D: Clone + Digest + FixedOutput + Send + Sync> AggregateSignature<D> {
143
201
AggregateSignatureType :: Concatenation => Ok ( AggregateSignature :: Concatenation (
144
202
ConcatenationProof :: from_bytes ( proof_bytes) ?,
145
203
) ) ,
204
+ #[ cfg( feature = "future_proof_system" ) ]
205
+ AggregateSignatureType :: Future => Ok ( AggregateSignature :: Future (
206
+ ConcatenationProof :: from_bytes ( proof_bytes) ?,
207
+ ) ) ,
146
208
}
147
209
}
148
210
149
211
/// Extract the list of signatures.
150
212
// TODO: transfer this function to the concatenation proof ? Some proofs might not fully carry this information
151
213
pub fn signatures ( & self ) -> Vec < SingleSignatureWithRegisteredParty > {
152
214
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
+ }
154
222
}
155
223
}
156
224
157
225
/// Extract the list of unique merkle tree nodes that covers path for all signatures.
158
226
// TODO: transfer this function to the concatenation proof
159
227
pub fn batch_proof ( & self ) -> MerkleBatchPath < D > {
160
228
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
+ }
162
236
}
163
237
}
164
238
@@ -167,8 +241,12 @@ impl<D: Clone + Digest + FixedOutput + Send + Sync> AggregateSignature<D> {
167
241
#[ cfg( test) ]
168
242
pub ( crate ) fn set_batch_proof ( & mut self , batch_proof : MerkleBatchPath < D > ) {
169
243
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
172
250
}
173
251
}
174
252
}
0 commit comments