Verifies an inclusion proof against the current MMR root
(&self, leaf: [u8; 32], mmr_proof: &MMRInclusionProof)
| 34 | |
| 35 | /// Verifies an inclusion proof against the current MMR root |
| 36 | pub fn verify_proof(&self, leaf: [u8; 32], mmr_proof: &MMRInclusionProof) -> bool { |
| 37 | println!("GUEST: mmr_proof: {:?}", mmr_proof); |
| 38 | println!("GUEST: leaf: {:?}", leaf); |
| 39 | let mut current_hash = leaf; |
| 40 | for i in 0..mmr_proof.inclusion_proof.len() { |
| 41 | let sibling = mmr_proof.inclusion_proof[i]; |
| 42 | if mmr_proof.internal_idx & (1 << i) == 0 { |
| 43 | current_hash = hash_pair(current_hash, sibling); |
| 44 | } else { |
| 45 | current_hash = hash_pair(sibling, current_hash); |
| 46 | } |
| 47 | } |
| 48 | println!("GUEST: calculated subroot: {:?}", current_hash); |
| 49 | println!("GUEST: subroots: {:?}", self.subroots); |
| 50 | self.subroots.get(mmr_proof.subroot_idx) == Some(¤t_hash) |
| 51 | } |
| 52 | } |