diff --git a/crates/cairo-serde/src/types/array_legacy.rs b/crates/cairo-serde/src/types/array_legacy.rs index 9595228..8227185 100644 --- a/crates/cairo-serde/src/types/array_legacy.rs +++ b/crates/cairo-serde/src/types/array_legacy.rs @@ -50,10 +50,9 @@ where fn cairo_deserialize(felts: &[FieldElement], offset: usize) -> Result { if offset >= felts.len() { - return Err(Error::Deserialize(format!( - "Buffer too short to deserialize an array: offset ({}) : buffer {:?}", - offset, felts, - ))); + // As the length of cairo 0 arrays is not included in the serialized form of the array, + // we don't have much choice here to return an empty array instead of an error. + return Ok(CairoArrayLegacy(vec![])); } let mut out: Vec = vec![]; @@ -96,4 +95,12 @@ mod tests { assert_eq!(a.0[2], felt!("3")); assert_eq!(a.0[3], felt!("4")); } + + #[test] + fn empty_array() { + // Array with only the length that is 0 (an other field as we're in cairo 0). + // So the deserialization of the array starts at index 1. + let serialized = vec![FieldElement::ZERO]; + let _a = CairoArrayLegacy::::cairo_deserialize(&serialized, 1).unwrap(); + } }