Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove deps on zkm-prover #60

Merged
merged 6 commits into from
Mar 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ zkm-sdk = { git = "https://github.com/zkMIPS/zkm-project-template", branch = "ma

## Don't use the libsnark

1. Set the environment variable `NO_USE_SNARK=true` .
1. Set the environment variable `USE_LOCAL_PROVER=true` .

2. Import the SDK

Expand Down
2 changes: 1 addition & 1 deletion sdk/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
panic!("Go build failed");
}

if let Some(_snark_flag) = std::env::var_os("NO_USE_SNARK") {
if std::env::var_os("USE_LOCAL_PROVER").is_some() {
tonic_build::configure()
.protoc_arg("--experimental_allow_proto3_optional")
.compile(&["src/proto/stage.proto"], &["src/proto"])?;
Expand Down
43 changes: 20 additions & 23 deletions sdk/src/network/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use ethers::signers::{LocalWallet, Signer};
use tokio::time::sleep;
use tokio::time::Duration;

use anyhow::{bail, Result};
use async_trait::async_trait;

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

use crate::network::prover::stage_service::Status;
use crate::network::prover::stage_service::{Status, Step};

pub struct NetworkProver {
pub stage_client: StageServiceClient<Channel>,
Expand Down Expand Up @@ -83,7 +84,7 @@ impl NetworkProver {
request.signature = signature.to_string();
}

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

#[async_trait]
impl Prover for NetworkProver {
async fn request_proof<'a>(&self, input: &'a ProverInput) -> anyhow::Result<String> {
async fn request_proof<'a>(&self, input: &'a ProverInput) -> Result<String> {
let proof_id = uuid::Uuid::new_v4().to_string();
let mut request = GenerateProofRequest {
proof_id: proof_id.clone(),
Expand Down Expand Up @@ -120,7 +121,7 @@ impl Prover for NetworkProver {
&self,
proof_id: &'a str,
timeout: Option<Duration>,
) -> anyhow::Result<Option<ProverResult>> {
) -> Result<Option<ProverResult>> {
let start_time = Instant::now();
let mut split_start_time = Instant::now();
let mut split_end_time = Instant::now();
Expand All @@ -129,7 +130,7 @@ impl Prover for NetworkProver {
loop {
if let Some(timeout) = timeout {
if start_time.elapsed() > timeout {
return Err(anyhow::anyhow!("Proof generation timed out."));
bail!("Proof generation timed out.");
}
}

Expand All @@ -139,25 +140,27 @@ impl Prover for NetworkProver {
match Status::from_i32(get_status_response.status as i32) {
Some(Status::Computing) => {
//log::info!("generate_proof step: {}", get_status_response.step);
match get_status_response.step {
0 => log::info!("generate_proof : queuing the task."),
1 => {
match Step::from_i32(get_status_response.step) {
Some(Step::Init) => log::info!("generate_proof : queuing the task."),
Some(Step::InSplit) => {
if last_step == 0 {
split_start_time = Instant::now();
}
log::info!("generate_proof : splitting the task.");
}
2 => {
Some(Step::InProve) => {
if last_step == 1 {
split_end_time = Instant::now();
}
log::info!("generate_proof : proving the task.");
}
3 => log::info!("generate_proof : aggregating the proof."),
4 => log::info!("generate_proof : aggregating the proof."),
5 => log::info!("generate_proof : finalizing the proof."),
6 => log::info!("generate_proof : completing the proof."),
i32::MIN..=-1_i32 | 7_i32..=i32::MAX => todo!(),
Some(Step::InAgg) => log::info!("generate_proof : aggregating the proof."),
Some(Step::InAggAll) => {
log::info!("generate_proof : aggregating the proof.")
}
Some(Step::InFinal) => log::info!("generate_proof : finalizing the proof."),
Some(Step::End) => log::info!("generate_proof : completing the proof."),
None => todo!(),
}
last_step = get_status_response.step;
sleep(Duration::from_secs(30)).await;
Expand Down Expand Up @@ -195,11 +198,7 @@ impl Prover for NetworkProver {
}
_ => {
log::error!("generate_proof failed status: {}", get_status_response.status);
//return Ok(None);
return Err(anyhow::anyhow!(
"generate_proof failed status: {}",
get_status_response.status
));
bail!("generate_proof failed status: {}", get_status_response.status);
}
}
}
Expand All @@ -210,17 +209,15 @@ impl Prover for NetworkProver {
_vk_path: &'a str,
_input: &'a ProverInput,
_timeout: Option<Duration>,
) -> anyhow::Result<()> {
log::info!("The proof network does not support the method.");

) -> Result<()> {
panic!("The proof network does not support the method!");
}

async fn prove<'a>(
&self,
input: &'a ProverInput,
timeout: Option<Duration>,
) -> anyhow::Result<Option<ProverResult>> {
) -> Result<Option<ProverResult>> {
log::info!("calling request_proof.");
let proof_id = self.request_proof(input).await?;
log::info!("calling wait_proof, proof_id={}", proof_id);
Expand Down
4 changes: 2 additions & 2 deletions sdk/src/proto/stage.proto
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ message GetStatusResponse {
string stark_proof_url = 5;
string solidity_verifier_url = 6;
bytes output_stream = 7;
int32 step = 8; // Step
Step step = 8; // Step
string public_values_url = 9;
uint64 total_steps = 10;
bytes receipt = 11;
bytes elf_id = 12;
}
}
Loading