Implement rs encode/decode
This commit is contained in:
parent
a8ef541cdb
commit
4baae88a1c
@ -5,8 +5,6 @@ use ark_ff::{BigInteger256, PrimeField, Zero};
|
||||
use ark_poly::domain::general::GeneralEvaluationDomain;
|
||||
use ark_poly::evaluations::univariate::Evaluations;
|
||||
use ark_poly::univariate::DensePolynomial;
|
||||
use num_bigint;
|
||||
use num_traits::ops::bytes::FromBytes;
|
||||
use thiserror::Error;
|
||||
// internal
|
||||
|
||||
|
@ -0,0 +1,34 @@
|
||||
use ark_bls12_381::Fr;
|
||||
use ark_poly::univariate::DensePolynomial;
|
||||
use ark_poly::{EvaluationDomain, Evaluations, GeneralEvaluationDomain, Polynomial};
|
||||
|
||||
pub fn encode(
|
||||
polynomial: &DensePolynomial<Fr>,
|
||||
evaluations: &Evaluations<Fr>,
|
||||
factor: usize,
|
||||
domain: &GeneralEvaluationDomain<Fr>,
|
||||
) -> Evaluations<Fr> {
|
||||
assert!(factor > 1);
|
||||
Evaluations::from_vec_and_domain(
|
||||
(0..evaluations.evals.len() * factor)
|
||||
.map(|i| polynomial.evaluate(&domain.element(i)))
|
||||
.collect(),
|
||||
*domain,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn decode(
|
||||
original_chunks_len: usize,
|
||||
points: &[Fr],
|
||||
domain: &GeneralEvaluationDomain<Fr>,
|
||||
) -> Evaluations<Fr> {
|
||||
let evals = Evaluations::<Fr>::from_vec_and_domain(points.to_vec(), *domain);
|
||||
let coeffs = evals.interpolate();
|
||||
|
||||
Evaluations::from_vec_and_domain(
|
||||
(0..original_chunks_len)
|
||||
.map(|i| coeffs.evaluate(&domain.element(i)))
|
||||
.collect(),
|
||||
*domain,
|
||||
)
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user