From 329e83925e4b03b86910dae1895c7c3ef0c01524 Mon Sep 17 00:00:00 2001 From: Pratyush Mishra Date: Thu, 5 Aug 2021 22:15:36 -0700 Subject: [PATCH] Rest --- src/lib.rs | 4 ++-- src/macros.rs | 33 ++++++++++++++++++--------------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 584f9b6e..1bd58407 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -42,7 +42,7 @@ pub mod groups; /// This module implements gadgets related to computing pairings in bilinear /// groups. -// pub mod pairing; +pub mod pairing; /// This module describes a trait for allocating new variables in a constraint /// system. @@ -63,7 +63,7 @@ pub mod prelude { eq::*, fields::{FieldOpsBounds, FieldVar}, groups::{CurveVar, GroupOpsBounds}, - pairing::PairingVar, + pairing::PairingGadget, select::*, R1CSVar, }; diff --git a/src/macros.rs b/src/macros.rs index 2770a7e3..0fc62baf 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -52,7 +52,9 @@ macro_rules! impl_bounded_ops { #[tracing::instrument(target = "r1cs", skip(self))] #[allow(unused_braces, clippy::redundant_closure_call)] fn $fn(self, other: Self) -> Self::Output { - ($impl)(self, other) + let mut result = self.clone(); + core::ops::$assign_trait::$assign_fn(&mut result, other); + result } } @@ -77,8 +79,9 @@ macro_rules! impl_bounded_ops { #[tracing::instrument(target = "r1cs", skip(self))] #[allow(unused_braces)] - fn $fn(self, other: &'a $type) -> Self::Output { - core::ops::$trait::$fn(&self, other) + fn $fn(mut self, other: &'a $type) -> Self::Output { + core::ops::$assign_trait::$assign_fn(&mut self, other); + self } } @@ -91,8 +94,9 @@ macro_rules! impl_bounded_ops { #[tracing::instrument(target = "r1cs", skip(self))] #[allow(unused_braces)] - fn $fn(self, other: $type) -> Self::Output { - core::ops::$trait::$fn(&self, &other) + fn $fn(mut self, other: $type) -> Self::Output { + core::ops::$assign_trait::$assign_fn(&mut self, &other); + self } } @@ -104,8 +108,7 @@ macro_rules! impl_bounded_ops { #[tracing::instrument(target = "r1cs", skip(self))] #[allow(unused_braces)] fn $assign_fn(&mut self, other: $type) { - let result = core::ops::$trait::$fn(&*self, &other); - *self = result + core::ops::$assign_trait::$assign_fn(self, &other); } } @@ -117,8 +120,7 @@ macro_rules! impl_bounded_ops { #[tracing::instrument(target = "r1cs", skip(self))] #[allow(unused_braces)] fn $assign_fn(&mut self, other: &'a $type) { - let result = core::ops::$trait::$fn(&*self, other); - *self = result + ($impl)(self, other) } } @@ -132,7 +134,9 @@ macro_rules! impl_bounded_ops { #[tracing::instrument(target = "r1cs", skip(self))] #[allow(unused_braces, clippy::redundant_closure_call)] fn $fn(self, other: $native) -> Self::Output { - ($constant_impl)(self, other) + let mut result = self.clone(); + core::ops::$assign_trait::$assign_fn(&mut result, other); + result } } @@ -145,8 +149,9 @@ macro_rules! impl_bounded_ops { #[tracing::instrument(target = "r1cs", skip(self))] #[allow(unused_braces)] - fn $fn(self, other: $native) -> Self::Output { - core::ops::$trait::$fn(&self, other) + fn $fn(mut self, other: $native) -> Self::Output { + core::ops::$assign_trait::$assign_fn(&mut self, other); + self } } @@ -155,12 +160,10 @@ macro_rules! impl_bounded_ops { $($bounds)* { - #[tracing::instrument(target = "r1cs", skip(self))] #[allow(unused_braces)] fn $assign_fn(&mut self, other: $native) { - let result = core::ops::$trait::$fn(&*self, other); - *self = result + ($constant_impl)(self, other) } } }