From 39584d20d79a0063664b3adbe386cfc2658cd22b Mon Sep 17 00:00:00 2001 From: YaoGalteland Date: Mon, 11 Mar 2024 10:02:49 +0100 Subject: [PATCH] remove mux.md --- book/src/design/gadgets/multiplexer.md | 132 ------------------------- 1 file changed, 132 deletions(-) delete mode 100644 book/src/design/gadgets/multiplexer.md diff --git a/book/src/design/gadgets/multiplexer.md b/book/src/design/gadgets/multiplexer.md deleted file mode 100644 index 6b531d2ace..0000000000 --- a/book/src/design/gadgets/multiplexer.md +++ /dev/null @@ -1,132 +0,0 @@ -# Multiplexer - -Given a boolean flag $\textsf{choice}$, this gadget is used for selecting one of two values ($\textsf{left}$ and $\textsf{right}$) based on the boolean flag. -If $\textsf{choice}$ is true, it returns $\textsf{right}$; otherwise, it returns $\textsf{left}$. This functionality is crucial for circuits that require conditional logic. -We use a multiplexer to compute differently for ZEC or for non-ZEC assets in Orchard protocol. - - -## Chip instructions - -mux is an instruction of the conditional swap gadget. - -```rust,ignore,no_run -pub trait CondSwapInstructions: UtilitiesInstructions { - /// Given an input `(choice, left, right)` where `choice` is a boolean flag, - /// returns `left` if `choice` is not set and `right` if `choice` is set. - fn mux( - &self, - layouter: &mut impl Layouter, - choice: Self::Var, - left: Self::Var, - right: Self::Var, - ) -> Result; -} -``` - -## Implement chip traits - -```rust,ignore,no_run -impl CondSwapInstructions for CondSwapChip { - fn mux( - &self, - layouter: &mut impl Layouter, - choice: Self::Var, - left: Self::Var, - right: Self::Var, - ) -> Result { - let config = self.config(); - - layouter.assign_region( - || "mux", - |mut region| { - // Enable `q_swap` selector - config.q_swap.enable(&mut region, 0)?; - - // Copy in `a` value - let left = left.copy_advice(|| "copy left", &mut region, config.a, 0)?; - - // Copy in `b` value - let right = right.copy_advice(|| "copy right", &mut region, config.b, 0)?; - - // Copy `choice` value - let choice = choice.copy_advice(|| "copy choice", &mut region, config.swap, 0)?; - - let a_swapped = left - .value() - .zip(right.value()) - .zip(choice.value()) - .map(|((left, right), choice)| { - if *choice == F::from(0_u64) { - left - } else { - right - } - }) - .cloned(); - let b_swapped = left - .value() - .zip(right.value()) - .zip(choice.value()) - .map(|((left, right), choice)| { - if *choice == F::from(0_u64) { - right - } else { - left - } - }) - .cloned(); - - region.assign_advice(|| "out b_swap", self.config.b_swapped, 0, || b_swapped)?; - region.assign_advice(|| "out a_swap", self.config.a_swapped, 0, || a_swapped) - }, - ) - } -} -``` - -## Multiplexer (mux) logic on ECC Points - -The mux chip also extends its functionality to work with elliptic curve points, facilitating operations like conditional selections between points. -Based on a boolean flag $\textsf{choice}$, it selects between two given points $\textsf{left}$ and $\textsf{right}$. -If $\textsf{choice}$ is true, it returns the point $\textsf{right}$; otherwise, it returns the point $\textsf{left}$. - -```rust,ignore,no_run -impl CondSwapChip { - /// Given an input `(choice, left, right)` where `choice` is a boolean flag and `left` and `right` are `EccPoint`, - /// returns `left` if `choice` is not set and `right` if `choice` is set. - pub fn mux_on_points( - &self, - mut layouter: impl Layouter, - choice: &AssignedCell, - left: &EccPoint, - right: &EccPoint, - ) -> Result { - let x_cell = self.mux(&mut layouter, choice.clone(), left.x(), right.x())?; - let y_cell = self.mux(&mut layouter, choice.clone(), left.y(), right.y())?; - Ok(EccPoint::from_coordinates_unchecked( - x_cell.into(), - y_cell.into(), - )) - } - - /// Given an input `(choice, left, right)` where `choice` is a boolean flag and `left` and `right` are - /// `NonIdentityEccPoint`, returns `left` if `choice` is not set and `right` if `choice` is set. - pub fn mux_on_non_identity_points( - &self, - mut layouter: impl Layouter, - choice: &AssignedCell, - left: &NonIdentityEccPoint, - right: &NonIdentityEccPoint, - ) -> Result { - let x_cell = self.mux(&mut layouter, choice.clone(), left.x(), right.x())?; - let y_cell = self.mux(&mut layouter, choice.clone(), left.y(), right.y())?; - Ok(NonIdentityEccPoint::from_coordinates_unchecked( - x_cell.into(), - y_cell.into(), - )) - } -} -``` - - -