diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e61dd2dee..e2488d713f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ #### Upcoming Changes +* feat: Sort builtin segment info upon serialization for Cairo PIE [#1654](https://github.com/lambdaclass/cairo-vm/pull/1654) + * feat: Fix output serialization for cairo 1 [#1645](https://github.com/lambdaclass/cairo-vm/pull/1645) * Reverts changes added by #1630 * Extends the serialization of Arrays added by the `print_output` flag to Spans and Dictionaries diff --git a/vm/src/vm/runners/cairo_pie.rs b/vm/src/vm/runners/cairo_pie.rs index e6e797fe2c..248a15828f 100644 --- a/vm/src/vm/runners/cairo_pie.rs +++ b/vm/src/vm/runners/cairo_pie.rs @@ -84,6 +84,7 @@ pub struct CairoPieMetadata { pub execution_segment: SegmentInfo, pub ret_fp_segment: SegmentInfo, pub ret_pc_segment: SegmentInfo, + #[serde(serialize_with = "serde_impl::serialize_builtin_segments")] pub builtin_segments: HashMap, pub extra_segments: Vec, } @@ -132,8 +133,9 @@ impl CairoPie { mod serde_impl { use crate::stdlib::collections::HashMap; use num_traits::Num; + use serde::ser::SerializeMap; - use super::{CairoPieMemory, CAIRO_PIE_VERSION}; + use super::{CairoPieMemory, SegmentInfo, CAIRO_PIE_VERSION}; use crate::stdlib::prelude::{String, Vec}; use crate::{ types::relocatable::{MaybeRelocatable, Relocatable}, @@ -321,6 +323,33 @@ mod serde_impl { seq_serializer.end() } + + pub fn serialize_builtin_segments( + values: &HashMap, + serializer: S, + ) -> Result + where + S: Serializer, + { + let mut map_serializer = serializer.serialize_map(Some(values.len()))?; + const BUILTIN_ORDERED_LIST: &[&str] = &[ + "output", + "pedersen", + "range_check", + "ecdsa", + "bitwise", + "ec_op", + "keccak", + "poseidon", + ]; + + for name in BUILTIN_ORDERED_LIST { + if let Some(info) = values.get(*name) { + map_serializer.serialize_entry(name, info)? + } + } + map_serializer.end() + } } #[cfg(test)]