Skip to content

Commit b763836

Browse files
committed
feat(host): enable zk_any for batch API
1 parent aa6b71c commit b763836

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

host/src/server/api/v3/proof/batch.rs

+19-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::{
44
api::v3::{ProofResponse, Status},
55
handler::prove_many,
66
prove_aggregation,
7-
utils::{is_zk_any_request, to_v3_status},
7+
utils::{draw_for_zk_any_request, fulfill_sp1_params, is_zk_any_request, to_v3_status},
88
},
99
};
1010
use axum::{extract::State, routing::post, Json, Router};
@@ -39,22 +39,33 @@ use utoipa::OpenApi;
3939
/// - risc0 - uses the risc0 prover
4040
async fn batch_handler(
4141
State(actor): State<Actor>,
42-
Json(batch_request_opt): Json<Value>,
42+
Json(mut batch_request_opt): Json<Value>,
4343
) -> HostResult<Status> {
4444
if is_zk_any_request(&batch_request_opt) {
45-
return Ok(Status::Ok {
46-
proof_type: ProofType::Native,
47-
data: ProofResponse::Status {
48-
status: TaskStatus::ZKAnyNotDrawn,
49-
},
50-
});
45+
fulfill_sp1_params(&mut batch_request_opt);
5146
}
5247

5348
let batch_request = {
5449
// Override the existing proof request config from the config file and command line
5550
// options with the request from the client, and convert to a BatchProofRequest.
5651
let mut opts = serde_json::to_value(actor.default_request_config())?;
5752
merge(&mut opts, &batch_request_opt);
53+
54+
// For zk_any request, draw zk proof type based on the block hash.
55+
if is_zk_any_request(&opts) {
56+
match draw_for_zk_any_request(&actor, &opts).await? {
57+
Some(proof_type) => opts["proof_type"] = serde_json::to_value(proof_type).unwrap(),
58+
None => {
59+
return Ok(Status::Ok {
60+
proof_type: ProofType::Native,
61+
data: ProofResponse::Status {
62+
status: TaskStatus::ZKAnyNotDrawn,
63+
},
64+
});
65+
}
66+
}
67+
}
68+
5869
let batch_request_opt: BatchProofRequestOpt = serde_json::from_value(opts)?;
5970
let batch_request: BatchProofRequest = batch_request_opt.try_into()?;
6071

0 commit comments

Comments
 (0)