mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-09-11 05:45:30 +03:00
impl group add, sub
This commit is contained in:
parent
162c0064b2
commit
c1df2b00b2
@ -51,6 +51,9 @@ impl<F: Field + PrimeField, G: Group, CS: ConstraintSystem<F>> ConstrainedProgra
|
||||
(ConstrainedValue::FieldElement(fe_1), ConstrainedValue::FieldElement(fe_2)) => {
|
||||
self.enforce_field_add(cs, fe_1, fe_2)?
|
||||
}
|
||||
(ConstrainedValue::GroupElement(ge_1), ConstrainedValue::GroupElement(ge_2)) => {
|
||||
Self::evaluate_group_add(ge_1, ge_2)
|
||||
}
|
||||
(val_1, val_2) => {
|
||||
return Err(ExpressionError::IncompatibleTypes(format!(
|
||||
"{} + {}",
|
||||
@ -73,6 +76,9 @@ impl<F: Field + PrimeField, G: Group, CS: ConstraintSystem<F>> ConstrainedProgra
|
||||
(ConstrainedValue::FieldElement(fe_1), ConstrainedValue::FieldElement(fe_2)) => {
|
||||
self.enforce_field_sub(cs, fe_1, fe_2)?
|
||||
}
|
||||
(ConstrainedValue::GroupElement(ge_1), ConstrainedValue::GroupElement(ge_2)) => {
|
||||
Self::evaluate_group_sub(ge_1, ge_2)
|
||||
}
|
||||
(val_1, val_2) => {
|
||||
return Err(ExpressionError::IncompatibleTypes(format!(
|
||||
"{} - {}",
|
||||
@ -166,6 +172,9 @@ impl<F: Field + PrimeField, G: Group, CS: ConstraintSystem<F>> ConstrainedProgra
|
||||
// (ResolvedValue::FieldElement(fe_1), ResolvedValue::FieldElement(fe_2)) => {
|
||||
// Self::field_eq(fe_1, fe_2)
|
||||
// }
|
||||
(ConstrainedValue::GroupElement(ge_1), ConstrainedValue::GroupElement(ge_2)) => {
|
||||
Self::evaluate_group_eq(ge_1, ge_2)
|
||||
}
|
||||
(val_1, val_2) => {
|
||||
return Err(ExpressionError::IncompatibleTypes(format!(
|
||||
"{} == {}",
|
||||
|
32
compiler/src/constraints/group_element.rs
Normal file
32
compiler/src/constraints/group_element.rs
Normal file
@ -0,0 +1,32 @@
|
||||
use crate::{ConstrainedProgram, ConstrainedValue};
|
||||
|
||||
use snarkos_models::{
|
||||
curves::{Field, PrimeField, Group},
|
||||
gadgets::{
|
||||
r1cs::ConstraintSystem,
|
||||
utilities::boolean::Boolean
|
||||
},
|
||||
};
|
||||
|
||||
impl<F: Field + PrimeField, G: Group, CS: ConstraintSystem<F>> ConstrainedProgram<F, G, CS> {
|
||||
pub fn evaluate_group_eq(
|
||||
group_element_1: G,
|
||||
group_element_2: G,
|
||||
) -> ConstrainedValue<F, G> {
|
||||
ConstrainedValue::Boolean(Boolean::constant(group_element_1.eq(&group_element_2)))
|
||||
}
|
||||
|
||||
pub fn evaluate_group_add(
|
||||
group_element_1: G,
|
||||
group_element_2: G,
|
||||
) -> ConstrainedValue<F, G> {
|
||||
ConstrainedValue::GroupElement(group_element_1.add(&group_element_2))
|
||||
}
|
||||
|
||||
pub fn evaluate_group_sub(
|
||||
group_element_1: G,
|
||||
group_element_2: G,
|
||||
) -> ConstrainedValue<F, G> {
|
||||
ConstrainedValue::GroupElement(group_element_1.sub(&group_element_2))
|
||||
}
|
||||
}
|
@ -18,6 +18,9 @@ pub use integer::*;
|
||||
pub mod field_element;
|
||||
pub use field_element::*;
|
||||
|
||||
pub mod group_element;
|
||||
pub use group_element::*;
|
||||
|
||||
pub mod program;
|
||||
pub use program::*;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user