Skip to content

Commit

Permalink
fix CI
Browse files Browse the repository at this point in the history
  • Loading branch information
[gavin-ygy] committed Nov 20, 2024
1 parent 7e12adc commit 57c75b4
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 45 deletions.
51 changes: 29 additions & 22 deletions host-program/src/bin/zkm-prove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -21,7 +24,6 @@ pub struct Sha2GoInput;
pub struct RevmeInput;
pub struct MemAllocVecInput;


#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
env_logger::try_init().unwrap_or_default();
Expand Down Expand Up @@ -89,10 +91,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
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);
Expand All @@ -106,7 +108,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
} 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(());
}
}
Expand All @@ -117,8 +122,13 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
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)
Expand Down Expand Up @@ -153,26 +163,26 @@ fn create_guest_input(guest_program: &String) -> Box<dyn InputProcessor> {

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;

}
}

Expand Down Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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,
Expand Down
9 changes: 4 additions & 5 deletions sdk/src/local/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Duration>,
) -> 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!(
Expand All @@ -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!"));
}
}
Expand All @@ -154,4 +153,4 @@ impl Prover for LocalProver {
log::info!("calling wait_proof, proof_id={}", proof_id);
self.wait_proof(&proof_id, timeout).await
}
}
}
2 changes: 1 addition & 1 deletion sdk/src/local/snark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
30 changes: 15 additions & 15 deletions sdk/src/network/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,24 +26,23 @@ pub struct NetworkProver {

impl NetworkProver {
pub async fn new(client_type: &ClientType) -> anyhow::Result<NetworkProver> {
/*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);
}
Expand Down Expand Up @@ -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<Duration>,
) -> 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>(
Expand All @@ -201,4 +201,4 @@ impl Prover for NetworkProver {
log::info!("calling wait_proof, proof_id={}", proof_id);
self.wait_proof(&proof_id, timeout).await
}
}
}
4 changes: 2 additions & 2 deletions sdk/src/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub trait Prover {
) -> anyhow::Result<Option<ProverResult>>;
async fn setup<'a>(
&self,
vk_path: &'a String,
vk_path: &'a String,
input: &'a ProverInput,
timeout: Option<Duration>,
) -> anyhow::Result<()>;
Expand All @@ -56,4 +56,4 @@ pub trait Prover {

pub trait InputProcessor {
fn process(&self, input: &mut ProverInput, args: String, json: String);
}
}

0 comments on commit 57c75b4

Please sign in to comment.