From e7fda23604cc968cc33e6580c41df970c4a896e4 Mon Sep 17 00:00:00 2001 From: "xander.z" <162873981+xander42280@users.noreply.github.com> Date: Tue, 10 Sep 2024 19:38:47 +0800 Subject: [PATCH] add contract (#8) --- sdk/Cargo.toml | 1 + sdk/src/network/prover.rs | 14 ++++++++++++++ sdk/src/proto/stage.proto | 11 +++++++++++ sdk/src/prover.rs | 3 ++- 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/sdk/Cargo.toml b/sdk/Cargo.toml index 4b5b8e8e..b9e29337 100644 --- a/sdk/Cargo.toml +++ b/sdk/Cargo.toml @@ -27,6 +27,7 @@ plonky2_maybe_rayon = { git = "https://github.com/zkMIPS/plonky2.git", branch = tonic = "0.8.1" prost = "0.11.0" +reqwest = { version = "0.11", features = ["rustls-tls"] } tokio = { version = "1.21.0", features = ["macros", "rt-multi-thread", "signal"] } ethers = "2.0.14" diff --git a/sdk/src/network/prover.rs b/sdk/src/network/prover.rs index 8296d89f..1eb99100 100644 --- a/sdk/src/network/prover.rs +++ b/sdk/src/network/prover.rs @@ -79,6 +79,12 @@ impl NetworkProver { let signature = self.wallet.sign_message(sign_data).await.unwrap(); request.signature = signature.to_string(); } + + pub async fn download_file(url: &str) -> anyhow::Result> { + let response = reqwest::get(url).await?; + let content = response.bytes().await?; + Ok(content.to_vec()) + } } #[async_trait] @@ -121,12 +127,20 @@ impl Prover for NetworkProver { match Status::from_i32(get_status_response.status as i32) { Some(Status::Computing) => { + log::debug!("generate_proof step: {}", get_status_response.step); sleep(Duration::from_secs(2)).await; } Some(Status::Success) => { + let stark_proof = + NetworkProver::download_file(&get_status_response.stark_proof_url).await?; + let solidity_verifier = + NetworkProver::download_file(&get_status_response.solidity_verifier_url) + .await?; let proof_result = ProverResult { output_stream: get_status_response.output_stream, proof_with_public_inputs: get_status_response.proof_with_public_inputs, + stark_proof, + solidity_verifier, }; return Ok(Some(proof_result)); } diff --git a/sdk/src/proto/stage.proto b/sdk/src/proto/stage.proto index c82eda1f..12622398 100644 --- a/sdk/src/proto/stage.proto +++ b/sdk/src/proto/stage.proto @@ -20,6 +20,16 @@ enum Status { FINAL_ERROR = 8; } +enum Step { + Init = 0; + InSplit = 1; + InProve = 2; + InAgg = 3; + InAggAll = 4; + InFinal = 5; + End = 6; +} + message BlockFileItem { string file_name = 1; bytes file_content = 2; @@ -60,4 +70,5 @@ message GetStatusResponse { string stark_proof_url = 5; string solidity_verifier_url = 6; bytes output_stream = 7; + int32 step = 8; // Step } \ No newline at end of file diff --git a/sdk/src/prover.rs b/sdk/src/prover.rs index a28378fe..ad6d3767 100644 --- a/sdk/src/prover.rs +++ b/sdk/src/prover.rs @@ -15,8 +15,9 @@ pub struct ProverInput { #[derive(Debug, Default, Deserialize, Serialize)] pub struct ProverResult { pub output_stream: Vec, - // pub stark_proof: Vec, pub proof_with_public_inputs: Vec, + pub stark_proof: Vec, + pub solidity_verifier: Vec, } #[async_trait]