mirror of
https://github.com/AleoHQ/leo.git
synced 2025-01-05 00:33:12 +03:00
call the char methods
This commit is contained in:
parent
768a597e04
commit
3cc3c7ab02
@ -23,14 +23,11 @@ use crate::{
|
||||
|
||||
use leo_ast::{InputValue, Span};
|
||||
use snarkvm_fields::PrimeField;
|
||||
use snarkvm_gadgets::{
|
||||
fields::FpGadget,
|
||||
utilities::{
|
||||
bits::comparator::{ComparatorGadget, EvaluateLtGadget},
|
||||
boolean::Boolean,
|
||||
eq::{ConditionalEqGadget, EqGadget, EvaluateEqGadget},
|
||||
select::CondSelectGadget,
|
||||
},
|
||||
use snarkvm_gadgets::utilities::{
|
||||
bits::comparator::{ComparatorGadget, EvaluateLtGadget},
|
||||
boolean::Boolean,
|
||||
eq::{ConditionalEqGadget, EqGadget, EvaluateEqGadget, NEqGadget},
|
||||
select::CondSelectGadget,
|
||||
};
|
||||
use snarkvm_r1cs::{ConstraintSystem, SynthesisError};
|
||||
|
||||
@ -96,7 +93,44 @@ impl<F: PrimeField> ConditionalEqGadget<F> for Char<F> {
|
||||
}
|
||||
|
||||
fn cost() -> usize {
|
||||
2 * <FpGadget<F> as CondSelectGadget<F>>::cost()
|
||||
<FieldType<F> as ConditionalEqGadget<F>>::cost()
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: PrimeField> NEqGadget<F> for Char<F> {
|
||||
fn enforce_not_equal<CS: ConstraintSystem<F>>(&self, cs: CS, other: &Self) -> Result<(), SynthesisError> {
|
||||
self.field.enforce_not_equal(cs, &other.field)
|
||||
}
|
||||
|
||||
fn cost() -> usize {
|
||||
<FieldType<F> as NEqGadget<F>>::cost()
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: PrimeField> CondSelectGadget<F> for Char<F> {
|
||||
fn conditionally_select<CS: ConstraintSystem<F>>(
|
||||
cs: CS,
|
||||
cond: &Boolean,
|
||||
first: &Self,
|
||||
second: &Self,
|
||||
) -> Result<Self, SynthesisError> {
|
||||
let field = FieldType::<F>::conditionally_select(cs, cond, &first.field, &second.field)?;
|
||||
|
||||
if field == first.field {
|
||||
return Ok(Char {
|
||||
character: first.character,
|
||||
field,
|
||||
});
|
||||
}
|
||||
|
||||
Ok(Char {
|
||||
character: second.character,
|
||||
field,
|
||||
})
|
||||
}
|
||||
|
||||
fn cost() -> usize {
|
||||
<FieldType<F> as CondSelectGadget<F>>::cost()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,7 @@ use snarkvm_gadgets::{
|
||||
alloc::AllocGadget,
|
||||
bits::comparator::{ComparatorGadget, EvaluateLtGadget},
|
||||
boolean::Boolean,
|
||||
eq::{ConditionalEqGadget, EqGadget, EvaluateEqGadget},
|
||||
eq::{ConditionalEqGadget, EqGadget, EvaluateEqGadget, NEqGadget},
|
||||
select::CondSelectGadget,
|
||||
uint::UInt8,
|
||||
ToBitsBEGadget,
|
||||
@ -37,8 +37,6 @@ use snarkvm_gadgets::{
|
||||
},
|
||||
};
|
||||
use snarkvm_r1cs::{ConstraintSystem, SynthesisError};
|
||||
|
||||
use snarkvm_gadgets::utilities::eq::NEqGadget;
|
||||
use std::{borrow::Borrow, cmp::Ordering};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
|
@ -148,7 +148,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConditionalEqGadget<F> for ConstrainedV
|
||||
bool_1.conditional_enforce_equal(cs, bool_2, condition)
|
||||
}
|
||||
(ConstrainedValue::Char(char_1), ConstrainedValue::Char(char_2)) => {
|
||||
char_1.field.conditional_enforce_equal(cs, &char_2.field, condition)
|
||||
char_1.conditional_enforce_equal(cs, char_2, condition)
|
||||
}
|
||||
(ConstrainedValue::Field(field_1), ConstrainedValue::Field(field_2)) => {
|
||||
field_1.conditional_enforce_equal(cs, field_2, condition)
|
||||
@ -195,7 +195,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> CondSelectGadget<F> for ConstrainedValu
|
||||
ConstrainedValue::Boolean(Boolean::conditionally_select(cs, cond, bool_1, bool_2)?)
|
||||
}
|
||||
(ConstrainedValue::Char(char_1), ConstrainedValue::Char(char_2)) => {
|
||||
ConstrainedValue::Field(FieldType::conditionally_select(cs, cond, &char_1.field, &char_2.field)?)
|
||||
ConstrainedValue::Char(Char::conditionally_select(cs, cond, char_1, char_2)?)
|
||||
}
|
||||
(ConstrainedValue::Field(field_1), ConstrainedValue::Field(field_2)) => {
|
||||
ConstrainedValue::Field(FieldType::conditionally_select(cs, cond, field_1, field_2)?)
|
||||
|
Loading…
Reference in New Issue
Block a user