From 0f2dfc550807b9a98143c3cdfdeb90a65a5496bb Mon Sep 17 00:00:00 2001 From: therealyingtong Date: Tue, 8 Jun 2021 00:20:09 +0800 Subject: [PATCH] Use UtilitiesInstructions::Var instead of internal associated type. Co-authored-by: Jack Grigg --- src/circuit/gadget/utilities/cond_swap.rs | 31 +++------------------ src/circuit/gadget/utilities/enable_flag.rs | 11 ++------ src/circuit/gadget/utilities/plonk.rs | 28 ++++++++----------- 3 files changed, 19 insertions(+), 51 deletions(-) diff --git a/src/circuit/gadget/utilities/cond_swap.rs b/src/circuit/gadget/utilities/cond_swap.rs index f2d6ed89..8a805b7d 100644 --- a/src/circuit/gadget/utilities/cond_swap.rs +++ b/src/circuit/gadget/utilities/cond_swap.rs @@ -8,27 +8,15 @@ use pasta_curves::arithmetic::FieldExt; use std::marker::PhantomData; pub trait CondSwapInstructions: UtilitiesInstructions { - /// Variable representing cell with a certain value in the circuit. - type Var; - #[allow(clippy::type_complexity)] /// Given an input pair (x,y) and a `swap` boolean flag, return /// (y,x) if `swap` is set, else (x,y) if `swap` is not set. fn swap( &self, layouter: impl Layouter, - pair: ( - >::Var, - >::Var, - ), + pair: (Self::Var, Self::Var), swap: Option, - ) -> Result< - ( - >::Var, - >::Var, - ), - Error, - >; + ) -> Result<(Self::Var, Self::Var), Error>; } /// A chip implementing a conditional swap. @@ -67,24 +55,13 @@ impl UtilitiesInstructions for CondSwapChip { } impl CondSwapInstructions for CondSwapChip { - type Var = CellValue; - #[allow(clippy::type_complexity)] fn swap( &self, mut layouter: impl Layouter, - pair: ( - >::Var, - >::Var, - ), + pair: (Self::Var, Self::Var), swap: Option, - ) -> Result< - ( - >::Var, - >::Var, - ), - Error, - > { + ) -> Result<(Self::Var, Self::Var), Error> { let config = self.config(); layouter.assign_region( diff --git a/src/circuit/gadget/utilities/enable_flag.rs b/src/circuit/gadget/utilities/enable_flag.rs index 2ccc4fda..2497f3a3 100644 --- a/src/circuit/gadget/utilities/enable_flag.rs +++ b/src/circuit/gadget/utilities/enable_flag.rs @@ -1,4 +1,4 @@ -use super::{copy, CellValue, UtilitiesInstructions, Var}; +use super::{copy, CellValue, UtilitiesInstructions}; use halo2::{ circuit::{Chip, Layouter}, plonk::{Advice, Column, ConstraintSystem, Error, Expression, Permutation, Selector}, @@ -8,15 +8,12 @@ use pasta_curves::arithmetic::FieldExt; use std::marker::PhantomData; pub trait EnableFlagInstructions: UtilitiesInstructions { - /// Variable representing cell with a certain value in the circuit. - type Var: Var; - /// Given a `value` and an `enable_flag`, check that either `value = 0` /// or `enable_flag = 1`. fn enable_flag( &self, layouter: impl Layouter, - value: >::Var, + value: Self::Var, enable_flag: Option, ) -> Result<(), Error>; } @@ -54,12 +51,10 @@ impl UtilitiesInstructions for EnableFlagChip { } impl EnableFlagInstructions for EnableFlagChip { - type Var = CellValue; - fn enable_flag( &self, mut layouter: impl Layouter, - value: >::Var, + value: Self::Var, enable_flag: Option, ) -> Result<(), Error> { let config = self.config().clone(); diff --git a/src/circuit/gadget/utilities/plonk.rs b/src/circuit/gadget/utilities/plonk.rs index a6437723..29d7c889 100644 --- a/src/circuit/gadget/utilities/plonk.rs +++ b/src/circuit/gadget/utilities/plonk.rs @@ -10,15 +10,13 @@ use std::marker::PhantomData; #[allow(clippy::upper_case_acronyms)] #[allow(clippy::too_many_arguments)] pub trait PLONKInstructions: UtilitiesInstructions { - type Var; - // Checks that a * sm * b = c * sc fn mul( &self, layouter: impl Layouter, - a: >::Var, - b: >::Var, - c: >::Var, + a: Self::Var, + b: Self::Var, + c: Self::Var, sc: Option, sm: Option, ) -> Result<(), Error>; @@ -26,9 +24,9 @@ pub trait PLONKInstructions: UtilitiesInstructions { fn add( &self, layouter: impl Layouter, - a: >::Var, - b: >::Var, - c: >::Var, + a: Self::Var, + b: Self::Var, + c: Self::Var, sa: Option, sb: Option, sc: Option, @@ -77,14 +75,12 @@ impl UtilitiesInstructions for PLONKChip { #[allow(clippy::upper_case_acronyms)] impl PLONKInstructions for PLONKChip { - type Var = CellValue; - fn mul( &self, mut layouter: impl Layouter, - a: >::Var, - b: >::Var, - c: >::Var, + a: Self::Var, + b: Self::Var, + c: Self::Var, sc: Option, sm: Option, ) -> Result<(), Error> { @@ -129,9 +125,9 @@ impl PLONKInstructions for PLONKChip { fn add( &self, mut layouter: impl Layouter, - a: >::Var, - b: >::Var, - c: >::Var, + a: Self::Var, + b: Self::Var, + c: Self::Var, sa: Option, sb: Option, sc: Option,