diff --git a/host-program/src/bin/zkm-prove.rs b/host-program/src/bin/zkm-prove.rs index 431f90c4..4b1b815d 100644 --- a/host-program/src/bin/zkm-prove.rs +++ b/host-program/src/bin/zkm-prove.rs @@ -10,7 +10,10 @@ use std::fs::read; use std::fs::File; use std::path::Path; use std::time::Instant; -use zkm_sdk::{prover::ClientType, prover::ProverInput, prover::ProverResult, ProverClient, prover::InputProcessor}; +use zkm_sdk::{ + prover::ClientType, prover::InputProcessor, prover::ProverInput, prover::ProverResult, + ProverClient, +}; pub const DEFAULT_PROVER_NETWORK_RPC: &str = "https://152.32.186.45:20002"; pub const DEFALUT_PROVER_NETWORK_DOMAIN: &str = "stage"; @@ -21,7 +24,6 @@ pub struct Sha2GoInput; pub struct RevmeInput; pub struct MemAllocVecInput; - #[tokio::main] async fn main() -> Result<(), Box> { env_logger::try_init().unwrap_or_default(); @@ -89,10 +91,10 @@ async fn main() -> Result<(), Box> { guest_input.process(&mut prover_input, args_parameter, json_path); log::info!( "guest program: {}, bincode(pulic_input): {:?} ", - &args[1], &prover_input.public_inputstream + &args[1], + &prover_input.public_inputstream ); - //If the vk or pk doesn't exist, it will run setup(). if zkm_prover.to_lowercase() == *"local".to_string() { let pk_file = format!("{}/proving.key", vk_path); @@ -106,7 +108,10 @@ async fn main() -> Result<(), Box> { } else { //setup the vk and pk for the first running local proving. log::info!("excuting the setup."); - let _ = prover_client.prover.setup(&vk_path, &prover_input, None).await; + let _ = prover_client + .prover + .setup(&vk_path, &prover_input, None) + .await; return Ok(()); } } @@ -117,8 +122,13 @@ async fn main() -> Result<(), Box> { Ok(Some(prover_result)) => { if !execute_only2 { //excute the guest program and generate the proof - process_proof_results(&prover_result, &prover_input, &proof_results_path, &zkm_prover) - .expect("process proof results error"); + process_proof_results( + &prover_result, + &prover_input, + &proof_results_path, + &zkm_prover, + ) + .expect("process proof results error"); } else { //only excute the guest program without proof print_guest_excution_output(&args[1], &prover_result) @@ -153,26 +163,26 @@ fn create_guest_input(guest_program: &String) -> Box { impl InputProcessor for Sha2RustInput { fn process(&self, input: &mut ProverInput, _args: String, _json: String) { - //input.public_inputstream.push(1); + //input.public_inputstream.push(1); let num_bytes: usize = 1024; //Notice! : if this value is small, it will not generate the proof. let pri_input = vec![5u8; num_bytes]; let mut hasher = Sha256::new(); hasher.update(&pri_input); let result = hasher.finalize(); let output: [u8; 32] = result.into(); - + // assume the arg[0] = hash(public input), and the arg[1] = public input. let public_input = output.to_vec(); let mut pub_buf = Vec::new(); bincode::serialize_into(&mut pub_buf, &public_input) .expect("public_input serialization failed"); - + let mut pri_buf = Vec::new(); - bincode::serialize_into(&mut pri_buf, &pri_input).expect("private_input serialization failed"); - + bincode::serialize_into(&mut pri_buf, &pri_input) + .expect("private_input serialization failed"); + input.public_inputstream = pub_buf; input.private_inputstream = pri_buf; - } } @@ -236,26 +246,24 @@ impl InputProcessor for Sha2GoInput { data.input12 = args[1].to_string(); let mut buf = Vec::new(); bincode::serialize_into(&mut buf, &data).expect("serialization failed"); - + input.public_inputstream = buf; - // input.private_inputstream = pri_buf; - + // input.private_inputstream = pri_buf; } } impl InputProcessor for MemAllocVecInput { fn process(&self, _input: &mut ProverInput, _args: String, _json: String) { //do nothing - //Because the guest program has no public inputs or private inputs. + //Because the guest program has no public inputs or private inputs. } } - impl InputProcessor for RevmeInput { fn process(&self, input: &mut ProverInput, _args: String, json: String) { - //json file + //json file input.public_inputstream = read(json).unwrap(); - // input.private_inputstream = pri_buf; + // input.private_inputstream = pri_buf; } } @@ -377,14 +385,13 @@ fn print_guest_excution_output( "mem-alloc-vec" => { log::info!("Executing the guest program successfully without output messages.") } //The guest program outputs nothing. - "revme" => log::info!("Executing the guest program successfully without output messages."), + "revme" => log::info!("Executing the guest program successfully without output messages."), _ => log::info!("Do nothing."), } return Ok(()); } - #[derive(Serialize, Deserialize, Debug)] struct PublicInputs { roots_before: Roots, diff --git a/sdk/src/local/prover.rs b/sdk/src/local/prover.rs index 640e6e92..2526245b 100644 --- a/sdk/src/local/prover.rs +++ b/sdk/src/local/prover.rs @@ -121,15 +121,14 @@ impl Prover for LocalProver { async fn setup<'a>( &self, - vk_path: &'a String, + vk_path: &'a String, input: &'a ProverInput, _timeout: Option, ) -> anyhow::Result<()> { let mut result = ProverResult::default(); //let inputdir = format!("{}/input", vk_path); fs::create_dir_all(&vk_path).unwrap(); - let should_agg = - crate::local::stark::prove_stark(&input, &vk_path, &mut result).unwrap(); + let should_agg = crate::local::stark::prove_stark(&input, &vk_path, &mut result).unwrap(); if !should_agg { log::info!("Setup: generating the stark proof false, please check the SEG_SIZE or other parameters."); return Err(anyhow::anyhow!( @@ -139,7 +138,7 @@ impl Prover for LocalProver { if crate::local::snark::setup(&vk_path) { log::info!("setup successful, the verify key is in the {}", vk_path); return Ok(()); - }else { + } else { return Err(anyhow::anyhow!("snark setup false!")); } } @@ -154,4 +153,4 @@ impl Prover for LocalProver { log::info!("calling wait_proof, proof_id={}", proof_id); self.wait_proof(&proof_id, timeout).await } -} +} \ No newline at end of file diff --git a/sdk/src/local/snark.rs b/sdk/src/local/snark.rs index a7b8620d..88b99a67 100644 --- a/sdk/src/local/snark.rs +++ b/sdk/src/local/snark.rs @@ -24,7 +24,7 @@ pub fn prove_snark(inputdir: &str, outputdir: &str) -> bool { #[cfg(feature = "snark")] pub fn setup(inputdir: &str) -> bool { let inputdir = std::ffi::CString::new(inputdir).unwrap(); - + let ret = unsafe { Setup(inputdir.as_ptr()) }; ret == 0 } diff --git a/sdk/src/network/prover.rs b/sdk/src/network/prover.rs index 5eaa4f5f..81b2e238 100644 --- a/sdk/src/network/prover.rs +++ b/sdk/src/network/prover.rs @@ -6,7 +6,7 @@ use std::time::Instant; use tonic::transport::Endpoint; use tonic::transport::{Channel, ClientTlsConfig}; -use crate::prover::{Prover, ProverInput, ProverResult,ClientType}; +use crate::prover::{ClientType, Prover, ProverInput, ProverResult}; use ethers::signers::{LocalWallet, Signer}; use tokio::time::sleep; use tokio::time::Duration; @@ -26,24 +26,23 @@ pub struct NetworkProver { impl NetworkProver { pub async fn new(client_type: &ClientType) -> anyhow::Result { - /*let endpoint = env::var("ENDPOINT").unwrap_or(DEFAULT_PROVER_NETWORK_RPC.to_string()); - let ca_cert_path = env::var("CA_CERT_PATH").unwrap_or("".to_string()); - let cert_path = env::var("CERT_PATH").unwrap_or("".to_string()); - let key_path = env::var("KEY_PATH").unwrap_or("".to_string()); - let domain_name = - env::var("DOMAIN_NAME").unwrap_or(DEFALUT_PROVER_NETWORK_DOMAIN.to_string()); - let private_key = env::var("PRIVATE_KEY").unwrap_or("".to_string());*/ - - let ssl_config = if client_type.ca_cert_path.is_empty() { None } else { - Some(Config::new(client_type.ca_cert_path.to_owned(), client_type.cert_path.to_owned(), client_type.key_path.to_owned()).await?) + Some( + Config::new( + client_type.ca_cert_path.to_owned(), + client_type.cert_path.to_owned(), + client_type.key_path.to_owned(), + ) + .await?, + ) }; let endpoint = match ssl_config { Some(config) => { - let mut tls_config = ClientTlsConfig::new().domain_name(client_type.domain_name.to_owned()); + let mut tls_config = + ClientTlsConfig::new().domain_name(client_type.domain_name.to_owned()); if let Some(ca_cert) = config.ca_cert { tls_config = tls_config.ca_certificate(ca_cert); } @@ -182,13 +181,14 @@ impl Prover for NetworkProver { async fn setup<'a>( &self, - _vk_path: &'a String, + _vk_path: &'a String, _input: &'a ProverInput, _timeout: Option, ) -> anyhow::Result<()> { log::info!("The proof network does not support the method."); return Err(anyhow::anyhow!( - "The proof network does not support the method!")); + "The proof network does not support the method!" + )); } async fn prove<'a>( @@ -201,4 +201,4 @@ impl Prover for NetworkProver { log::info!("calling wait_proof, proof_id={}", proof_id); self.wait_proof(&proof_id, timeout).await } -} +} \ No newline at end of file diff --git a/sdk/src/prover.rs b/sdk/src/prover.rs index 1b71ba95..3bd029f3 100644 --- a/sdk/src/prover.rs +++ b/sdk/src/prover.rs @@ -43,7 +43,7 @@ pub trait Prover { ) -> anyhow::Result>; async fn setup<'a>( &self, - vk_path: &'a String, + vk_path: &'a String, input: &'a ProverInput, timeout: Option, ) -> anyhow::Result<()>; @@ -56,4 +56,4 @@ pub trait Prover { pub trait InputProcessor { fn process(&self, input: &mut ProverInput, args: String, json: String); -} \ No newline at end of file +}