Skip to content

Commit

Permalink
chore: modify according to the comments
Browse files Browse the repository at this point in the history
  • Loading branch information
felicityin committed Jan 13, 2025
1 parent 5f495fb commit 68d37c5
Show file tree
Hide file tree
Showing 11 changed files with 179 additions and 168 deletions.
11 changes: 8 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
/target
/verifier/data/test_circuit
/test-vectors/mips
target
verifier/data/test_circuit
test-vectors/mips
push.sh
mips-zkm-zkvm-elf
libsnark.h
libsnark.so
*.log
Cargo.lock
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Please refer to [this](guest-program/README.md) guide.
```sh
cd zkm-project-template
sh sdk/src/local/libsnark/compile.sh # compile snark library
cargo build --release # build host programs
cargo build --release # build host programs
```

If successfully, it will generate the binary files in `target/release`/{`sha2-rust` ,`sha2-go` ,`revme`, `mem-alloc-vec`}
Expand Down Expand Up @@ -114,7 +114,7 @@ The result proof and contract file will be in the contracts/verifier and contrac
> The proving task requires several stages: queuing, splitting, proving, aggregating and finalizing. Each stage involves a varying duration.
Must set the `PRIVATE_KEY` and `ZKM_PROVER=network` in [`run-proving.sh`](host-program/run-proving.sh) and run the program:
Must set the `PROOF_NETWORK_PRVKEY` and `ZKM_PROVER=network` in [`run-proving.sh`](host-program/run-proving.sh) and run the program:

```sh
./run-proving.sh sha2-rust
Expand Down
56 changes: 26 additions & 30 deletions host-program/mem-alloc-vec/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ use anyhow::Result;
use std::env;
use std::fs::read;
use std::time::Instant;
use zkm_sdk::{prover::ClientCfg, prover::ProverInput, ProverClient};

pub const DEFAULT_PROVER_NETWORK_RPC: &str = "https://152.32.186.45:20002";
pub const DEFALUT_PROVER_NETWORK_DOMAIN: &str = "stage";
use zkm_sdk::{is_local_prover, prover::ClientCfg, prover::ProverInput, ProverClient};

#[tokio::main]
async fn main() -> Result<()> {
Expand All @@ -29,45 +26,44 @@ async fn main() -> Result<()> {
let elf_path = env::var("ELF_PATH").unwrap_or(env!("GUEST_TARGET_PATH").to_string());
let proof_results_path = env::var("PROOF_RESULTS_PATH").unwrap_or("../contracts".to_string());
let vk_path = env::var("VERIFYING_KEY_PATH").unwrap_or("/tmp/input".to_string());
let zkm_prover_type = env::var("ZKM_PROVER").expect("ZKM PROVER is missing");

//network proving
let endpoint = env::var("ENDPOINT").unwrap_or(DEFAULT_PROVER_NETWORK_RPC.to_string());
// network proving
let endpoint = env::var("ENDPOINT").unwrap_or("".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 zkm_prover_type = env::var("ZKM_PROVER").expect("ZKM PROVER is missing");
let domain_name = env::var("DOMAIN_NAME").unwrap_or("".to_string());
let private_key = env::var("PROOF_NETWORK_PRVKEY").unwrap_or("".to_string());

let client_config: ClientCfg = ClientCfg {
zkm_prover: zkm_prover_type.to_owned(),
endpoint: Some(endpoint),
ca_cert_path: Some(ca_cert_path),
cert_path: Some(cert_path),
key_path: Some(key_path),
domain_name: Some(domain_name),
private_key: Some(private_key),
vk_path: vk_path.to_owned(),
};
let mut client_config: ClientCfg =
ClientCfg::new(zkm_prover_type.to_owned(), vk_path.to_owned());

if !is_local_prover(&zkm_prover_type) {
client_config.set_network(
endpoint,
ca_cert_path,
cert_path,
key_path,
domain_name,
private_key,
);
}

let prover_client = ProverClient::new(&client_config).await;
log::info!("new prover client,ok.");

let prover_input = ProverInput {
elf: read(elf_path).unwrap(),
public_inputstream: vec![],
private_inputstream: vec![],
seg_size,
execute_only,
precompile: false,
receipt_inputs: vec![],
receipts: vec![],
..Default::default()
};

//If the guest program does't have inputs, it does't need the set_guest_input().
//set_guest_input(&mut prover_input, None);
// If the guest program does't have inputs, it does't need the set_guest_input().
// set_guest_input(&mut prover_input, None);

//excuting the setup_and_generate_sol_verifier
// excuting the setup_and_generate_sol_verifier
if setup_flag {
match prover_client
.setup_and_generate_sol_verifier(&zkm_prover_type, &vk_path, &prover_input)
Expand All @@ -86,7 +82,7 @@ async fn main() -> Result<()> {
match proving_result {
Ok(Some(prover_result)) => {
if !execute_only {
//excute the guest program and generate the proof
// excute the guest program and generate the proof
prover_client
.process_proof_results(
&prover_result,
Expand All @@ -96,8 +92,8 @@ async fn main() -> Result<()> {
)
.expect("Process proof results false");
} else {
//only excute the guest program without generating the proof.
//the mem-alloc-vec guest program doesn't have output messages.
// only excute the guest program without generating the proof.
// the mem-alloc-vec guest program doesn't have output messages.
prover_client
.print_guest_execution_output(false, &prover_result)
.expect("Print guest program excution's output false.");
Expand Down
54 changes: 25 additions & 29 deletions host-program/revme/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ use anyhow::Result;
use std::env;
use std::fs::read;
use std::time::Instant;
use zkm_sdk::{prover::ClientCfg, prover::ProverInput, ProverClient};

pub const DEFAULT_PROVER_NETWORK_RPC: &str = "https://152.32.186.45:20002";
pub const DEFALUT_PROVER_NETWORK_DOMAIN: &str = "stage";
use zkm_sdk::{is_local_prover, prover::ClientCfg, prover::ProverInput, ProverClient};

#[tokio::main]
async fn main() -> Result<()> {
Expand All @@ -30,45 +27,44 @@ async fn main() -> Result<()> {
let json_path = env::var("JSON_PATH").expect("JSON PATH is missing");
let proof_results_path = env::var("PROOF_RESULTS_PATH").unwrap_or("../contracts".to_string());
let vk_path = env::var("VERIFYING_KEY_PATH").unwrap_or("/tmp/input".to_string());
let zkm_prover_type = env::var("ZKM_PROVER").expect("ZKM PROVER is missing");

//network proving
let endpoint = env::var("ENDPOINT").unwrap_or(DEFAULT_PROVER_NETWORK_RPC.to_string());
// network proving
let endpoint = env::var("ENDPOINT").unwrap_or("".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 zkm_prover_type = env::var("ZKM_PROVER").expect("ZKM PROVER is missing");
let domain_name = env::var("DOMAIN_NAME").unwrap_or("".to_string());
let private_key = env::var("PROOF_NETWORK_PRVKEY").unwrap_or("".to_string());

let client_config: ClientCfg = ClientCfg {
zkm_prover: zkm_prover_type.to_owned(),
endpoint: Some(endpoint),
ca_cert_path: Some(ca_cert_path),
cert_path: Some(cert_path),
key_path: Some(key_path),
domain_name: Some(domain_name),
private_key: Some(private_key),
vk_path: vk_path.to_owned(),
};
let mut client_config: ClientCfg =
ClientCfg::new(zkm_prover_type.to_owned(), vk_path.to_owned());

if !is_local_prover(&zkm_prover_type) {
client_config.set_network(
endpoint,
ca_cert_path,
cert_path,
key_path,
domain_name,
private_key,
);
}

let prover_client = ProverClient::new(&client_config).await;
log::info!("new prover client,ok.");

let mut prover_input = ProverInput {
elf: read(elf_path).unwrap(),
public_inputstream: vec![],
private_inputstream: vec![],
seg_size,
execute_only,
precompile: false,
receipt_inputs: vec![],
receipts: vec![],
..Default::default()
};

//If the guest program does't have inputs, it does't need the setting.
// If the guest program does't have inputs, it does't need the setting.
set_guest_input(&mut prover_input, Some(&json_path));

//excuting the setup_and_generate_sol_verifier
// excuting the setup_and_generate_sol_verifier
if setup_flag {
match prover_client
.setup_and_generate_sol_verifier(&zkm_prover_type, &vk_path, &prover_input)
Expand All @@ -87,7 +83,7 @@ async fn main() -> Result<()> {
match proving_result {
Ok(Some(prover_result)) => {
if !execute_only {
//excute the guest program and generate the proof
// excute the guest program and generate the proof
prover_client
.process_proof_results(
&prover_result,
Expand All @@ -97,8 +93,8 @@ async fn main() -> Result<()> {
)
.expect("process proof results error");
} else {
//only excute the guest program without generating the proof.
//the revme guest program doesn't have outputs messages.
// only excute the guest program without generating the proof.
// the revme guest program doesn't have outputs messages.
prover_client
.print_guest_execution_output(false, &prover_result)
.expect("print guest program excution's output false.");
Expand Down
3 changes: 2 additions & 1 deletion host-program/run-proving.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ export SETUP_FLAG=false

##network proving
export CA_CERT_PATH=${BASEDIR}/tool/ca.pem
export PRIVATE_KEY= ##The private key corresponding to the public key when registering in the https://www.zkm.io/apply
export PROOF_NETWORK_PRVKEY= ##The private key corresponding to the public key when registering in the https://www.zkm.io/apply
export ENDPOINT=https://152.32.186.45:20002 ##the test entry of zkm proof network
export DOMAIN_NAME=stage

echo "Compile guest-program ${program}"
if [[ "$program" =~ .*go$ ]];then
Expand Down
47 changes: 21 additions & 26 deletions host-program/sha2-go/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ use serde::{Deserialize, Serialize};
use std::env;
use std::fs::read;
use std::time::Instant;
use zkm_sdk::{prover::ClientCfg, prover::ProverInput, ProverClient};

pub const DEFAULT_PROVER_NETWORK_RPC: &str = "https://152.32.186.45:20002";
pub const DEFALUT_PROVER_NETWORK_DOMAIN: &str = "stage";
use zkm_sdk::{is_local_prover, prover::ClientCfg, prover::ProverInput, ProverClient};

const GUEST_TARGET_PATH: &str = concat!(
env!("CARGO_MANIFEST_DIR"),
Expand All @@ -33,48 +30,46 @@ async fn main() -> Result<()> {

let elf_path = env::var("ELF_PATH").unwrap_or(GUEST_TARGET_PATH.to_string());
let args_parameter = env::var("ARGS").unwrap_or("data-to-hash".to_string());
//let json_path = env::var("JSON_PATH").expect("JSON PATH is missing");
let proof_results_path = env::var("PROOF_RESULTS_PATH").unwrap_or("../contracts".to_string());
let vk_path = env::var("VERIFYING_KEY_PATH").unwrap_or("/tmp/input".to_string());

//network proving
let endpoint = env::var("ENDPOINT").unwrap_or(DEFAULT_PROVER_NETWORK_RPC.to_string());
// network proving
let endpoint = env::var("ENDPOINT").unwrap_or("".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 domain_name = env::var("DOMAIN_NAME").unwrap_or("".to_string());
let private_key = env::var("PROOF_NETWORK_PRVKEY").unwrap_or("".to_string());
let zkm_prover_type = env::var("ZKM_PROVER").expect("ZKM PROVER is missing");

let client_config: ClientCfg = ClientCfg {
zkm_prover: zkm_prover_type.to_owned(),
endpoint: Some(endpoint),
ca_cert_path: Some(ca_cert_path),
cert_path: Some(cert_path),
key_path: Some(key_path),
domain_name: Some(domain_name),
private_key: Some(private_key),
vk_path: vk_path.to_owned(),
};
let mut client_config: ClientCfg =
ClientCfg::new(zkm_prover_type.to_owned(), vk_path.to_owned());

if !is_local_prover(&zkm_prover_type) {
client_config.set_network(
endpoint,
ca_cert_path,
cert_path,
key_path,
domain_name,
private_key,
);
}

let prover_client = ProverClient::new(&client_config).await;
log::info!("new prover client,ok.");

let mut prover_input = ProverInput {
elf: read(elf_path).unwrap(),
public_inputstream: vec![],
private_inputstream: vec![],
seg_size,
execute_only,
precompile: false,
receipt_inputs: vec![],
receipts: vec![],
..Default::default()
};

//If the guest program does't have inputs, it does't need the setting.
// If the guest program does't have inputs, it does't need the setting.
set_guest_input(&mut prover_input, Some(&args_parameter));

//excuting the setup_and_generate_sol_verifier
// excuting the setup_and_generate_sol_verifier
if setup_flag {
match prover_client
.setup_and_generate_sol_verifier(&zkm_prover_type, &vk_path, &prover_input)
Expand Down
Loading

0 comments on commit 68d37c5

Please sign in to comment.