@@ -68,44 +68,28 @@ fn cache_path(kind: Kind) -> Option<PathBuf> {
68
68
super :: circuit_blobs:: home_base_dir ( ) . map ( |p| p. join ( cache_filename ( kind) ) )
69
69
}
70
70
71
- macro_rules! read_cache {
72
- ( $kind: expr, $digest: expr) => { {
73
- #[ cfg( not( target_family = "wasm" ) ) ]
74
- let data = super :: circuit_blobs:: fetch( & cache_filename( $kind) )
75
- . context( "fetching verifier index failed" ) ?;
76
- #[ cfg( target_family = "wasm" ) ]
77
- let data = super :: circuit_blobs:: fetch( & cache_filename( $kind) )
78
- . await
79
- . context( "fetching verifier index failed" ) ?;
80
- let mut slice = data. as_slice( ) ;
81
- let mut d = [ 0 ; 32 ] ;
82
- // source digest
83
- slice. read_exact( & mut d) . context( "reading source digest" ) ?;
84
- if d != $digest {
85
- anyhow:: bail!( "source digest verification failed" ) ;
86
- }
87
-
88
- // index digest
89
- slice. read_exact( & mut d) . context( "reading index digest" ) ?;
90
-
91
- let mut hasher = Sha256 :: new( ) ;
92
- hasher. update( slice) ;
93
- let digest = hasher. finalize( ) ;
94
- if d != digest. as_slice( ) {
95
- anyhow:: bail!( "verifier index digest verification failed" ) ;
96
- }
97
- Ok ( super :: caching:: verifier_index_from_bytes( slice) ?)
98
- } } ;
99
- }
71
+ async fn read_cache ( kind : Kind , digest : & [ u8 ] ) -> anyhow:: Result < VerifierIndex < Fq > > {
72
+ let data = super :: circuit_blobs:: fetch ( & cache_filename ( kind) )
73
+ . await
74
+ . context ( "fetching verifier index failed" ) ?;
75
+ let mut slice = data. as_slice ( ) ;
76
+ let mut d = [ 0 ; 32 ] ;
77
+ // source digest
78
+ slice. read_exact ( & mut d) . context ( "reading source digest" ) ?;
79
+ if d != digest {
80
+ anyhow:: bail!( "source digest verification failed" ) ;
81
+ }
100
82
101
- #[ cfg( not( target_family = "wasm" ) ) ]
102
- fn read_cache ( kind : Kind , digest : & [ u8 ] ) -> anyhow:: Result < VerifierIndex < Fq > > {
103
- read_cache ! ( kind, digest)
104
- }
83
+ // index digest
84
+ slice. read_exact ( & mut d) . context ( "reading index digest" ) ?;
105
85
106
- #[ cfg( target_family = "wasm" ) ]
107
- async fn read_cache ( kind : Kind , digest : & [ u8 ] ) -> anyhow:: Result < VerifierIndex < Fq > > {
108
- read_cache ! ( kind, digest)
86
+ let mut hasher = Sha256 :: new ( ) ;
87
+ hasher. update ( slice) ;
88
+ let digest = hasher. finalize ( ) ;
89
+ if d != digest. as_slice ( ) {
90
+ anyhow:: bail!( "verifier index digest verification failed" ) ;
91
+ }
92
+ Ok ( super :: caching:: verifier_index_from_bytes ( slice) ?)
109
93
}
110
94
111
95
#[ cfg( not( target_family = "wasm" ) ) ]
@@ -130,46 +114,31 @@ fn write_cache(kind: Kind, index: &VerifierIndex<Fq>, digest: &[u8]) -> anyhow::
130
114
Ok ( ( ) )
131
115
}
132
116
133
- macro_rules! make_with_ext_cache {
134
- ( $kind: expr, $data: expr) => { {
135
- let verifier_index: VerifierIndex <Fq > = serde_json:: from_str( $data) . unwrap( ) ;
136
- let mut hasher = Sha256 :: new( ) ;
137
- hasher. update( $data) ;
138
- let src_index_digest = hasher. finalize( ) ;
139
-
140
- #[ cfg( not( target_family = "wasm" ) ) ]
141
- let cache = read_cache( $kind, & src_index_digest) ;
142
- #[ cfg( target_family = "wasm" ) ]
143
- let cache = read_cache( $kind, & src_index_digest) . await ;
144
-
145
- match cache {
146
- Ok ( verifier_index) => {
147
- info!( system_time( ) ; "Verifier index is loaded" ) ;
148
- verifier_index
149
- }
150
- Err ( err) => {
151
- warn!( system_time( ) ; "Cannot load verifier index: {err}" ) ;
152
- let index = make_verifier_index( verifier_index) ;
153
- #[ cfg( not( target_family = "wasm" ) ) ]
154
- if let Err ( err) = write_cache( $kind, & index, & src_index_digest) {
155
- warn!( system_time( ) ; "Cannot store verifier index to cache file: {err}" ) ;
156
- } else {
157
- info!( system_time( ) ; "Stored verifier index to cache file" ) ;
158
- }
159
- index
160
- }
161
- }
162
- } }
163
- }
117
+ async fn make_with_ext_cache ( kind : Kind , data : & str ) -> VerifierIndex < Fq > {
118
+ let verifier_index: VerifierIndex < Fq > = serde_json:: from_str ( data) . unwrap ( ) ;
119
+ let mut hasher = Sha256 :: new ( ) ;
120
+ hasher. update ( data) ;
121
+ let src_index_digest = hasher. finalize ( ) ;
164
122
165
- #[ cfg( not( target_family = "wasm" ) ) ]
166
- fn make_with_ext_cache ( kind : Kind , data : & str ) -> VerifierIndex < Fq > {
167
- make_with_ext_cache ! ( kind, data)
168
- }
123
+ let cache = read_cache ( kind, & src_index_digest) . await ;
169
124
170
- #[ cfg( target_family = "wasm" ) ]
171
- async fn make_with_ext_cache ( kind : Kind , data : & str ) -> VerifierIndex < Fq > {
172
- make_with_ext_cache ! ( kind, data)
125
+ match cache {
126
+ Ok ( verifier_index) => {
127
+ info ! ( system_time( ) ; "Verifier index is loaded" ) ;
128
+ verifier_index
129
+ }
130
+ Err ( err) => {
131
+ warn ! ( system_time( ) ; "Cannot load verifier index: {err}" ) ;
132
+ let index = make_verifier_index ( verifier_index) ;
133
+ #[ cfg( not( target_family = "wasm" ) ) ]
134
+ if let Err ( err) = write_cache ( kind, & index, & src_index_digest) {
135
+ warn ! ( system_time( ) ; "Cannot store verifier index to cache file: {err}" ) ;
136
+ } else {
137
+ info ! ( system_time( ) ; "Stored verifier index to cache file" ) ;
138
+ }
139
+ index
140
+ }
141
+ }
173
142
}
174
143
175
144
#[ derive( Serialize , Deserialize , Debug , Clone ) ]
@@ -215,23 +184,8 @@ impl TransactionVerifier {
215
184
}
216
185
}
217
186
218
- #[ cfg( not( target_family = "wasm" ) ) ]
219
- impl BlockVerifier {
220
- pub fn make ( ) -> Self {
221
- BLOCK_VERIFIER
222
- . get_or_init ( || {
223
- Self ( Arc :: new ( make_with_ext_cache (
224
- Self :: kind ( ) ,
225
- Self :: src_json ( ) ,
226
- ) ) )
227
- } )
228
- . clone ( )
229
- }
230
- }
231
-
232
- #[ cfg( target_family = "wasm" ) ]
233
187
impl BlockVerifier {
234
- async fn make_impl ( ) -> Self {
188
+ pub async fn make_async ( ) -> Self {
235
189
if let Some ( v) = BLOCK_VERIFIER . get ( ) {
236
190
v. clone ( )
237
191
} else {
@@ -242,33 +196,14 @@ impl BlockVerifier {
242
196
}
243
197
}
244
198
245
- #[ cfg( not( test) ) ]
246
- pub async fn make ( ) -> Self {
247
- Self :: make_impl ( ) . await
248
- }
249
- #[ cfg( test) ]
250
- pub fn make ( ) -> Self {
251
- tokio:: runtime:: Handle :: current ( ) . block_on ( async { Self :: make_impl ( ) . await } )
252
- }
253
- }
254
-
255
- #[ cfg( not( target_family = "wasm" ) ) ]
256
- impl TransactionVerifier {
199
+ #[ cfg( not( target_family = "wasm" ) ) ]
257
200
pub fn make ( ) -> Self {
258
- TX_VERIFIER
259
- . get_or_init ( || {
260
- Self ( Arc :: new ( make_with_ext_cache (
261
- Self :: kind ( ) ,
262
- Self :: src_json ( ) ,
263
- ) ) )
264
- } )
265
- . clone ( )
201
+ super :: provers:: block_on ( Self :: make_async ( ) )
266
202
}
267
203
}
268
204
269
- #[ cfg( target_family = "wasm" ) ]
270
205
impl TransactionVerifier {
271
- pub async fn make ( ) -> Self {
206
+ pub async fn make_async ( ) -> Self {
272
207
if let Some ( v) = TX_VERIFIER . get ( ) {
273
208
v. clone ( )
274
209
} else {
@@ -278,6 +213,11 @@ impl TransactionVerifier {
278
213
TX_VERIFIER . get_or_init ( move || verifier) . clone ( )
279
214
}
280
215
}
216
+
217
+ #[ cfg( not( target_family = "wasm" ) ) ]
218
+ pub fn make ( ) -> Self {
219
+ super :: provers:: block_on ( Self :: make_async ( ) )
220
+ }
281
221
}
282
222
283
223
impl std:: ops:: Deref for BlockVerifier {
0 commit comments