arnaucube
arnaucube/sonobePublic Self-hosted repository
sonobe/folding-schemes/src/utils/mod.rs
folding-schemes/src/utils/mod.rsRaw
 1use ark_ec::{AffineRepr, CurveGroup};
 2use ark_ff::PrimeField;
 3use ark_std::Zero;
 4
 5pub mod gadgets;
 6pub mod hypercube;
 7pub mod lagrange_poly;
 8pub mod mle;
 9pub mod vec;
10
11// expose espresso local modules
12pub mod espresso;
13pub use crate::utils::espresso::multilinear_polynomial;
14pub use crate::utils::espresso::sum_check;
15pub use crate::utils::espresso::virtual_polynomial;
16
17/// For a given x, returns [1, x^1, x^2, ..., x^n-1];
18pub fn powers_of<F: PrimeField>(x: F, n: usize) -> Vec<F> {
19    let mut c: Vec<F> = vec![F::zero(); n];
20    c[0] = F::one();
21    for i in 1..n {
22        c[i] = c[i - 1] * x;
23    }
24    c
25}
26
27/// returns the coordinates of a commitment point. This is compatible with the arkworks
28/// GC.to_constraint_field()[..2]
29pub fn get_cm_coordinates<C: CurveGroup>(cm: &C) -> Vec<C::BaseField> {
30    let zero = (&C::BaseField::zero(), &C::BaseField::zero());
31    let cm = cm.into_affine();
32    let (cm_x, cm_y) = cm.xy().unwrap_or(zero);
33    vec![*cm_x, *cm_y]
34}