3
3
#[ cfg( feature = "bonsai-auto-scaling" ) ]
4
4
use crate :: bonsai:: auto_scaling:: shutdown_bonsai;
5
5
use crate :: {
6
- methods:: risc0_aggregation:: RISC0_AGGREGATION_ELF ,
7
- methods:: risc0_guest:: { RISC0_GUEST_ELF , RISC0_GUEST_ID } ,
6
+ methods:: risc0_aggregation:: RISC0_AGGREGATION_ELF , methods :: risc0_batch :: RISC0_BATCH_ELF ,
7
+ methods:: risc0_guest:: RISC0_GUEST_ELF ,
8
8
} ;
9
9
use alloy_primitives:: { hex:: ToHexExt , B256 } ;
10
10
use bonsai:: { cancel_proof, maybe_prove} ;
@@ -18,8 +18,10 @@ use raiko_lib::{
18
18
prover:: { IdStore , IdWrite , Proof , ProofKey , Prover , ProverConfig , ProverError , ProverResult } ,
19
19
} ;
20
20
use risc0_zkvm:: {
21
- compute_image_id, default_prover, serde:: to_vec, sha:: Digestible , ExecutorEnv , ProverOpts ,
22
- Receipt ,
21
+ compute_image_id, default_prover,
22
+ serde:: to_vec,
23
+ sha:: { Digest , Digestible } ,
24
+ ExecutorEnv , ProverOpts , Receipt ,
23
25
} ;
24
26
use serde:: { Deserialize , Serialize } ;
25
27
use serde_with:: serde_as;
@@ -92,7 +94,7 @@ impl Prover for Risc0Prover {
92
94
. await ?;
93
95
94
96
let proof_gen_result = if config. snark && config. bonsai {
95
- bonsai:: bonsai_stark_to_snark ( uuid, receipt, output. hash )
97
+ bonsai:: bonsai_stark_to_snark ( uuid, receipt, output. hash , RISC0_GUEST_ELF )
96
98
. await
97
99
. map ( |r0_response| r0_response. into ( ) )
98
100
. map_err ( |e| ProverError :: GuestError ( e. to_string ( ) ) )
@@ -147,11 +149,16 @@ impl Prover for Risc0Prover {
147
149
. iter ( )
148
150
. map ( |proof| proof. input . unwrap ( ) )
149
151
. collect :: < Vec < _ > > ( ) ;
152
+
153
+ let input_proof_hex_str = input. proofs [ 0 ] . proof . as_ref ( ) . unwrap ( ) ;
154
+ let input_proof_bytes = hex:: decode ( & input_proof_hex_str[ 2 ..] ) . unwrap ( ) ;
155
+ let input_image_id_bytes: [ u8 ; 32 ] = input_proof_bytes[ 32 ..64 ] . try_into ( ) . unwrap ( ) ;
156
+ let input_proof_image_id = Digest :: from ( input_image_id_bytes) ;
150
157
let input = ZkAggregationGuestInput {
151
- image_id : RISC0_GUEST_ID ,
158
+ image_id : input_proof_image_id . as_words ( ) . try_into ( ) . unwrap ( ) ,
152
159
block_inputs,
153
160
} ;
154
- info ! ( "Start aggregate proofs" ) ;
161
+
155
162
// add_assumption makes the receipt to be verified available to the prover.
156
163
let env = {
157
164
let mut env = ExecutorEnv :: builder ( ) ;
@@ -171,10 +178,9 @@ impl Prover for Risc0Prover {
171
178
"Generate aggregation receipt journal: {:?}" ,
172
179
alloy_primitives:: hex:: encode_prefixed( receipt. journal. bytes. clone( ) )
173
180
) ;
174
- let block_proof_image_id = compute_image_id ( RISC0_GUEST_ELF ) . unwrap ( ) ;
175
181
let aggregation_image_id = compute_image_id ( RISC0_AGGREGATION_ELF ) . unwrap ( ) ;
176
182
let proof_data = snarks:: verify_aggregation_groth16_proof (
177
- block_proof_image_id ,
183
+ input_proof_image_id ,
178
184
aggregation_image_id,
179
185
receipt. clone ( ) ,
180
186
)
@@ -220,12 +226,60 @@ impl Prover for Risc0Prover {
220
226
}
221
227
222
228
async fn batch_run (
223
- _input : GuestBatchInput ,
224
- _output : & GuestBatchOutput ,
225
- _config : & ProverConfig ,
226
- _store : Option < & mut dyn IdWrite > ,
229
+ input : GuestBatchInput ,
230
+ output : & GuestBatchOutput ,
231
+ config : & ProverConfig ,
232
+ id_store : Option < & mut dyn IdWrite > ,
227
233
) -> ProverResult < Proof > {
228
- unimplemented ! ( ) ;
234
+ let mut id_store = id_store;
235
+ let config = Risc0Param :: deserialize ( config. get ( "risc0" ) . unwrap ( ) ) . unwrap ( ) ;
236
+ let proof_key = (
237
+ input. taiko . chain_spec . chain_id ,
238
+ input. taiko . batch_id ,
239
+ output. hash ,
240
+ ProofType :: Risc0 as u8 ,
241
+ ) ;
242
+
243
+ let encoded_input = to_vec ( & input) . expect ( "Could not serialize proving input!" ) ;
244
+
245
+ let ( uuid, receipt) = maybe_prove :: < GuestBatchInput , B256 > (
246
+ & config,
247
+ encoded_input,
248
+ RISC0_BATCH_ELF ,
249
+ & output. hash ,
250
+ ( Vec :: < Receipt > :: new ( ) , Vec :: new ( ) ) ,
251
+ proof_key,
252
+ & mut id_store,
253
+ )
254
+ . await ?;
255
+
256
+ let proof_gen_result = if config. snark && config. bonsai {
257
+ bonsai:: bonsai_stark_to_snark ( uuid, receipt, output. hash , RISC0_BATCH_ELF )
258
+ . await
259
+ . map ( |r0_response| r0_response. into ( ) )
260
+ . map_err ( |e| ProverError :: GuestError ( e. to_string ( ) ) )
261
+ } else {
262
+ if !config. snark {
263
+ warn ! ( "proof is not in snark mode, please check." ) ;
264
+ }
265
+ Ok ( Risc0Response {
266
+ proof : receipt. journal . encode_hex_with_prefix ( ) ,
267
+ receipt : serde_json:: to_string ( & receipt) . unwrap ( ) ,
268
+ uuid,
269
+ input : output. hash ,
270
+ }
271
+ . into ( ) )
272
+ } ;
273
+
274
+ #[ cfg( feature = "bonsai-auto-scaling" ) ]
275
+ if config. bonsai {
276
+ // shutdown bonsai
277
+ shutdown_bonsai ( )
278
+ . await
279
+ . map_err ( |e| ProverError :: GuestError ( e. to_string ( ) ) ) ?;
280
+ }
281
+
282
+ proof_gen_result
229
283
}
230
284
}
231
285
0 commit comments