@@ -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 ,
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,9 +96,13 @@ 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)
83
101
}
102
+ #[ cfg( feature = "future_proof_system" ) ]
103
+ AggregateSignature :: Future => Err ( StmAggregateSignatureError :: UnsupportedProofSystem (
104
+ self . into ( ) ,
105
+ ) ) ,
84
106
}
85
107
}
86
108
@@ -98,21 +120,33 @@ 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
- . filter_map ( |s| match s {
107
- Self :: Concatenation ( stm_aggr_sig) => Some ( stm_aggr_sig) ,
108
- } )
109
- . collect :: < Vec < _ > > ( ) ,
110
- msgs,
111
- avks,
112
- parameters,
113
- ) ,
114
- } ,
115
- )
129
+ . filter_map ( |s| s. to_concatenation_proof ( ) . cloned ( ) )
130
+ . collect :: < Vec < _ > > ( ) ;
131
+ if concatenation_proofs. len ( ) != aggregate_signatures_length {
132
+ return Err ( StmAggregateSignatureError :: BatchInvalid ) ;
133
+ }
134
+
135
+ ConcatenationProof :: batch_verify (
136
+ & concatenation_proofs,
137
+ msgs,
138
+ avks,
139
+ parameters,
140
+ )
141
+ }
142
+ #[ cfg( feature = "future_proof_system" ) ]
143
+ AggregateSignatureType :: Future => {
144
+ Err ( StmAggregateSignatureError :: UnsupportedProofSystem (
145
+ aggregate_signature_type,
146
+ ) )
147
+ }
148
+ }
149
+ } )
116
150
. map_err ( |_| StmAggregateSignatureError :: BatchInvalid )
117
151
}
118
152
@@ -127,6 +161,8 @@ impl<D: Clone + Digest + FixedOutput + Send + Sync> AggregateSignature<D> {
127
161
AggregateSignature :: Concatenation ( concatenation_proof) => {
128
162
concatenation_proof. to_bytes ( )
129
163
}
164
+ #[ cfg( feature = "future_proof_system" ) ]
165
+ AggregateSignature :: Future => vec ! [ ] ,
130
166
} ;
131
167
aggregate_signature_bytes. append ( & mut proof_bytes) ;
132
168
@@ -143,22 +179,45 @@ impl<D: Clone + Digest + FixedOutput + Send + Sync> AggregateSignature<D> {
143
179
AggregateSignatureType :: Concatenation => Ok ( AggregateSignature :: Concatenation (
144
180
ConcatenationProof :: from_bytes ( proof_bytes) ?,
145
181
) ) ,
182
+ #[ cfg( feature = "future_proof_system" ) ]
183
+ AggregateSignatureType :: Future => Ok ( AggregateSignature :: Future ) ,
184
+ }
185
+ }
186
+
187
+ /// If the aggregate signature is a concatenation proof, return it.
188
+ pub fn to_concatenation_proof ( & self ) -> Option < & ConcatenationProof < D > > {
189
+ match self {
190
+ AggregateSignature :: Concatenation ( proof) => Some ( proof) ,
191
+ #[ cfg( feature = "future_proof_system" ) ]
192
+ AggregateSignature :: Future => None ,
146
193
}
147
194
}
148
195
149
196
/// Extract the list of signatures.
150
197
// TODO: transfer this function to the concatenation proof ? Some proofs might not fully carry this information
151
198
pub fn signatures ( & self ) -> Vec < SingleSignatureWithRegisteredParty > {
152
199
match self {
153
- AggregateSignature :: Concatenation ( stm_aggr_sig) => stm_aggr_sig. signatures . clone ( ) ,
200
+ AggregateSignature :: Concatenation ( concatenation_proof) => {
201
+ concatenation_proof. signatures . clone ( )
202
+ }
203
+ #[ cfg( feature = "future_proof_system" ) ]
204
+ AggregateSignature :: Future ( concatenation_proof) => {
205
+ concatenation_proof. signatures . clone ( )
206
+ }
154
207
}
155
208
}
156
209
157
210
/// Extract the list of unique merkle tree nodes that covers path for all signatures.
158
211
// TODO: transfer this function to the concatenation proof
159
212
pub fn batch_proof ( & self ) -> MerkleBatchPath < D > {
160
213
match self {
161
- AggregateSignature :: Concatenation ( stm_aggr_sig) => stm_aggr_sig. batch_proof . clone ( ) ,
214
+ AggregateSignature :: Concatenation ( concatenation_proof) => {
215
+ concatenation_proof. batch_proof . clone ( )
216
+ }
217
+ #[ cfg( feature = "future_proof_system" ) ]
218
+ AggregateSignature :: Future ( concatenation_proof) => {
219
+ concatenation_proof. batch_proof . clone ( )
220
+ }
162
221
}
163
222
}
164
223
@@ -167,8 +226,12 @@ impl<D: Clone + Digest + FixedOutput + Send + Sync> AggregateSignature<D> {
167
226
#[ cfg( test) ]
168
227
pub ( crate ) fn set_batch_proof ( & mut self , batch_proof : MerkleBatchPath < D > ) {
169
228
match self {
170
- AggregateSignature :: Concatenation ( stm_aggr_sig) => {
171
- stm_aggr_sig. batch_proof = batch_proof
229
+ AggregateSignature :: Concatenation ( concatenation_proof) => {
230
+ concatenation_proof. batch_proof = batch_proof
231
+ }
232
+ #[ cfg( feature = "future_proof_system" ) ]
233
+ AggregateSignature :: Future ( concatenation_proof) => {
234
+ concatenation_proof. batch_proof = batch_proof
172
235
}
173
236
}
174
237
}
0 commit comments