Skip to content

Commit

Permalink
fix: generate image id for precompile elf dynamicaly
Browse files Browse the repository at this point in the history
  • Loading branch information
weilzkm committed Dec 3, 2024
1 parent 921cd4c commit dc4028d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 2 additions & 3 deletions prover/examples/sha2-precompile/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ extern crate alloc;
use alloc::vec::Vec;

zkm_runtime::entrypoint!(main);
const SHA_ELF:[u8; 32] = [83, 70, 149, 120, 71, 122, 247, 101, 174, 227, 186, 199, 6, 32, 152, 39, 176, 153, 148, 65, 154, 248, 140, 95, 163, 122, 249, 151, 112, 84, 68, 192];

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


zkm_runtime::io::verify(SHA_ELF.to_vec(), &input);
zkm_runtime::io::verify(elf_id, &input);
let mut hasher = Sha256::new();
hasher.update(input);
let result = hasher.finalize();
Expand Down
3 changes: 3 additions & 0 deletions prover/examples/zkmips.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ fn prove_sha2_precompile() {
receipt.userdata
);

let image_id = receipt.root_before;
receipts.push(receipt.into());

let mut state = load_elf_with_patch(&elf_path, vec![]);
Expand All @@ -374,6 +375,8 @@ fn prove_sha2_precompile() {
log::info!("private input value: {:?}", private_input);
state.add_input_stream(&private_input.to_vec());

state.add_input_stream(&image_id);

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

let value = state.read_public_values::<[u8; 32]>();
Expand Down

0 comments on commit dc4028d

Please sign in to comment.