Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loosen bounds on merkle hash arguments #1311

Merged
merged 2 commits into from
May 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- [`tendermint`]: Loosen bounds of merkle hashing functions to accept borrowed data.
([\#1310](https://github.com/informalsystems/tendermint-rs/issues/1310))
6 changes: 3 additions & 3 deletions tendermint/src/merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub type Hash = [u8; HASH_SIZE];
/// Compute a simple Merkle root from vectors of arbitrary byte vectors.
/// The leaves of the tree are the bytes of the given byte vectors in
/// the given order.
pub fn simple_hash_from_byte_vectors<H>(byte_vecs: &[Vec<u8>]) -> Hash
pub fn simple_hash_from_byte_vectors<H>(byte_vecs: &[impl AsRef<[u8]>]) -> Hash
where
H: MerkleHash + Default,
{
Expand Down Expand Up @@ -48,11 +48,11 @@ pub trait MerkleHash {
// Implements recursion into subtrees.
// Pre and post-conditions: the hasher is in the reset state
// before and after calling this function.
fn hash_byte_vectors(&mut self, byte_vecs: &[Vec<u8>]) -> Hash {
fn hash_byte_vectors(&mut self, byte_vecs: &[impl AsRef<[u8]>]) -> Hash {
let length = byte_vecs.len();
match length {
0 => self.empty_hash(),
1 => self.leaf_hash(&byte_vecs[0]),
1 => self.leaf_hash(byte_vecs[0].as_ref()),
_ => {
let split = length.next_power_of_two() / 2;
let left = self.hash_byte_vectors(&byte_vecs[..split]);
Expand Down
Loading