Skip to content

Commit 86f652f

Browse files
committedMar 5, 2018
Some minor documentation/changes to domain.
1 parent f7815f6 commit 86f652f

File tree

2 files changed

+54
-11
lines changed

2 files changed

+54
-11
lines changed
 

‎src/domain.rs

+52-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
1+
//! This module contains an `EvaluationDomain` abstraction for
2+
//! performing various kinds of polynomial arithmetic on top of
3+
//! the scalar field.
4+
//!
5+
//! In pairing-based SNARKs like Groth16, we need to calculate
6+
//! a quotient polynomial over a target polynomial with roots
7+
//! at distinct points associated with each constraint of the
8+
//! constraint system. In order to be efficient, we choose these
9+
//! roots to be the powers of a 2^n root of unity in the field.
10+
//! This allows us to perform polynomial operations in O(n)
11+
//! by performing an O(n log n) FFT over such a domain.
12+
113
use pairing::{
214
Engine,
315
Field,
4-
PrimeField
16+
PrimeField,
17+
CurveProjective
518
};
619

720
use super::{
@@ -10,8 +23,6 @@ use super::{
1023

1124
use super::multicore::Worker;
1225

13-
const LARGEST_POLYNOMIAL_DEGREE: usize = 1 << 28;
14-
1526
pub struct EvaluationDomain<E: Engine, G: Group<E>> {
1627
coeffs: Vec<G>,
1728
exp: u32,
@@ -36,12 +47,6 @@ impl<E: Engine, G: Group<E>> EvaluationDomain<E, G> {
3647

3748
pub fn from_coeffs(mut coeffs: Vec<G>) -> Result<EvaluationDomain<E, G>, SynthesisError>
3849
{
39-
// For platform compatibility, we expect not to
40-
// deal with these kinds of large polynomials.
41-
if coeffs.len() > LARGEST_POLYNOMIAL_DEGREE {
42-
return Err(SynthesisError::PolynomialDegreeTooLarge)
43-
}
44-
4550
// Compute the size of our evaluation domain
4651
let mut m = 1;
4752
let mut exp = 0;
@@ -126,13 +131,18 @@ impl<E: Engine, G: Group<E>> EvaluationDomain<E, G> {
126131
self.distribute_powers(worker, geninv);
127132
}
128133

134+
/// This evaluates t(tau) for this domain, which is
135+
/// tau^m - 1 for these radix-2 domains.
129136
pub fn z(&self, tau: &E::Fr) -> E::Fr {
130137
let mut tmp = tau.pow(&[self.coeffs.len() as u64]);
131138
tmp.sub_assign(&E::Fr::one());
132139

133140
tmp
134141
}
135142

143+
/// The target polynomial is the zero polynomial in our
144+
/// evaluation domain, so we must perform division over
145+
/// a coset.
136146
pub fn divide_by_z_on_coset(&mut self, worker: &Worker)
137147
{
138148
let i = self.z(&E::Fr::multiplicative_generator()).inverse().unwrap();
@@ -148,6 +158,7 @@ impl<E: Engine, G: Group<E>> EvaluationDomain<E, G> {
148158
});
149159
}
150160

161+
/// Perform O(n) multiplication of two polynomials in the domain.
151162
pub fn mul_assign(&mut self, worker: &Worker, other: &EvaluationDomain<E, Scalar<E>>) {
152163
assert_eq!(self.coeffs.len(), other.coeffs.len());
153164

@@ -162,6 +173,7 @@ impl<E: Engine, G: Group<E>> EvaluationDomain<E, G> {
162173
});
163174
}
164175

176+
/// Perform O(n) subtraction of one polynomial from another in the domain.
165177
pub fn sub_assign(&mut self, worker: &Worker, other: &EvaluationDomain<E, G>) {
166178
assert_eq!(self.coeffs.len(), other.coeffs.len());
167179

@@ -184,6 +196,37 @@ pub trait Group<E: Engine>: Sized + Copy + Clone + Send + Sync {
184196
fn group_sub_assign(&mut self, other: &Self);
185197
}
186198

199+
pub struct Point<G: CurveProjective>(pub G);
200+
201+
impl<G: CurveProjective> PartialEq for Point<G> {
202+
fn eq(&self, other: &Point<G>) -> bool {
203+
self.0 == other.0
204+
}
205+
}
206+
207+
impl<G: CurveProjective> Copy for Point<G> { }
208+
209+
impl<G: CurveProjective> Clone for Point<G> {
210+
fn clone(&self) -> Point<G> {
211+
*self
212+
}
213+
}
214+
215+
impl<G: CurveProjective> Group<G::Engine> for Point<G> {
216+
fn group_zero() -> Self {
217+
Point(G::zero())
218+
}
219+
fn group_mul_assign(&mut self, by: &G::Scalar) {
220+
self.0.mul_assign(by.into_repr());
221+
}
222+
fn group_add_assign(&mut self, other: &Self) {
223+
self.0.add_assign(&other.0);
224+
}
225+
fn group_sub_assign(&mut self, other: &Self) {
226+
self.0.sub_assign(&other.0);
227+
}
228+
}
229+
187230
pub struct Scalar<E: Engine>(pub E::Fr);
188231

189232
impl<E: Engine> PartialEq for Scalar<E> {

‎src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ extern crate bit_vec;
77
extern crate crossbeam;
88
extern crate byteorder;
99

10-
pub mod multicore;
11-
pub mod multiexp;
10+
mod multicore;
11+
mod multiexp;
1212
pub mod domain;
1313
pub mod groth16;
1414

0 commit comments

Comments
 (0)
Please sign in to comment.