-
Notifications
You must be signed in to change notification settings - Fork 396
Expand file tree
/
Copy pathlib.rs
More file actions
47 lines (39 loc) · 1.21 KB
/
lib.rs
File metadata and controls
47 lines (39 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
use lambdaworks_crypto::merkle_tree::traits::IsMerkleTreeBackend;
use serde::{Deserialize, Serialize};
use tiny_keccak::{Hasher, Keccak};
#[derive(Serialize, Deserialize)]
pub struct Risc0ImageIdAndPubInputs {
pub image_id: [u8; 32],
pub public_inputs: Vec<u8>,
}
impl Risc0ImageIdAndPubInputs {
pub fn commitment(&self) -> [u8; 32] {
let mut hasher = Keccak::v256();
for &word in &self.image_id {
hasher.update(&word.to_be_bytes());
}
hasher.update(&self.public_inputs);
let mut hash = [0u8; 32];
hasher.finalize(&mut hash);
hash
}
}
impl IsMerkleTreeBackend for Risc0ImageIdAndPubInputs {
type Data = Risc0ImageIdAndPubInputs;
type Node = [u8; 32];
fn hash_data(leaf: &Self::Data) -> Self::Node {
leaf.commitment()
}
fn hash_new_parent(child_1: &Self::Node, child_2: &Self::Node) -> Self::Node {
let mut hasher = Keccak::v256();
hasher.update(child_1);
hasher.update(child_2);
let mut hash = [0u8; 32];
hasher.finalize(&mut hash);
hash
}
}
#[derive(Serialize, Deserialize)]
pub struct Input {
pub proofs_image_id_and_pub_inputs: Vec<Risc0ImageIdAndPubInputs>,
}