Skip to content

Commit

Permalink
Merge pull request #19 from zkemail/feat/gpu_prover
Browse files Browse the repository at this point in the history
Feat/gpu prover
  • Loading branch information
Bisht13 authored Jan 6, 2025
2 parents df43ae9 + 3b255ec commit d5564d3
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ slog-term = "2.9.0"
slog-json = "2.6.1"
lazy_static = "1.4"
file-rotate = "0.7.5"
regex = "=1.10.6"
regex = "1.10.6"
mailparse = "0.15.0"
wasm-bindgen = "0.2.95"
wasm-bindgen-futures = "0.4.45"
Expand Down
47 changes: 47 additions & 0 deletions src/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub struct ProverRes {
/// The proof in JSON format.
proof: ProofJson,
/// The public signals associated with the proof.
#[serde(alias = "publicOutputs")]
pub_signals: Vec<String>,
}

Expand Down Expand Up @@ -104,3 +105,49 @@ pub async fn generate_proof(

Ok((proof, pub_signals))
}

pub async fn generate_proof_gpu(
input: &str,
blueprint_id: &str,
proof_id: &str,
zkey_download_url: &str,
circuit_cpp_download_url: &str,
api_key: &str,
prover_url: &str,
) -> Result<(Bytes, Vec<U256>)> {
let client = reqwest::Client::new();

// Parse input string as JSON value
let input_json: serde_json::Value = serde_json::from_str(input)?;

// Send POST request to the prover
let res = client
.post(prover_url)
.header("x-api-key", api_key)
.header("Content-Type", "application/json")
.json(&serde_json::json!({
"blueprintId": blueprint_id,
"proofId": proof_id,
"zkeyDownloadUrl": zkey_download_url,
"circuitCppDownloadUrl": circuit_cpp_download_url,
"input": input_json
}))
.send()
.await?
.error_for_status()?;

// Parse the response JSON
let res_json = res.json::<ProverRes>().await?;

// Convert the proof to Ethereum-compatible bytes
let proof = res_json.proof.to_eth_bytes()?;

// Convert public signals to U256
let pub_signals = res_json
.pub_signals
.into_iter()
.map(|str| U256::from_dec_str(&str).expect("pub signal should be u256"))
.collect();

Ok((proof, pub_signals))
}

0 comments on commit d5564d3

Please sign in to comment.