From dbe565765645bdc1ff5eafc4d4d1aeb8dff4102e Mon Sep 17 00:00:00 2001 From: Weikeng Chen Date: Fri, 5 Feb 2021 17:51:01 -0800 Subject: [PATCH] Fix mul_without_reduce when self is a constant (#36) * fix * fix --- src/nonnative_field_var.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/nonnative_field_var.rs b/src/nonnative_field_var.rs index d687abfe..3e8d8ebf 100644 --- a/src/nonnative_field_var.rs +++ b/src/nonnative_field_var.rs @@ -455,7 +455,19 @@ impl NonNativeFieldVar R1CSResult> { match self { - Self::Constant(c) => Ok(NonNativeFieldMulResultVar::Constant(*c)), + Self::Constant(c) => match other { + Self::Constant(other_c) => Ok(NonNativeFieldMulResultVar::Constant(*c * other_c)), + Self::Var(other_v) => { + let self_v = + AllocatedNonNativeFieldVar::::new_constant( + self.cs(), + c, + )?; + Ok(NonNativeFieldMulResultVar::Var( + other_v.mul_without_reduce(&self_v)?, + )) + } + }, Self::Var(v) => { let other_v = match other { Self::Constant(other_c) => {