Skip to content

Commit

Permalink
make min_encoding_chunks part of utils public intf
Browse files Browse the repository at this point in the history
  • Loading branch information
martyall committed Feb 8, 2025
1 parent 505b3b7 commit 9f86c96
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions saffron/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,14 @@ pub mod test_utils {
}
}

// returns the minimum number of polynomials required to encode the data
pub fn min_encoding_chunks<F: PrimeField, D: EvaluationDomain<F>>(domain: &D, xs: &[u8]) -> usize {
let m = F::MODULUS_BIT_SIZE as usize / 8;
let n = xs.len();
let num_field_elems = (n + m - 1) / m;
(num_field_elems + domain.size() - 1) / domain.size()
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down Expand Up @@ -337,12 +345,10 @@ mod tests {
}
}

// The number of field elements required to encode the data, including the padding
fn padded_field_length(xs: &[u8]) -> usize {
let m = Fp::MODULUS_BIT_SIZE as usize / 8;
let n = xs.len();
let num_field_elems = (n + m - 1) / m;
let num_polys = (num_field_elems + DOMAIN.size() - 1) / DOMAIN.size();
DOMAIN.size() * num_polys
let n = min_encoding_chunks(&*DOMAIN, xs);
n * DOMAIN.size()
}

proptest! {
Expand Down

0 comments on commit 9f86c96

Please sign in to comment.