pub fn compress_state_diffs(mut state_diffs: Vec<StateDiffRecord>) -> Vec<u8> {
    let mut res = vec![];

    // IMPORTANT: Sorting here is determined by the order expected in the circuits.
    state_diffs.sort_by_key(|rec| (rec.address, rec.key));

    let (initial_writes, repeated_writes): (Vec<_>, Vec<_>) = state_diffs
        .iter()
        .partition(|rec| rec.enumeration_index == 0);

    res.extend((initial_writes.len() as u16).to_be_bytes());
    for state_diff in initial_writes {
        res.extend(state_diff.compress());
    }

    for state_diff in repeated_writes {
        res.extend(state_diff.compress());
    }

    prepend_header(res)
}
Compresses a vector of state diff records according to the following:
num_initial writes (u32) || compressed initial writes || compressed repeated writes
core/lib/types/src/storage/writes/mod.rs