11use crate :: zk_circuits_handler:: universal:: UniversalHandler ;
22use async_trait:: async_trait;
33use axiom_sdk:: {
4- AxiomConfig , AxiomSdk , ProofType as AxiomProofType , SaveOption ,
4+ AxiomSdk , ProofType as AxiomProofType ,
55 build:: BuildSdk ,
66 input:: Input as AxiomInput ,
77 prove:: { ProveArgs , ProveSdk } ,
@@ -23,17 +23,22 @@ use scroll_zkvm_types::{
2323 proof:: { OpenVmEvmProof , OpenVmVersionedVmStarkProof , ProofEnum } ,
2424} ;
2525use serde:: { Deserialize , Serialize } ;
26- use std:: { collections:: HashMap , fs:: File , path:: Path } ;
26+ use std:: { collections:: HashMap , fs:: File , io:: Write , path:: Path } ;
27+ use tempfile:: NamedTempFile ;
2728use tracing:: Level ;
2829
2930#[ derive( Debug , Clone , Serialize , Deserialize ) ]
3031pub struct AxiomProverConfig {
31- #[ serde( rename = "axiom_api_key" ) ]
32- pub api_key : String ,
32+ pub axiom : AxiomConfig ,
3333 pub sdk_config : SdkConfig ,
34+ }
35+
36+ #[ derive( Debug , Clone , Serialize , Deserialize ) ]
37+ pub struct AxiomConfig {
38+ pub api_key : String ,
3439 // vk to program mapping
35- #[ serde( rename = "axiom_programs" ) ]
3640 pub programs : HashMap < String , AxiomProgram > ,
41+ pub num_gpus : Option < usize > ,
3742}
3843
3944#[ derive( Debug , Clone , Serialize , Deserialize ) ]
@@ -110,9 +115,9 @@ impl AxiomProver {
110115 config_id : Option < String > ,
111116 req : impl FnOnce ( AxiomSdk ) -> eyre:: Result < R > + Send + ' static ,
112117 ) -> eyre:: Result < R > {
113- let api_key = self . config . api_key . clone ( ) ;
118+ let api_key = self . config . axiom . api_key . clone ( ) ;
114119 tokio:: task:: spawn_blocking ( move || {
115- let config = AxiomConfig {
120+ let config = axiom_sdk :: AxiomConfig {
116121 api_key : Some ( api_key) ,
117122 config_id,
118123 ..Default :: default ( )
@@ -130,6 +135,7 @@ impl AxiomProver {
130135 let vk = hex:: encode ( vk) ;
131136 debug ! ( vk = %vk) ;
132137 self . config
138+ . axiom
133139 . programs
134140 . get ( vk. as_str ( ) )
135141 . cloned ( )
@@ -146,8 +152,13 @@ impl AxiomProver {
146152 let prover_task: ProvingTask = prover_task. into ( ) ;
147153
148154 let program = self . get_program ( & prover_task. vk ) ?;
155+ let num_gpus = self . config . axiom . num_gpus ;
156+
157+ let mut input_file = NamedTempFile :: new ( ) ?;
158+ let input = prover_task. build_openvm_input ( ) ;
159+ serde_json:: to_writer ( & mut input_file, & input) ?;
160+ input_file. flush ( ) ?;
149161
150- let input = serde_json:: to_value ( prover_task. build_openvm_input ( ) ) ?;
151162 let proof_type = if req. proof_type == ProofType :: Bundle {
152163 AxiomProofType :: Evm
153164 } else {
@@ -165,9 +176,9 @@ impl AxiomProver {
165176 . make_axiom_request ( Some ( program. config_id ) , move |sdk| {
166177 sdk. generate_new_proof ( ProveArgs {
167178 program_id : Some ( program. program_id . clone ( ) ) ,
168- input : Some ( AxiomInput :: Value ( input ) ) ,
179+ input : Some ( AxiomInput :: FilePath ( input_file . path ( ) . to_path_buf ( ) ) ) ,
169180 proof_type : Some ( proof_type) ,
170- num_gpus : Some ( 4 ) ,
181+ num_gpus,
171182 priority : None ,
172183 } )
173184 } )
@@ -208,11 +219,13 @@ impl AxiomProver {
208219
209220 let axiom_proof_type: AxiomProofType = status. proof_type . parse ( ) ?;
210221 let proof = if status. state == "Succeeded" {
211- Some ( sdk. get_generated_proof (
222+ let file = NamedTempFile :: new ( ) ?;
223+ sdk. get_generated_proof (
212224 & status. id ,
213225 & axiom_proof_type,
214- SaveOption :: DoNotSave ,
215- ) ?)
226+ Some ( file. path ( ) . to_path_buf ( ) ) ,
227+ ) ?;
228+ Some ( file)
216229 } else {
217230 None
218231 } ;
@@ -296,14 +309,14 @@ impl AxiomProver {
296309 }
297310 }
298311
299- if let Some ( proof_bytes ) = proof {
312+ if let Some ( proof_file ) = proof {
300313 let proof = match proof_type {
301314 ProofType :: Bundle => {
302- let proof: OpenVmEvmProof = serde_json:: from_slice ( & proof_bytes ) ?;
315+ let proof: OpenVmEvmProof = serde_json:: from_reader ( proof_file ) ?;
303316 ProofEnum :: Evm ( proof. into ( ) )
304317 }
305318 _ => {
306- let proof: OpenVmVersionedVmStarkProof = serde_json:: from_slice ( & proof_bytes ) ?;
319+ let proof: OpenVmVersionedVmStarkProof = serde_json:: from_reader ( proof_file ) ?;
307320 ProofEnum :: Stark ( proof. try_into ( ) ?)
308321 }
309322 } ;
0 commit comments