Skip to content

Commit

Permalink
fix: random value hashes (keep-starknet-strange#1308)
Browse files Browse the repository at this point in the history
Co-authored-by: AurelienFT <[email protected]>
Co-authored-by: AurelienFT <[email protected]>
  • Loading branch information
3 people committed Dec 11, 2023
1 parent 4c1eb9e commit f30acea
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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::<Msb0>()[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;
Expand Down

0 comments on commit f30acea

Please sign in to comment.