Return evaluations from bytes_to_polynomial as well

This commit is contained in:
Daniel Sanchez Quiros 2024-04-02 15:18:25 +02:00
parent 52606faf83
commit 708dcf55a5
2 changed files with 6 additions and 5 deletions

View File

@ -49,10 +49,11 @@ pub fn bytes_to_evaluations<const CHUNK_SIZE: usize>(
/// polynomial. Then use FFT to transform that polynomial into coefficient form. /// polynomial. Then use FFT to transform that polynomial into coefficient form.
/// `CHUNK_SIZE` needs to be 31 (bytes) or less, otherwise it cannot be encoded. /// `CHUNK_SIZE` needs to be 31 (bytes) or less, otherwise it cannot be encoded.
/// The input data need to be padded, so it fits in a len modulus of `CHUNK_SIZE`. /// The input data need to be padded, so it fits in a len modulus of `CHUNK_SIZE`.
/// Returns the polynomial in evaluation form and in coefficient form
pub fn bytes_to_polynomial<const CHUNK_SIZE: usize>( pub fn bytes_to_polynomial<const CHUNK_SIZE: usize>(
data: &[u8], data: &[u8],
domain: GeneralEvaluationDomain<Fr>, domain: GeneralEvaluationDomain<Fr>,
) -> Result<DensePolynomial<Fr>, KzgRsError> { ) -> Result<(Evaluations<Fr>, DensePolynomial<Fr>), KzgRsError> {
if CHUNK_SIZE >= 32 { if CHUNK_SIZE >= 32 {
return Err(KzgRsError::ChunkSizeTooBig(CHUNK_SIZE)); return Err(KzgRsError::ChunkSizeTooBig(CHUNK_SIZE));
} }
@ -63,8 +64,8 @@ pub fn bytes_to_polynomial<const CHUNK_SIZE: usize>(
}); });
} }
let evals = bytes_to_evaluations::<CHUNK_SIZE>(data, domain); let evals = bytes_to_evaluations::<CHUNK_SIZE>(data, domain);
let coefficients = evals.interpolate(); let coefficients = evals.interpolate_by_ref();
Ok(coefficients) Ok((evals, coefficients))
} }
#[cfg(test)] #[cfg(test)]
@ -86,7 +87,7 @@ mod test {
let mut rng = thread_rng(); let mut rng = thread_rng();
bytes.try_fill(&mut rng).unwrap(); bytes.try_fill(&mut rng).unwrap();
let evals = bytes_to_evaluations::<31>(&bytes, *DOMAIN); let evals = bytes_to_evaluations::<31>(&bytes, *DOMAIN);
let poly = bytes_to_polynomial::<31>(&bytes, *DOMAIN).unwrap(); let (_, poly) = bytes_to_polynomial::<31>(&bytes, *DOMAIN).unwrap();
for i in 0..100 { for i in 0..100 {
let eval_point = DOMAIN.element(i); let eval_point = DOMAIN.element(i);
let point = poly.evaluate(&eval_point); let point = poly.evaluate(&eval_point);

View File

@ -100,7 +100,7 @@ mod test {
let mut rng = thread_rng(); let mut rng = thread_rng();
bytes.try_fill(&mut rng).unwrap(); bytes.try_fill(&mut rng).unwrap();
let evaluations = bytes_to_evaluations::<31>(&bytes, *DOMAIN).evals; let evaluations = bytes_to_evaluations::<31>(&bytes, *DOMAIN).evals;
let poly = bytes_to_polynomial::<31>(&bytes, *DOMAIN).unwrap(); let (_, poly) = bytes_to_polynomial::<31>(&bytes, *DOMAIN).unwrap();
let commitment = commit_polynomial(&poly, &GLOBAL_PARAMETERS).unwrap(); let commitment = commit_polynomial(&poly, &GLOBAL_PARAMETERS).unwrap();
let proofs: Vec<_> = (0..10) let proofs: Vec<_> = (0..10)
.map(|i| generate_element_proof(i, &poly, &GLOBAL_PARAMETERS, &DOMAIN).unwrap()) .map(|i| generate_element_proof(i, &poly, &GLOBAL_PARAMETERS, &DOMAIN).unwrap())