From 18824c0c8366833335480707a94045f843154ebd Mon Sep 17 00:00:00 2001 From: Weikeng Chen Date: Mon, 16 Nov 2020 00:11:35 -0800 Subject: [PATCH] Allow CS being none for into_edwards (#15) --- src/groups/curves/twisted_edwards/mod.rs | 27 +++++++++++++++++------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/groups/curves/twisted_edwards/mod.rs b/src/groups/curves/twisted_edwards/mod.rs index c41a6e3..04f8ceb 100644 --- a/src/groups/curves/twisted_edwards/mod.rs +++ b/src/groups/curves/twisted_edwards/mod.rs @@ -112,15 +112,26 @@ mod montgomery_affine_impl { #[tracing::instrument(target = "r1cs")] pub fn into_edwards(&self) -> Result, 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)?;