From f30acea8af7e28e956e771928130e12bfc084832 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Delabrouille?= <34384633+tdelabro@users.noreply.github.com> Date: Mon, 11 Dec 2023 12:26:12 +0100 Subject: [PATCH] fix: random value hashes (#1308) Co-authored-by: AurelienFT Co-authored-by: AurelienFT <32803821+AurelienFT@users.noreply.github.com> --- CHANGELOG.md | 2 ++ .../commitments/src/merkle_patricia_tree/merkle_node.rs | 7 ++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5011fbd6f5..42da5aba7a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Next release +- fix: Change seliazation of bitvec to &[u8] in merkle tree to avoid memory + uninitialized - chore: change SCARB config version for foundry CI ## v0.6.0 diff --git a/crates/primitives/commitments/src/merkle_patricia_tree/merkle_node.rs b/crates/primitives/commitments/src/merkle_patricia_tree/merkle_node.rs index 8d75bcceeb..8329cfe24f 100644 --- a/crates/primitives/commitments/src/merkle_patricia_tree/merkle_node.rs +++ b/crates/primitives/commitments/src/merkle_patricia_tree/merkle_node.rs @@ -7,6 +7,7 @@ use bitvec::order::Msb0; use bitvec::prelude::BitVec; use bitvec::slice::BitSlice; +use bitvec::view::BitView; use mp_felt::Felt252Wrapper; use mp_hashers::HasherT; use starknet_api::stdlib::collections::HashMap; @@ -287,10 +288,10 @@ impl EdgeNode { None => unreachable!("child node not found"), }; - let mut temp_path = self.path.clone(); - temp_path.force_align(); + let mut bytes = [0u8; 32]; + bytes.view_bits_mut::()[256 - self.path.len()..].copy_from_bitslice(&self.path); - let path = Felt252Wrapper::try_from(temp_path.into_vec().as_slice()).unwrap(); + let path = Felt252Wrapper::try_from(&bytes).unwrap(); let mut length = [0; 32]; // Safe as len() is guaranteed to be <= 251 length[31] = self.path.len() as u8;