Skip to content

Commit

Permalink
Remove use of BTreeMap in configure()
Browse files Browse the repository at this point in the history
  • Loading branch information
therealyingtong committed Apr 26, 2021
1 parent 6c5624d commit 4016e7b
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 145 deletions.
239 changes: 103 additions & 136 deletions src/circuit/gadget/ecc/chip.rs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/circuit/gadget/ecc/chip/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use halo2::{
plonk::{ConstraintSystem, Error, Expression},
};

#[allow(clippy::too_many_arguments)]
pub(super) fn create_gate<F: FieldExt>(
meta: &mut ConstraintSystem<F>,
q_add: Expression<F>,
Expand Down
2 changes: 2 additions & 0 deletions src/circuit/gadget/ecc/chip/add_complete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use halo2::{
plonk::{ConstraintSystem, Error, Expression},
};

#[allow(clippy::too_many_arguments)]
pub(crate) fn create_gate<F: FieldExt>(
meta: &mut ConstraintSystem<F>,
q_add_complete: Expression<F>,
Expand Down Expand Up @@ -142,6 +143,7 @@ pub(crate) fn create_gate<F: FieldExt>(
}
}

#[allow(clippy::many_single_char_names)]
pub(super) fn assign_region<C: CurveAffine>(
a: &EccPoint<C::Base>,
b: &EccPoint<C::Base>,
Expand Down
8 changes: 5 additions & 3 deletions src/circuit/gadget/ecc/chip/double.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ pub(super) fn create_gate<F: FieldExt>(
x_p: Expression<F>,
y_p: Expression<F>,
) {
let x_p_2 = x_p.clone() * x_p.clone();
let x_p_4 = x_p_2.clone() * x_p_2.clone();

// 4⋅(y_p)^2⋅(x_a + 2⋅x_p) − 9⋅(x_p)^4 = 0
meta.create_gate("point doubling expr1", |_| {
let x_p_4 = x_p.clone() * x_p.clone() * x_p.clone() * x_p.clone();
let expr1 = y_p.clone()
* y_p.clone()
* (x_a.clone() + x_p.clone() * F::from_u64(2))
Expand All @@ -28,8 +30,8 @@ pub(super) fn create_gate<F: FieldExt>(

// 2⋅y_p⋅(y_a + y_p) − 3⋅(x_p)^2⋅(x_p − x_a) = 0
meta.create_gate("point doubling expr2", |_| {
let expr2 = y_p.clone() * (y_a + y_p) * F::from_u64(2)
- x_p.clone() * x_p.clone() * (x_p - x_a) * F::from_u64(3);
let expr2 =
y_p.clone() * (y_a + y_p) * F::from_u64(2) - x_p_2 * (x_p - x_a) * F::from_u64(3);

q_double * expr2
});
Expand Down
1 change: 1 addition & 0 deletions src/circuit/gadget/ecc/chip/mul.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use halo2::{
plonk::{ConstraintSystem, Error, Expression},
};

#[allow(clippy::too_many_arguments)]
pub(super) fn create_gate<F: FieldExt>(
meta: &mut ConstraintSystem<F>,
q_mul: Expression<F>,
Expand Down
12 changes: 9 additions & 3 deletions src/circuit/gadget/ecc/chip/mul_fixed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use halo2::{
poly::Rotation,
};

#[allow(clippy::too_many_arguments)]
pub(super) fn create_gate<F: FieldExt>(
meta: &mut ConstraintSystem<F>,
lagrange_coeffs: [Column<Fixed>; constants::H],
Expand Down Expand Up @@ -146,7 +147,7 @@ pub(super) fn assign_region<C: CurveAffine>(
let u_val = base.u.as_ref().zip(k_usize[0]).map(|(u, k_0)| u[0][k_0]);
region.assign_advice(
|| "u",
config.u,
config.mul_fixed_u,
offset,
|| u_val.ok_or(Error::SynthesisError),
)?;
Expand Down Expand Up @@ -189,7 +190,12 @@ pub(super) fn assign_region<C: CurveAffine>(

// Assign u = (y_p + z_w).sqrt()
let u_val = base.u.as_ref().zip(k_usize[w]).map(|(u, k)| u[w][k]);
region.assign_advice(|| "u", config.u, w, || u_val.ok_or(Error::SynthesisError))?;
region.assign_advice(
|| "u",
config.mul_fixed_u,
w,
|| u_val.ok_or(Error::SynthesisError),
)?;

// Add to the cumulative sum
sum = add::assign_region::<C>(&mul_b, &sum, offset + w, region, config.clone())?;
Expand Down Expand Up @@ -220,7 +226,7 @@ pub(super) fn assign_region<C: CurveAffine>(
.map(|(u, k)| u[constants::NUM_WINDOWS - 1][k]);
region.assign_advice(
|| "u",
config.u,
config.mul_fixed_u,
offset + constants::NUM_WINDOWS - 1,
|| u_val.ok_or(Error::SynthesisError),
)?;
Expand Down
11 changes: 8 additions & 3 deletions src/circuit/gadget/ecc/chip/mul_fixed_short.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ pub(super) fn assign_region<C: CurveAffine>(
.map(|(u, k_0)| u[0][k_0]);
region.assign_advice(
|| "u",
config.u,
config.mul_fixed_u,
offset,
|| u_val.ok_or(Error::SynthesisError),
)?;
Expand Down Expand Up @@ -182,7 +182,12 @@ pub(super) fn assign_region<C: CurveAffine>(

// Assign u = (y_p + z_w).sqrt()
let u_val = base.u_short.as_ref().zip(k_usize[w]).map(|(u, k)| u[w][k]);
region.assign_advice(|| "u", config.u, w, || u_val.ok_or(Error::SynthesisError))?;
region.assign_advice(
|| "u",
config.mul_fixed_u,
w,
|| u_val.ok_or(Error::SynthesisError),
)?;

// Add to the cumulative sum
sum = add::assign_region::<C>(&mul_b, &sum, offset + w, region, config.clone()).unwrap();
Expand Down Expand Up @@ -214,7 +219,7 @@ pub(super) fn assign_region<C: CurveAffine>(
.map(|(u, k)| u[constants::NUM_WINDOWS_SHORT - 1][k]);
region.assign_advice(
|| "u",
config.u,
config.mul_fixed_u,
offset + constants::NUM_WINDOWS_SHORT - 1,
|| u_val.ok_or(Error::SynthesisError),
)?;
Expand Down

0 comments on commit 4016e7b

Please sign in to comment.