Skip to content

Commit c3a99ac

Browse files
Let Radix2Domain::offset to be FpVar instead of F (#65)
* restructure code * done * add changelog * add the changelog to mark this as a breaking change * add the CHANGELOG * tweak * add `EqGadget` * rename generate_interpolate_cache to generate_interpolation_cache * address the comment Co-authored-by: weikeng <[email protected]>
1 parent 02ee91d commit c3a99ac

File tree

4 files changed

+211
-37
lines changed

4 files changed

+211
-37
lines changed

CHANGELOG.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,35 @@
22

33
### Breaking changes
44

5-
- #60 Rename `AllocatedBit` to `AllocatedBool` for consistency with the `Boolean` variable.
6-
You can update downstream usage with `grep -rl 'AllocatedBit' . | xargs env LANG=C env LC_CTYPE=C sed -i '' 's/AllocatedBit/AllocatedBool/g'`.
5+
- [\#60](https://github.com/arkworks-rs/r1cs-std/pull/60) Rename `AllocatedBit` to `AllocatedBool` for consistency with the `Boolean` variable.
6+
You can update downstream usage with `grep -rl 'AllocatedBit' . | xargs env LANG=C env LC_CTYPE=C sed -i '' 's/AllocatedBit/AllocatedBool/g'`.
7+
- [\#65](https://github.com/arkworks-rs/r1cs-std/pull/65) Rename `Radix2Domain` in `r1cs-std` to `Radix2DomainVar`.
78

89
### Features
910

10-
- [\#53](https://github.com/arkworks-rs/r1cs-std/pull/53) Add univariate evaluation domain and lagrange interpolation.
11+
- [\#53](https://github.com/arkworks-rs/r1cs-std/pull/53) Add univariate evaluation domain and Lagrange interpolation.
1112

1213
### Improvements
1314

15+
- [\#65](https://github.com/arkworks-rs/r1cs-std/pull/65) Add support for non-constant coset offset in `Radix2DomainVar`.
16+
1417
### Bug Fixes
1518

1619

1720
## v0.2.0
1821

1922
### Breaking changes
23+
2024
- [\#12](https://github.com/arkworks-rs/r1cs-std/pull/12) Make the output of the `ToBitsGadget` impl for `FpVar` fixed-size
2125
- [\#48](https://github.com/arkworks-rs/r1cs-std/pull/48) Add `Clone` trait bound to `CondSelectGadget`.
2226

2327
### Features
28+
2429
- [\#21](https://github.com/arkworks-rs/r1cs-std/pull/21) Add `UInt128`
2530
- [\#50](https://github.com/arkworks-rs/r1cs-std/pull/50) Add `DensePolynomialVar`
2631

2732
### Improvements
33+
2834
- [\#5](https://github.com/arkworks-rs/r1cs-std/pull/5) Speedup BLS-12 pairing
2935
- [\#13](https://github.com/arkworks-rs/r1cs-std/pull/13) Add `ToConstraintFieldGadget` to `ProjectiveVar`
3036
- [\#15](https://github.com/arkworks-rs/r1cs-std/pull/15), #16 Allow `cs` to be `None` when converting a Montgomery point into a Twisted Edwards point
@@ -38,6 +44,7 @@ You can update downstream usage with `grep -rl 'AllocatedBit' . | xargs env LANG
3844
- [\#46](https://github.com/arkworks-rs/r1cs-std/pull/46) Add mux gadget as an auto-impl in `CondSelectGadget` to support random access of an array
3945

4046
### Bug fixes
47+
4148
- [\#8](https://github.com/arkworks-rs/r1cs-std/pull/8) Fix bug in `three_bit_cond_neg_lookup` when using a constant lookup bit
4249
- [\#9](https://github.com/arkworks-rs/r1cs-std/pull/9) Fix bug in `short_weierstrass::ProjectiveVar::to_affine`
4350
- [\#29](https://github.com/arkworks-rs/r1cs-std/pull/29) Fix `to_non_unique_bytes` for `BLS12::G1Prepared`

src/poly/domain/mod.rs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::boolean::Boolean;
2+
use crate::eq::EqGadget;
23
use crate::fields::fp::FpVar;
34
use crate::fields::FieldVar;
45
use ark_ff::PrimeField;
@@ -7,23 +8,33 @@ use ark_std::vec::Vec;
78

89
pub mod vanishing_poly;
910

10-
#[derive(Copy, Clone, Hash, Eq, PartialEq, Debug)]
11+
#[derive(Clone, Debug)]
1112
/// Defines an evaluation domain over a prime field. The domain is a coset of size `1<<dim`.
1213
///
1314
/// Native code corresponds to `ark-poly::univariate::domain::radix2`, but `ark-poly` only supports
1415
/// subgroup for now.
1516
///
1617
/// TODO: support cosets in `ark-poly`.
17-
pub struct Radix2Domain<F: PrimeField> {
18+
pub struct Radix2DomainVar<F: PrimeField> {
1819
/// generator of subgroup g
1920
pub gen: F,
2021
/// index of the quotient group (i.e. the `offset`)
21-
pub offset: F,
22+
pub offset: FpVar<F>,
2223
/// dimension of evaluation domain
2324
pub dim: u64,
2425
}
2526

26-
impl<F: PrimeField> Radix2Domain<F> {
27+
impl<F: PrimeField> EqGadget<F> for Radix2DomainVar<F> {
28+
fn is_eq(&self, other: &Self) -> Result<Boolean<F>, SynthesisError> {
29+
if self.gen != other.gen || self.dim != other.dim {
30+
Ok(Boolean::constant(false))
31+
} else {
32+
self.offset.is_eq(&other.offset)
33+
}
34+
}
35+
}
36+
37+
impl<F: PrimeField> Radix2DomainVar<F> {
2738
/// order of the domain
2839
pub fn order(&self) -> usize {
2940
1 << self.dim
@@ -40,6 +51,11 @@ impl<F: PrimeField> Radix2Domain<F> {
4051
result
4152
}
4253

54+
/// Size of the domain
55+
pub fn size(&self) -> u64 {
56+
1 << self.dim
57+
}
58+
4359
/// For domain `h<g>` with dimension `n`, `position` represented by `query_pos` in big endian form,
4460
/// returns `h*g^{position}<g^{n-query_pos.len()}>`
4561
pub fn query_position_to_coset(
@@ -64,7 +80,7 @@ impl<F: PrimeField> Radix2Domain<F> {
6480
first_point_in_coset += &term;
6581
}
6682

67-
first_point_in_coset *= &FpVar::Constant(self.offset);
83+
first_point_in_coset *= &self.offset;
6884

6985
coset.push(first_point_in_coset);
7086
for i in 1..(1 << (coset_dim as usize)) {

src/poly/evaluations/univariate/lagrange_interpolator.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,11 @@ impl<F: PrimeField> LagrangeInterpolator<F> {
9898

9999
#[cfg(test)]
100100
mod tests {
101-
use crate::poly::domain::Radix2Domain;
101+
use crate::fields::fp::FpVar;
102+
use crate::fields::FieldVar;
103+
use crate::poly::domain::Radix2DomainVar;
102104
use crate::poly::evaluations::univariate::lagrange_interpolator::LagrangeInterpolator;
105+
use crate::R1CSVar;
103106
use ark_ff::{FftField, Field, One};
104107
use ark_poly::univariate::DensePolynomial;
105108
use ark_poly::{Polynomial, UVPolynomial};
@@ -112,21 +115,25 @@ mod tests {
112115
let poly = DensePolynomial::rand(15, &mut rng);
113116
let gen = Fr::get_root_of_unity(1 << 4).unwrap();
114117
assert_eq!(gen.pow(&[1 << 4]), Fr::one());
115-
let domain = Radix2Domain {
118+
let domain = Radix2DomainVar {
116119
gen,
117-
offset: Fr::multiplicative_generator(),
120+
offset: FpVar::constant(Fr::multiplicative_generator()),
118121
dim: 4, // 2^4 = 16
119122
};
120123
// generate evaluations of `poly` on this domain
121-
let mut coset_point = domain.offset;
124+
let mut coset_point = domain.offset.value().unwrap();
122125
let mut oracle_evals = Vec::new();
123126
for _ in 0..(1 << 4) {
124127
oracle_evals.push(poly.evaluate(&coset_point));
125128
coset_point *= gen;
126129
}
127130

128-
let interpolator =
129-
LagrangeInterpolator::new(domain.offset, domain.gen, domain.dim, oracle_evals);
131+
let interpolator = LagrangeInterpolator::new(
132+
domain.offset.value().unwrap(),
133+
domain.gen,
134+
domain.dim,
135+
oracle_evals,
136+
);
130137

131138
// the point to evaluate at
132139
let interpolate_point = Fr::rand(&mut rng);

0 commit comments

Comments
 (0)