Skip to content

Commit

Permalink
refactor: simplify AllocatedPoint::default
Browse files Browse the repository at this point in the history
  • Loading branch information
huitseeker committed Feb 28, 2024
1 parent 8ef2a85 commit bec419d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/gadgets/ecc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ impl<G: Group> AllocatedPoint<G> {
}

/// Allocates a default point on the curve, set to the identity point.
pub fn default<CS: ConstraintSystem<G::Base>>(mut cs: CS) -> Result<Self, SynthesisError> {
pub fn default<CS: ConstraintSystem<G::Base>>(mut cs: CS) -> Self {
let zero = alloc_zero(cs.namespace(|| "zero"));
let one = alloc_one(cs.namespace(|| "one"));

Ok(Self {
Self {
x: zero.clone(),
y: zero,
is_infinity: one,
})
}
}

/// Returns coordinates associated with the point.
Expand Down Expand Up @@ -509,7 +509,7 @@ impl<G: Group> AllocatedPoint<G> {

// when self.is_infinity = 1, return the default point, else return res
// we already set res.is_infinity to be self.is_infinity, so we do not need to set it here
let default = Self::default(cs.namespace(|| "default"))?;
let default = Self::default(cs.namespace(|| "default"));
let x = conditionally_select2(
cs.namespace(|| "check if self.is_infinity is zero (x)"),
&default.x,
Expand Down
4 changes: 2 additions & 2 deletions src/gadgets/r1cs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ impl<E: Engine, const N: usize> AllocatedRelaxedR1CSInstance<E, N> {
limb_width: usize,
n_limbs: usize,
) -> Result<Self, SynthesisError> {
let W = AllocatedPoint::default(cs.namespace(|| "allocate W"))?;
let W = AllocatedPoint::default(cs.namespace(|| "allocate W"));
let E = W.clone();

let u = W.x.clone(); // In the default case, W.x = u = 0
Expand Down Expand Up @@ -159,7 +159,7 @@ impl<E: Engine, const N: usize> AllocatedRelaxedR1CSInstance<E, N> {
limb_width: usize,
n_limbs: usize,
) -> Result<Self, SynthesisError> {
let E = AllocatedPoint::default(cs.namespace(|| "allocate default E"))?;
let E = AllocatedPoint::default(cs.namespace(|| "allocate default E"));

let u = alloc_one(cs.namespace(|| "one"));

Expand Down

0 comments on commit bec419d

Please sign in to comment.