From afff1ce6745c40d6d3534d0ff701924566160e11 Mon Sep 17 00:00:00 2001 From: Constance Date: Mon, 18 Dec 2023 09:55:20 +0100 Subject: [PATCH] Update comments --- halo2_gadgets/src/utilities/cond_swap.rs | 29 ++++++++++-------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/halo2_gadgets/src/utilities/cond_swap.rs b/halo2_gadgets/src/utilities/cond_swap.rs index 062314425..dbb2a4558 100644 --- a/halo2_gadgets/src/utilities/cond_swap.rs +++ b/halo2_gadgets/src/utilities/cond_swap.rs @@ -27,9 +27,8 @@ pub trait CondSwapInstructions: UtilitiesInstructions { swap: Value, ) -> Result<(Self::Var, Self::Var), Error>; - /// Given an input `(choice, left, right)`, returns `left` if choice=0 and `right` otherwise. - /// - /// `choice` must be constrained to {0, 1} separately. + /// 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, @@ -164,10 +163,10 @@ impl CondSwapInstructions for CondSwapChip { .zip(right.value()) .zip(choice.value()) .map(|((left, right), choice)| { - if *choice == F::from(1_u64) { - right - } else { + if *choice == F::from(0_u64) { left + } else { + right } }) .cloned(); @@ -176,10 +175,10 @@ impl CondSwapInstructions for CondSwapChip { .zip(right.value()) .zip(choice.value()) .map(|((left, right), choice)| { - if *choice == F::from(1_u64) { - left - } else { + if *choice == F::from(0_u64) { right + } else { + left } }) .cloned(); @@ -192,10 +191,8 @@ impl CondSwapInstructions for CondSwapChip { } impl CondSwapChip { - /// Given an input `(choice, left, right)`, returns `left` if choice=0 and `right` otherwise. - /// - /// `left` and `right` are `EccPoint` - /// `choice` must be constrained to {0, 1} separately. + /// 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, @@ -211,10 +208,8 @@ impl CondSwapChip { )) } - /// Given an input `(choice, left, right)`, returns `left` if choice=0 and `right` otherwise. - /// - /// `left` and `right` are `NonIdentityEccPoint` - /// `choice` must be constrained to {0, 1} separately. + /// 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,