mirror of
https://github.com/arnaucube/ark-r1cs-std.git
synced 2026-01-12 00:41:32 +01:00
Rename arguments to CondSelectGadget for code clarity
This commit is contained in:
committed by
Pratyush Mishra
parent
6c0ee7ffbc
commit
23c6bb4bd0
@@ -449,19 +449,19 @@ impl<F: PrimeField> CondSelectGadget<F> for FpGadget<F> {
|
||||
fn conditionally_select<CS: ConstraintSystem<F>>(
|
||||
mut cs: CS,
|
||||
cond: &Boolean,
|
||||
first: &Self,
|
||||
second: &Self,
|
||||
true_value: &Self,
|
||||
false_value: &Self,
|
||||
) -> Result<Self, SynthesisError> {
|
||||
if let Boolean::Constant(cond) = *cond {
|
||||
if cond {
|
||||
Ok(first.clone())
|
||||
Ok(true_value.clone())
|
||||
} else {
|
||||
Ok(second.clone())
|
||||
Ok(false_value.clone())
|
||||
}
|
||||
} else {
|
||||
let result = Self::alloc(cs.ns(|| ""), || {
|
||||
cond.get_value()
|
||||
.and_then(|cond| if cond { first } else { second }.get_value())
|
||||
.and_then(|cond| if cond { true_value } else { false_value }.get_value())
|
||||
.get()
|
||||
})?;
|
||||
// a = self; b = other; c = cond;
|
||||
@@ -473,8 +473,8 @@ impl<F: PrimeField> CondSelectGadget<F> for FpGadget<F> {
|
||||
cs.enforce(
|
||||
|| "conditionally_select",
|
||||
|_| cond.lc(one, F::one()),
|
||||
|lc| (&first.variable - &second.variable) + lc,
|
||||
|lc| (&result.variable - &second.variable) + lc,
|
||||
|lc| (&true_value.variable - &false_value.variable) + lc,
|
||||
|lc| (&result.variable - &false_value.variable) + lc,
|
||||
);
|
||||
|
||||
Ok(result)
|
||||
|
||||
@@ -787,20 +787,20 @@ where
|
||||
fn conditionally_select<CS: ConstraintSystem<ConstraintF>>(
|
||||
mut cs: CS,
|
||||
cond: &Boolean,
|
||||
first: &Self,
|
||||
second: &Self,
|
||||
true_value: &Self,
|
||||
false_value: &Self,
|
||||
) -> Result<Self, SynthesisError> {
|
||||
let c0 = Fp6Gadget::<P, ConstraintF>::conditionally_select(
|
||||
&mut cs.ns(|| "c0"),
|
||||
cond,
|
||||
&first.c0,
|
||||
&second.c0,
|
||||
&true_value.c0,
|
||||
&false_value.c0,
|
||||
)?;
|
||||
let c1 = Fp6Gadget::<P, ConstraintF>::conditionally_select(
|
||||
&mut cs.ns(|| "c1"),
|
||||
cond,
|
||||
&first.c1,
|
||||
&second.c1,
|
||||
&true_value.c1,
|
||||
&false_value.c1,
|
||||
)?;
|
||||
|
||||
Ok(Self::new(c0, c1))
|
||||
|
||||
@@ -581,20 +581,20 @@ impl<P: Fp2Parameters<Fp = ConstraintF>, ConstraintF: PrimeField> CondSelectGadg
|
||||
fn conditionally_select<CS: ConstraintSystem<ConstraintF>>(
|
||||
mut cs: CS,
|
||||
cond: &Boolean,
|
||||
first: &Self,
|
||||
second: &Self,
|
||||
true_value: &Self,
|
||||
false_value: &Self,
|
||||
) -> Result<Self, SynthesisError> {
|
||||
let c0 = FpGadget::<ConstraintF>::conditionally_select(
|
||||
&mut cs.ns(|| "c0"),
|
||||
cond,
|
||||
&first.c0,
|
||||
&second.c0,
|
||||
&true_value.c0,
|
||||
&false_value.c0,
|
||||
)?;
|
||||
let c1 = FpGadget::<ConstraintF>::conditionally_select(
|
||||
&mut cs.ns(|| "c1"),
|
||||
cond,
|
||||
&first.c1,
|
||||
&second.c1,
|
||||
&true_value.c1,
|
||||
&false_value.c1,
|
||||
)?;
|
||||
|
||||
Ok(Self::new(c0, c1))
|
||||
|
||||
@@ -861,26 +861,26 @@ where
|
||||
fn conditionally_select<CS: ConstraintSystem<ConstraintF>>(
|
||||
mut cs: CS,
|
||||
cond: &Boolean,
|
||||
first: &Self,
|
||||
second: &Self,
|
||||
true_value: &Self,
|
||||
false_value: &Self,
|
||||
) -> Result<Self, SynthesisError> {
|
||||
let c0 = Fp2Gadget::<P, ConstraintF>::conditionally_select(
|
||||
&mut cs.ns(|| "c0"),
|
||||
cond,
|
||||
&first.c0,
|
||||
&second.c0,
|
||||
&true_value.c0,
|
||||
&false_value.c0,
|
||||
)?;
|
||||
let c1 = Fp2Gadget::<P, ConstraintF>::conditionally_select(
|
||||
&mut cs.ns(|| "c1"),
|
||||
cond,
|
||||
&first.c1,
|
||||
&second.c1,
|
||||
&true_value.c1,
|
||||
&false_value.c1,
|
||||
)?;
|
||||
let c2 = Fp2Gadget::<P, ConstraintF>::conditionally_select(
|
||||
&mut cs.ns(|| "c2"),
|
||||
cond,
|
||||
&first.c2,
|
||||
&second.c2,
|
||||
&true_value.c2,
|
||||
&false_value.c2,
|
||||
)?;
|
||||
|
||||
Ok(Self::new(c0, c1, c2))
|
||||
|
||||
Reference in New Issue
Block a user