From 9a71a7e486f45ee10ef4f5c934a19e59211678f5 Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Mon, 22 Mar 2021 00:54:09 +0000 Subject: [PATCH] Fix default implementation on FixedVector (#2264) ## 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 = <_>::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 --- consensus/ssz_types/src/fixed_vector.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/consensus/ssz_types/src/fixed_vector.rs b/consensus/ssz_types/src/fixed_vector.rs index 01173e6596..9ae0d06bab 100644 --- a/consensus/ssz_types/src/fixed_vector.rs +++ b/consensus/ssz_types/src/fixed_vector.rs @@ -114,10 +114,10 @@ impl Into> for FixedVector { } } -impl Default for FixedVector { +impl Default for FixedVector { fn default() -> Self { Self { - vec: Vec::default(), + vec: (0..N::to_usize()).map(|_| T::default()).collect(), _phantom: PhantomData, } }