1use crate::pcs_transcript::PcsProverTranscript;
2use rand::{rngs::StdRng, seq::SliceRandom};
3use rand_core::SeedableRng;
4use zinc_transcript::traits::Transcribable;
5
6pub(super) fn shuffle_seeded<T>(slice: &mut [T], seed: u64) {
8 let mut rng = StdRng::seed_from_u64(seed);
9 slice.shuffle(&mut rng);
10}
11
12#[allow(clippy::unwrap_used)]
15fn fmt_thousands(n: usize) -> String {
16 let s = n.to_string();
17 s.as_bytes()
18 .rchunks(3)
19 .rev()
20 .map(|c| std::str::from_utf8(c).unwrap())
21 .collect::<Vec<_>>()
22 .join(" ")
23}
24
25pub fn eprint_proof_size(label: impl std::fmt::Display, proof: &impl Transcribable) {
27 let mut transcript = PcsProverTranscript::new_from_commitments(std::iter::empty());
28 transcript
29 .write(proof)
30 .expect("transcribing proof should not fail");
31 let raw = transcript.stream.into_inner();
32
33 eprint_bytes_size(label, &raw);
34}
35
36pub fn eprint_bytes_size(label: impl std::fmt::Display, raw: &[u8]) {
38 macro_rules! print {
39 ($details:expr, $size_bytes:expr) => {
40 eprintln!(
41 " Proof size ({label}, {}): {} bytes ({} KiB)",
42 $details,
43 fmt_thousands($size_bytes),
44 $size_bytes.div_ceil(1024),
45 );
46 };
47 }
48 print!("raw", raw.len());
49
50 let zstd = zstd::encode_all(raw, 22).expect("zstd compression failed");
51 print!("zstd-22", zstd.len());
52}