zkMIPS / zkm

The universal zkVM empowering Ethereum as the Global Settlement Layer
https://zkm.io
MIT License
105 stars 50 forks source link

user data #178

Closed gavin-ygy closed 2 weeks ago

gavin-ygy commented 3 weeks ago
  1. modify the sha2-rust guest program ( output the hash(public_input))

    pub fn main() {
    let public_input: Vec<u8> = zkm_runtime::io::read();
    let input: Vec<u8> = zkm_runtime::io::read();
    
    let mut hasher = Sha256::new();
    // hasher.update(input);
     hasher.update(public_input);
    let result = hasher.finalize();
    
    let output: [u8; 32] = result.into();
    //assert_eq!(output.to_vec(), public_input);
    
    zkm_runtime::io::commit::<[u8; 32]>(&output);
    }
  2. only execute the sha2-rust guest program on zkm (without proof), the return data is the following: [37, 239, 0, 170, 248, 76, 96, 64, 145, 63, 153, 93, 50, 225, 236, 247, 254, 78, 173, 45, 106, 228, 172, 71, 22, 64, 75, 35, 253, 132, 58, 225]

  3. prove the sha2-rust guest program, the public_input.json {"roots_before":{"root":[2766321147,2694049612,604723523,3935473971,3375932118,2348353898,1033527446,3633790516]},"roots_after":{"root":[1849541892,359379942,2559789461,188920962,1528236828,3934539291,1762794076,3301967725]},"userdata":[187,16,238,8,12,95,113,30,103,155,101,195,74,185,43,245,178,222,83,124,136,187,157,76,39,206,243,127,32,120,215,94]}

  4. the step2's data is different with the public_input.json 's userdata

weilzkm commented 2 weeks ago

Yeah. they are different: The output of guest program is the hash of raw input. The userdata is hash of serialized input(which encodes both data and type info of the raw input).