arnaucube
arnaucube/ark-r1cs-stdPublic Self-hosted repository
Allow CS being none for into_edwards (#15)

Weikeng Chen w.k@berkeley.edu
Mon, 16 Nov 2020 00:11:35 -0800
commit

18824c0c8366833335480707a94045f843154ebd

parent

f4691621ee2e17121090805d278bdcfe8ee4c03a

1 files changed, 19 insertions(+), 8 deletions(-)

jump to
M src/groups/curves/twisted_edwards/mod.rs → src/groups/curves/twisted_edwards/mod.rs

@@ -112,15 +112,26 @@ /// Converts `self` into a Twisted Edwards curve point variable.

#[tracing::instrument(target = "r1cs")] pub fn into_edwards(&self) -> Result<AffineVar<P, F>, SynthesisError> { let cs = self.cs(); + + let mode = if cs.is_none() { + AllocationMode::Constant + } else { + AllocationMode::Witness + }; + // Compute u = x / y - let u = F::new_witness(ark_relations::ns!(cs, "u"), || { - let y_inv = self - .y - .value()? - .inverse() - .ok_or(SynthesisError::DivisionByZero)?; - Ok(self.x.value()? * &y_inv) - })?; + let u = F::new_variable( + ark_relations::ns!(cs, "u"), + || { + let y_inv = self + .y + .value()? + .inverse() + .ok_or(SynthesisError::DivisionByZero)?; + Ok(self.x.value()? * &y_inv) + }, + mode, + )?; u.mul_equals(&self.y, &self.x)?;