diff --git a/ipa-core/src/secret_sharing/vector/array.rs b/ipa-core/src/secret_sharing/vector/array.rs index ebc0c1947..260d4829a 100644 --- a/ipa-core/src/secret_sharing/vector/array.rs +++ b/ipa-core/src/secret_sharing/vector/array.rs @@ -6,7 +6,7 @@ use std::{ }; use generic_array::{ArrayLength, GenericArray}; -use typenum::{U16, U256, U32, U64}; +use typenum::{Unsigned, U16, U256, U32, U64}; use crate::{ const_assert_eq, @@ -353,7 +353,7 @@ macro_rules! impl_serializable { type DeserializationError = ::DeserializationError; fn serialize(&self, buf: &mut GenericArray) { - let sz: usize = (::BITS / 8).try_into().unwrap(); + let sz: usize = ::Size::USIZE; for i in 0..$width { self.0[i].serialize( GenericArray::try_from_mut_slice(&mut buf[sz * i..sz * (i + 1)]).unwrap(), @@ -364,7 +364,7 @@ macro_rules! impl_serializable { fn deserialize( buf: &GenericArray, ) -> Result { - let sz: usize = (::BITS / 8).try_into().unwrap(); + let sz: usize = ::Size::USIZE; let mut res = [V::ZERO; $width]; for i in 0..$width { res[i] = V::deserialize(GenericArray::from_slice(&buf[sz * i..sz * (i + 1)]))?; @@ -390,6 +390,7 @@ mod test { }; use super::*; + use crate::ff::boolean_array::BA3; impl Arbitrary for StdArray where @@ -483,6 +484,13 @@ mod test { let copy = StdArray::::from_iter(iter); assert_eq!(copy, a); } + + #[test] + fn serde(a: StdArray) { + let mut buf = GenericArray::default(); + a.serialize(&mut buf); + assert_eq!(a, StdArray::deserialize(&buf).unwrap()); + } } #[test]