Skip to content

Commit

Permalink
Use HashKey alias instead of plain array (#484)
Browse files Browse the repository at this point in the history
  • Loading branch information
richardpringle authored Jan 9, 2024
1 parent 4cd0b79 commit c8383e1
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions firewood/src/merkle/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::{
merkle_util::{new_merkle, DataStoreError, MerkleSetup},
};

use super::{BinarySerde, NodeObjRef, TRIE_HASH_LEN};
use super::{BinarySerde, NodeObjRef};

#[derive(Debug, Error)]
pub enum ProofError {
Expand Down Expand Up @@ -102,7 +102,7 @@ pub struct Proof<N>(pub HashMap<HashKey, N>);
#[derive(Debug)]
enum SubProof {
Data(Vec<u8>),
Hash([u8; TRIE_HASH_LEN]),
Hash(HashKey),
}

impl<N: AsRef<[u8]> + Send> Proof<N> {
Expand All @@ -114,7 +114,7 @@ impl<N: AsRef<[u8]> + Send> Proof<N> {
pub fn verify<K: AsRef<[u8]>>(
&self,
key: K,
root_hash: [u8; 32],
root_hash: HashKey,
) -> Result<Option<Vec<u8>>, ProofError> {
let mut key_nibbles = Nibbles::<0>::new(key.as_ref()).into_iter();

Expand Down Expand Up @@ -147,7 +147,7 @@ impl<N: AsRef<[u8]> + Send> Proof<N> {

pub fn verify_range_proof<K: AsRef<[u8]>, V: AsRef<[u8]>>(
&self,
root_hash: [u8; 32],
root_hash: HashKey,
first_key: K,
last_key: K,
keys: Vec<K>,
Expand Down Expand Up @@ -262,7 +262,7 @@ impl<N: AsRef<[u8]> + Send> Proof<N> {
fn proof_to_path<K: AsRef<[u8]>, S: ShaleStore<Node> + Send + Sync, T: BinarySerde>(
&self,
key: K,
root_hash: [u8; 32],
root_hash: HashKey,
merkle_setup: &mut MerkleSetup<S, T>,
allow_non_existent_node: bool,
) -> Result<Option<Vec<u8>>, ProofError> {
Expand Down Expand Up @@ -391,8 +391,8 @@ impl<N: AsRef<[u8]> + Send> Proof<N> {

fn decode_subproof<'a, S: ShaleStore<Node>, T, N: AsRef<[u8]>>(
merkle: &'a Merkle<S, T>,
proofs_map: &HashMap<[u8; 32], N>,
child_hash: &[u8; 32],
proofs_map: &HashMap<HashKey, N>,
child_hash: &HashKey,
) -> Result<NodeObjRef<'a>, ProofError> {
let child_proof = proofs_map
.get(child_hash)
Expand Down Expand Up @@ -459,7 +459,7 @@ fn locate_subproof(
}
}

fn generate_subproof_hash(encoded: &[u8]) -> Result<[u8; 32], ProofError> {
fn generate_subproof_hash(encoded: &[u8]) -> Result<HashKey, ProofError> {
match encoded.len() {
0..=31 => {
let sub_hash = sha3::Keccak256::digest(encoded).into();
Expand Down

0 comments on commit c8383e1

Please sign in to comment.