Skip to content

Commit

Permalink
Implement additive operation of polynomials
Browse files Browse the repository at this point in the history
  • Loading branch information
osuketh committed Apr 19, 2019
1 parent d9ed44f commit d866d2e
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 4 deletions.
4 changes: 2 additions & 2 deletions core/sonic/src/helped/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::cs::{SynthesisDriver, Circuit, Backend, Variable, Coeff};
use crate::srs::SRS;
use crate::transcript::ProvingTranscript;
use crate::polynomials::commitment::{polynomial_commitment};
use crate::utils::{ChainExt, mul_powers};
use crate::utils::{ChainExt, coeffs_consecutive_powers};

pub const NUM_BLINDINGS: usize = 4;

Expand Down Expand Up @@ -106,7 +106,7 @@ impl<E: Engine> Proof<E> {
let first_power = y_inv.pow(&[(2 * n + NUM_BLINDINGS) as u64]);

// Evaluate the polynomial r(X, Y) at y
mul_powers(
coeffs_consecutive_powers(
&mut rxy,
first_power,
y,
Expand Down
3 changes: 3 additions & 0 deletions core/sonic/src/polynomials/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use pairing::Engine;
pub mod commitment;
pub mod s_eval;
pub mod operations;

pub struct Polynomial<E: Engine>(Vec<E::Fr>);
18 changes: 18 additions & 0 deletions core/sonic/src/polynomials/operations.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use bellman::multicore::Worker;
use pairing::{Engine, Field};

pub fn add_polynomials<F: Field>(a: &mut [F], b: &[F]) {
assert_eq!(a.len(), b.len());

let worker = Worker::new();

worker.scope(a.len(), |scope, chunk| {
for (a, b) in a.chunks_mut(chunk).zip(b.chunks(chunk)) {
scope.spawn(move |_| {
for (a, b) in a.iter_mut().zip(b.iter()) {
a.add_assign(b);
}
});
}
});
}
4 changes: 3 additions & 1 deletion core/sonic/src/polynomials/s_eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use pairing::{Engine, Field};
use bellman::SynthesisError;

/// Defined in Section 5: SYSTEM OF CONSTRAINTS
/// Evaluation of s(X, Y) at x
#[derive(Clone)]
pub struct SxEval<E: Engine> {
y: E::Fr,
Expand All @@ -20,7 +21,8 @@ pub struct SxEval<E: Engine> {
}

impl<E: Engine> SxEval<E> {
/// Initialize s(X, y) where y is fixed.
pub fn new(y: E::Fr, n: usize) -> Result<Self, SynthesisError> {
unimplemented!();
}
}
}
2 changes: 1 addition & 1 deletion core/sonic/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl<T, U> DoubleEndedIterator for Chain<T, U>
/// Multiply each coefficient by some power of the base in a form
/// `first_power * base^{i}`
/// This would be sparse, consecutive multiplication based on non-zero coefficients.
pub fn mul_powers<'a, F: Field> (
pub fn coeffs_consecutive_powers<'a, F: Field> (
coeffs: &mut [F],
first_power: F,
base: F
Expand Down

0 comments on commit d866d2e

Please sign in to comment.