Skip to content

Commit 190c4fb

Browse files
authored
chore: remove deps on zkm-prover (#60)
* feat: remove zkm prover * fix: polish code * fix steps * chore: code polishing * chore: code polishing
1 parent 5965643 commit 190c4fb

File tree

4 files changed

+24
-27
lines changed

4 files changed

+24
-27
lines changed

sdk/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ zkm-sdk = { git = "https://github.com/zkMIPS/zkm-project-template", branch = "ma
2626

2727
## Don't use the libsnark
2828

29-
1. Set the environment variable `NO_USE_SNARK=true` .
29+
1. Set the environment variable `USE_LOCAL_PROVER=true` .
3030

3131
2. Import the SDK
3232

sdk/build.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
1616
panic!("Go build failed");
1717
}
1818

19-
if let Some(_snark_flag) = std::env::var_os("NO_USE_SNARK") {
19+
if std::env::var_os("USE_LOCAL_PROVER").is_some() {
2020
tonic_build::configure()
2121
.protoc_arg("--experimental_allow_proto3_optional")
2222
.compile(&["src/proto/stage.proto"], &["src/proto"])?;

sdk/src/network/prover.rs

+20-23
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use ethers::signers::{LocalWallet, Signer};
1212
use tokio::time::sleep;
1313
use tokio::time::Duration;
1414

15+
use anyhow::{bail, Result};
1516
use async_trait::async_trait;
1617

1718
#[derive(Clone)]
@@ -24,7 +25,7 @@ pub mod stage_service {
2425
tonic::include_proto!("stage.v1");
2526
}
2627

27-
use crate::network::prover::stage_service::Status;
28+
use crate::network::prover::stage_service::{Status, Step};
2829

2930
pub struct NetworkProver {
3031
pub stage_client: StageServiceClient<Channel>,
@@ -83,7 +84,7 @@ impl NetworkProver {
8384
request.signature = signature.to_string();
8485
}
8586

86-
pub async fn download_file(url: &str) -> anyhow::Result<Vec<u8>> {
87+
pub async fn download_file(url: &str) -> Result<Vec<u8>> {
8788
let response = reqwest::get(url).await?;
8889
let content = response.bytes().await?;
8990
Ok(content.to_vec())
@@ -92,7 +93,7 @@ impl NetworkProver {
9293

9394
#[async_trait]
9495
impl Prover for NetworkProver {
95-
async fn request_proof<'a>(&self, input: &'a ProverInput) -> anyhow::Result<String> {
96+
async fn request_proof<'a>(&self, input: &'a ProverInput) -> Result<String> {
9697
let proof_id = uuid::Uuid::new_v4().to_string();
9798
let mut request = GenerateProofRequest {
9899
proof_id: proof_id.clone(),
@@ -120,7 +121,7 @@ impl Prover for NetworkProver {
120121
&self,
121122
proof_id: &'a str,
122123
timeout: Option<Duration>,
123-
) -> anyhow::Result<Option<ProverResult>> {
124+
) -> Result<Option<ProverResult>> {
124125
let start_time = Instant::now();
125126
let mut split_start_time = Instant::now();
126127
let mut split_end_time = Instant::now();
@@ -129,7 +130,7 @@ impl Prover for NetworkProver {
129130
loop {
130131
if let Some(timeout) = timeout {
131132
if start_time.elapsed() > timeout {
132-
return Err(anyhow::anyhow!("Proof generation timed out."));
133+
bail!("Proof generation timed out.");
133134
}
134135
}
135136

@@ -139,25 +140,27 @@ impl Prover for NetworkProver {
139140
match Status::from_i32(get_status_response.status as i32) {
140141
Some(Status::Computing) => {
141142
//log::info!("generate_proof step: {}", get_status_response.step);
142-
match get_status_response.step {
143-
0 => log::info!("generate_proof : queuing the task."),
144-
1 => {
143+
match Step::from_i32(get_status_response.step) {
144+
Some(Step::Init) => log::info!("generate_proof : queuing the task."),
145+
Some(Step::InSplit) => {
145146
if last_step == 0 {
146147
split_start_time = Instant::now();
147148
}
148149
log::info!("generate_proof : splitting the task.");
149150
}
150-
2 => {
151+
Some(Step::InProve) => {
151152
if last_step == 1 {
152153
split_end_time = Instant::now();
153154
}
154155
log::info!("generate_proof : proving the task.");
155156
}
156-
3 => log::info!("generate_proof : aggregating the proof."),
157-
4 => log::info!("generate_proof : aggregating the proof."),
158-
5 => log::info!("generate_proof : finalizing the proof."),
159-
6 => log::info!("generate_proof : completing the proof."),
160-
i32::MIN..=-1_i32 | 7_i32..=i32::MAX => todo!(),
157+
Some(Step::InAgg) => log::info!("generate_proof : aggregating the proof."),
158+
Some(Step::InAggAll) => {
159+
log::info!("generate_proof : aggregating the proof.")
160+
}
161+
Some(Step::InFinal) => log::info!("generate_proof : finalizing the proof."),
162+
Some(Step::End) => log::info!("generate_proof : completing the proof."),
163+
None => todo!(),
161164
}
162165
last_step = get_status_response.step;
163166
sleep(Duration::from_secs(30)).await;
@@ -195,11 +198,7 @@ impl Prover for NetworkProver {
195198
}
196199
_ => {
197200
log::error!("generate_proof failed status: {}", get_status_response.status);
198-
//return Ok(None);
199-
return Err(anyhow::anyhow!(
200-
"generate_proof failed status: {}",
201-
get_status_response.status
202-
));
201+
bail!("generate_proof failed status: {}", get_status_response.status);
203202
}
204203
}
205204
}
@@ -210,17 +209,15 @@ impl Prover for NetworkProver {
210209
_vk_path: &'a str,
211210
_input: &'a ProverInput,
212211
_timeout: Option<Duration>,
213-
) -> anyhow::Result<()> {
214-
log::info!("The proof network does not support the method.");
215-
212+
) -> Result<()> {
216213
panic!("The proof network does not support the method!");
217214
}
218215

219216
async fn prove<'a>(
220217
&self,
221218
input: &'a ProverInput,
222219
timeout: Option<Duration>,
223-
) -> anyhow::Result<Option<ProverResult>> {
220+
) -> Result<Option<ProverResult>> {
224221
log::info!("calling request_proof.");
225222
let proof_id = self.request_proof(input).await?;
226223
log::info!("calling wait_proof, proof_id={}", proof_id);

sdk/src/proto/stage.proto

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ message GetStatusResponse {
7474
string stark_proof_url = 5;
7575
string solidity_verifier_url = 6;
7676
bytes output_stream = 7;
77-
int32 step = 8; // Step
77+
Step step = 8; // Step
7878
string public_values_url = 9;
7979
uint64 total_steps = 10;
8080
bytes receipt = 11;
8181
bytes elf_id = 12;
82-
}
82+
}

0 commit comments

Comments
 (0)