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

[DON"T MERGE]chore: update example #154

Closed
wants to merge 1 commit into from
Closed
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
7 changes: 5 additions & 2 deletions prover/examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,14 @@ cd prover/examples/sha2
cargo build --target=mips-unknown-linux-musl
```

* Run the host program
* Run the host program

// echo -n 'world!' | sha256sum
// 711e9609339e92b03ddc0a211827dba421f38f9ed8b9d806e1ffdd8c15ffa03d

```
cd ../..
RUST_LOG=info ELF_PATH=examples/sha2/target/mips-unknown-linux-musl/debug/sha2-bench SEG_OUTPUT=/tmp/output cargo run --release --example zkmips bench
ARGS="711e9609339e92b03ddc0a211827dba421f38f9ed8b9d806e1ffdd8c15ffa03d world!" RUST_LOG=info ELF_PATH=examples/sha2/target/mips-unknown-linux-musl/debug/sha2-bench SEG_OUTPUT=/tmp/output cargo run --release --example zkmips bench

Or

Expand Down
6 changes: 5 additions & 1 deletion prover/examples/sha2/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@ use alloc::vec::Vec;
zkm_runtime::entrypoint!(main);

pub fn main() {
let public_input: [u8; 32] = zkm_runtime::io::read();
let input: Vec<u8> = zkm_runtime::io::read();

let mut hasher = Sha256::new();
hasher.update(input);
let result = hasher.finalize();

zkm_runtime::io::commit::<[u8; 32]>(&result.into());
let output: [u8; 32] = result.into();
assert_eq!(output, public_input);

zkm_runtime::io::commit::<[u8; 32]>(&output);
}
16 changes: 14 additions & 2 deletions prover/examples/zkmips.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,25 @@ fn prove_sha2_bench() {

let mut state = load_elf_with_patch(&elf_path, vec![]);
// load input
let input = [5u8; 32];
state.add_input_stream(&input.to_vec());
let args = env::var("ARGS").unwrap_or("data-to-hash".to_string());
// assume the first arg is the hash output(which is a public input), and the second is the input.
let args: Vec<&str> = args.split_whitespace().collect();
assert_eq!(args.len(), 2);

let public_input: Vec<u8> = hex::decode(args[0]).unwrap();
state.add_input_stream(&public_input);
log::info!("expected public value in hex: {:X?}", args[0]);
log::info!("expected public value: {:X?}", public_input);

let private_input = args[1].as_bytes();
log::info!("private input value: {:X?}", private_input);
state.add_input_stream(&private_input);

let (total_steps, mut state) = split_prog_into_segs(state, &seg_path, "", 0);

let value = state.read_public_values::<[u8; 32]>();
log::info!("public value: {:X?}", value);
log::info!("public value: {} in hex", hex::encode(value));

let seg_file = format!("{seg_path}/{}", 0);
let seg_reader = BufReader::new(File::open(seg_file).unwrap());
Expand Down
Loading