Skip to content

Commit

Permalink
Fix default implementation on FixedVector (#2264)
Browse files Browse the repository at this point in the history
## Issue Addressed

NA

## Proposed Changes

Whilst hacking on something I noticed that the default implementation of `FixedVector` can violate the length constraint!

E.g., `let v: FixedVector<u8; U4> = <_>::default()` would create a fixed vector with length 0, even though it promises to *always* have length 4! This causes SSZ deserialization to fail and probably other things too.

This isn't a security risk as it can't be triggered externally, however it's a foot gun for LH devs.

## Additional Info

NA
  • Loading branch information
paulhauner committed Mar 22, 2021
1 parent d18bba5 commit 9a71a7e
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions consensus/ssz_types/src/fixed_vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ impl<T, N: Unsigned> Into<Vec<T>> for FixedVector<T, N> {
}
}

impl<T, N: Unsigned> Default for FixedVector<T, N> {
impl<T: Default, N: Unsigned> Default for FixedVector<T, N> {
fn default() -> Self {
Self {
vec: Vec::default(),
vec: (0..N::to_usize()).map(|_| T::default()).collect(),
_phantom: PhantomData,
}
}
Expand Down

0 comments on commit 9a71a7e

Please sign in to comment.