@@ -7,7 +7,7 @@ use axum::{
7
7
routing:: { get, post} ,
8
8
Json , Router ,
9
9
} ;
10
- use log:: info;
10
+ use log:: { error , info} ;
11
11
use op_succinct_client_utils:: {
12
12
boot:: { hash_rollup_config, BootInfoStruct } ,
13
13
types:: u32_to_u8,
@@ -121,7 +121,13 @@ async fn request_span_proof(
121
121
Json ( payload) : Json < SpanProofRequest > ,
122
122
) -> Result < ( StatusCode , Json < ProofResponse > ) , AppError > {
123
123
info ! ( "Received span proof request: {:?}" , payload) ;
124
- let fetcher = OPSuccinctDataFetcher :: new_with_rollup_config ( RunContext :: Docker ) . await ?;
124
+ let fetcher = match OPSuccinctDataFetcher :: new_with_rollup_config ( RunContext :: Docker ) . await {
125
+ Ok ( f) => f,
126
+ Err ( e) => {
127
+ error ! ( "Failed to create data fetcher: {}" , e) ;
128
+ return Err ( AppError ( e) ) ;
129
+ }
130
+ } ;
125
131
126
132
let host_cli = match fetcher
127
133
. get_host_cli_args (
@@ -134,7 +140,7 @@ async fn request_span_proof(
134
140
{
135
141
Ok ( cli) => cli,
136
142
Err ( e) => {
137
- log :: error!( "Failed to get host CLI args: {}" , e) ;
143
+ error ! ( "Failed to get host CLI args: {}" , e) ;
138
144
return Err ( AppError ( anyhow:: anyhow!(
139
145
"Failed to get host CLI args: {}" ,
140
146
e
@@ -147,15 +153,15 @@ async fn request_span_proof(
147
153
// host, and return an ID that the client can poll on to check if the proof was submitted.
148
154
let mut witnessgen_executor = WitnessGenExecutor :: new ( WITNESSGEN_TIMEOUT , RunContext :: Docker ) ;
149
155
if let Err ( e) = witnessgen_executor. spawn_witnessgen ( & host_cli) . await {
150
- log :: error!( "Failed to spawn witness generation: {}" , e) ;
156
+ error ! ( "Failed to spawn witness generation: {}" , e) ;
151
157
return Err ( AppError ( anyhow:: anyhow!(
152
158
"Failed to spawn witness generation: {}" ,
153
159
e
154
160
) ) ) ;
155
161
}
156
162
// Log any errors from running the witness generation process.
157
163
if let Err ( e) = witnessgen_executor. flush ( ) . await {
158
- log :: error!( "Failed to generate witness: {}" , e) ;
164
+ error ! ( "Failed to generate witness: {}" , e) ;
159
165
return Err ( AppError ( anyhow:: anyhow!(
160
166
"Failed to generate witness: {}" ,
161
167
e
@@ -165,7 +171,7 @@ async fn request_span_proof(
165
171
let sp1_stdin = match get_proof_stdin ( & host_cli) {
166
172
Ok ( stdin) => stdin,
167
173
Err ( e) => {
168
- log :: error!( "Failed to get proof stdin: {}" , e) ;
174
+ error ! ( "Failed to get proof stdin: {}" , e) ;
169
175
return Err ( AppError ( anyhow:: anyhow!(
170
176
"Failed to get proof stdin: {}" ,
171
177
e
@@ -176,7 +182,7 @@ async fn request_span_proof(
176
182
let private_key = match env:: var ( "SP1_PRIVATE_KEY" ) {
177
183
Ok ( private_key) => private_key,
178
184
Err ( e) => {
179
- log :: error!( "Failed to get SP1 private key: {}" , e) ;
185
+ error ! ( "Failed to get SP1 private key: {}" , e) ;
180
186
return Err ( AppError ( anyhow:: anyhow!(
181
187
"Failed to get SP1 private key: {}" ,
182
188
e
@@ -186,7 +192,7 @@ async fn request_span_proof(
186
192
let rpc_url = match env:: var ( "PROVER_NETWORK_RPC" ) {
187
193
Ok ( rpc_url) => rpc_url,
188
194
Err ( e) => {
189
- log :: error!( "Failed to get PROVER_NETWORK_RPC: {}" , e) ;
195
+ error ! ( "Failed to get PROVER_NETWORK_RPC: {}" , e) ;
190
196
return Err ( AppError ( anyhow:: anyhow!(
191
197
"Failed to get PROVER_NETWORK_RPC: {}" ,
192
198
e
@@ -205,7 +211,7 @@ async fn request_span_proof(
205
211
{
206
212
Ok ( vk_hash) => vk_hash,
207
213
Err ( e) => {
208
- log :: error!( "Failed to register program: {}" , e) ;
214
+ error ! ( "Failed to register program: {}" , e) ;
209
215
return Err ( AppError ( anyhow:: anyhow!(
210
216
"Failed to register program: {}" ,
211
217
e
@@ -224,7 +230,7 @@ async fn request_span_proof(
224
230
{
225
231
Ok ( proof_id) => proof_id,
226
232
Err ( e) => {
227
- log :: error!( "Failed to request proof: {}" , e) ;
233
+ error ! ( "Failed to request proof: {}" , e) ;
228
234
return Err ( AppError ( anyhow:: anyhow!( "Failed to request proof: {}" , e) ) ) ;
229
235
}
230
236
} ;
@@ -263,14 +269,18 @@ async fn request_agg_proof(
263
269
) ?;
264
270
let l1_head: [ u8 ; 32 ] = l1_head_bytes. try_into ( ) . unwrap ( ) ;
265
271
266
- let fetcher = OPSuccinctDataFetcher :: new_with_rollup_config ( RunContext :: Docker ) . await ?;
267
- let res = fetcher
272
+ let fetcher = match OPSuccinctDataFetcher :: new_with_rollup_config ( RunContext :: Docker ) . await {
273
+ Ok ( f) => f,
274
+ Err ( e) => return Err ( AppError ( anyhow:: anyhow!( "Failed to create fetcher: {}" , e) ) ) ,
275
+ } ;
276
+
277
+ let headers = match fetcher
268
278
. get_header_preimages ( & boot_infos, l1_head. into ( ) )
269
- . await ;
270
- let headers = match res {
271
- Ok ( headers ) => headers ,
279
+ . await
280
+ {
281
+ Ok ( h ) => h ,
272
282
Err ( e) => {
273
- log :: error!( "Failed to get header preimages: {}" , e) ;
283
+ error ! ( "Failed to get header preimages: {}" , e) ;
274
284
return Err ( AppError ( anyhow:: anyhow!(
275
285
"Failed to get header preimages: {}" ,
276
286
e
@@ -286,42 +296,39 @@ async fn request_agg_proof(
286
296
287
297
let stdin =
288
298
match get_agg_proof_stdin ( proofs, boot_infos, headers, & state. range_vk , l1_head. into ( ) ) {
289
- Ok ( stdin ) => stdin ,
299
+ Ok ( s ) => s ,
290
300
Err ( e) => {
291
- log :: error!( "Failed to get agg proof stdin: {}" , e) ;
301
+ error ! ( "Failed to get agg proof stdin: {}" , e) ;
292
302
return Err ( AppError ( anyhow:: anyhow!(
293
303
"Failed to get agg proof stdin: {}" ,
294
304
e
295
305
) ) ) ;
296
306
}
297
307
} ;
298
308
299
- let res = prover. register_program ( & state. agg_vk , AGG_ELF ) . await ;
300
- let vk_hash = match res {
309
+ let vk_hash = match prover. register_program ( & state. agg_vk , AGG_ELF ) . await {
301
310
Ok ( vk_hash) => vk_hash,
302
311
Err ( e) => {
303
- log :: error!( "Failed to register program: {}" , e) ;
312
+ error ! ( "Failed to register program: {}" , e) ;
304
313
return Err ( AppError ( anyhow:: anyhow!(
305
314
"Failed to register program: {}" ,
306
315
e
307
316
) ) ) ;
308
317
}
309
318
} ;
310
- let res = prover
319
+ let proof_id = match prover
311
320
. request_proof (
312
321
& vk_hash,
313
322
& stdin,
314
323
ProofMode :: Groth16 ,
315
324
1_000_000_000_000 ,
316
325
None ,
317
326
)
318
- . await ;
319
-
320
- // Check if error, otherwise get proof ID.
321
- let proof_id = match res {
322
- Ok ( proof_id) => proof_id,
327
+ . await
328
+ {
329
+ Ok ( id) => id,
323
330
Err ( e) => {
324
- log :: error!( "Failed to request proof: {}" , e) ;
331
+ error ! ( "Failed to request proof: {}" , e) ;
325
332
return Err ( AppError ( anyhow:: anyhow!( "Failed to request proof: {}" , e) ) ) ;
326
333
}
327
334
} ;
@@ -335,33 +342,54 @@ async fn request_mock_span_proof(
335
342
Json ( payload) : Json < SpanProofRequest > ,
336
343
) -> Result < ( StatusCode , Json < ProofStatus > ) , AppError > {
337
344
info ! ( "Received mock span proof request: {:?}" , payload) ;
338
- let fetcher = OPSuccinctDataFetcher :: new_with_rollup_config ( RunContext :: Docker ) . await ?;
345
+ let fetcher = match OPSuccinctDataFetcher :: new_with_rollup_config ( RunContext :: Docker ) . await {
346
+ Ok ( f) => f,
347
+ Err ( e) => {
348
+ error ! ( "Failed to create data fetcher: {}" , e) ;
349
+ return Err ( AppError ( e) ) ;
350
+ }
351
+ } ;
339
352
340
- let host_cli = fetcher
353
+ let host_cli = match fetcher
341
354
. get_host_cli_args (
342
355
payload. start ,
343
356
payload. end ,
344
357
ProgramType :: Multi ,
345
358
CacheMode :: DeleteCache ,
346
359
)
347
- . await ?;
360
+ . await
361
+ {
362
+ Ok ( cli) => cli,
363
+ Err ( e) => {
364
+ error ! ( "Failed to get host CLI args: {}" , e) ;
365
+ return Err ( AppError ( e) ) ;
366
+ }
367
+ } ;
348
368
349
369
// Start the server and native client with a timeout.
350
370
// Note: Ideally, the server should call out to a separate process that executes the native
351
371
// host, and return an ID that the client can poll on to check if the proof was submitted.
352
372
let mut witnessgen_executor = WitnessGenExecutor :: new ( WITNESSGEN_TIMEOUT , RunContext :: Docker ) ;
353
- witnessgen_executor. spawn_witnessgen ( & host_cli) . await ?;
373
+ if let Err ( e) = witnessgen_executor. spawn_witnessgen ( & host_cli) . await {
374
+ error ! ( "Failed to spawn witness generator: {}" , e) ;
375
+ return Err ( AppError ( e) ) ;
376
+ }
354
377
// Log any errors from running the witness generation process.
355
- let res = witnessgen_executor. flush ( ) . await ;
356
- if let Err ( e) = res {
357
- log:: error!( "Failed to generate witness: {}" , e) ;
378
+ if let Err ( e) = witnessgen_executor. flush ( ) . await {
379
+ error ! ( "Failed to generate witness: {}" , e) ;
358
380
return Err ( AppError ( anyhow:: anyhow!(
359
381
"Failed to generate witness: {}" ,
360
382
e
361
383
) ) ) ;
362
384
}
363
385
364
- let sp1_stdin = get_proof_stdin ( & host_cli) ?;
386
+ let sp1_stdin = match get_proof_stdin ( & host_cli) {
387
+ Ok ( stdin) => stdin,
388
+ Err ( e) => {
389
+ error ! ( "Failed to get proof stdin: {}" , e) ;
390
+ return Err ( AppError ( e) ) ;
391
+ }
392
+ } ;
365
393
366
394
let prover = ProverClient :: mock ( ) ;
367
395
let proof = prover
@@ -404,30 +432,62 @@ async fn request_mock_agg_proof(
404
432
. map ( |proof| proof. proof . clone ( ) )
405
433
. collect ( ) ;
406
434
407
- let l1_head_bytes = hex:: decode (
435
+ let l1_head_bytes = match hex:: decode (
408
436
payload
409
437
. head
410
438
. strip_prefix ( "0x" )
411
439
. expect ( "Invalid L1 head, no 0x prefix." ) ,
412
- ) ?;
440
+ ) {
441
+ Ok ( bytes) => bytes,
442
+ Err ( e) => {
443
+ error ! ( "Failed to decode L1 head: {}" , e) ;
444
+ return Err ( AppError ( anyhow:: anyhow!( "Failed to decode L1 head: {}" , e) ) ) ;
445
+ }
446
+ } ;
413
447
let l1_head: [ u8 ; 32 ] = l1_head_bytes. try_into ( ) . unwrap ( ) ;
414
448
415
- let fetcher = OPSuccinctDataFetcher :: new_with_rollup_config ( RunContext :: Docker ) . await ?;
416
- let headers = fetcher
449
+ let fetcher = match OPSuccinctDataFetcher :: new_with_rollup_config ( RunContext :: Docker ) . await {
450
+ Ok ( f) => f,
451
+ Err ( e) => {
452
+ error ! ( "Failed to create data fetcher: {}" , e) ;
453
+ return Err ( AppError ( e) ) ;
454
+ }
455
+ } ;
456
+ let headers = match fetcher
417
457
. get_header_preimages ( & boot_infos, l1_head. into ( ) )
418
- . await ?;
458
+ . await
459
+ {
460
+ Ok ( h) => h,
461
+ Err ( e) => {
462
+ error ! ( "Failed to get header preimages: {}" , e) ;
463
+ return Err ( AppError ( e) ) ;
464
+ }
465
+ } ;
419
466
420
467
let prover = ProverClient :: mock ( ) ;
421
468
422
469
let stdin =
423
- get_agg_proof_stdin ( proofs, boot_infos, headers, & state. range_vk , l1_head. into ( ) ) . unwrap ( ) ;
470
+ match get_agg_proof_stdin ( proofs, boot_infos, headers, & state. range_vk , l1_head. into ( ) ) {
471
+ Ok ( s) => s,
472
+ Err ( e) => {
473
+ error ! ( "Failed to get aggregation proof stdin: {}" , e) ;
474
+ return Err ( AppError ( e) ) ;
475
+ }
476
+ } ;
424
477
425
478
// Simulate the mock proof. proof.bytes() returns an empty byte array for mock proofs.
426
- let proof = prover
479
+ let proof = match prover
427
480
. prove ( & state. agg_pk , stdin)
428
481
. set_skip_deferred_proof_verification ( true )
429
482
. groth16 ( )
430
- . run ( ) ?;
483
+ . run ( )
484
+ {
485
+ Ok ( p) => p,
486
+ Err ( e) => {
487
+ error ! ( "Failed to generate proof: {}" , e) ;
488
+ return Err ( AppError ( e) ) ;
489
+ }
490
+ } ;
431
491
432
492
Ok ( (
433
493
StatusCode :: OK ,
0 commit comments