mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-09-11 05:45:30 +03:00
add partial grouptype module
This commit is contained in:
parent
19f6e64c48
commit
1232481219
42
compiler/src/group/edwards_bls12.rs
Normal file
42
compiler/src/group/edwards_bls12.rs
Normal file
@ -0,0 +1,42 @@
|
||||
use crate::errors::GroupError;
|
||||
use crate::GroupType;
|
||||
|
||||
use snarkos_curves::edwards_bls12::{EdwardsParameters, Fq};
|
||||
use snarkos_curves::templates::twisted_edwards_extended::GroupAffine;
|
||||
use snarkos_gadgets::curves::edwards_bls12::FqGadget;
|
||||
use snarkos_gadgets::curves::templates::twisted_edwards::AffineGadget;
|
||||
use snarkos_models::curves::ModelParameters;
|
||||
use std::str::FromStr;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum EdwardsGroupType {
|
||||
Constant(GroupAffine<EdwardsParameters>),
|
||||
Allocated(AffineGadget<EdwardsParameters, Fq, FqGadget>),
|
||||
}
|
||||
|
||||
impl GroupType<<EdwardsParameters as ModelParameters>::BaseField, Fq> for EdwardsGroupType {
|
||||
fn constant(x: String, y: String) -> Result<Self, GroupError> {
|
||||
let x = <EdwardsParameters as ModelParameters>::BaseField::from_str(&x)
|
||||
.map_err(|_| GroupError::InvalidGroup(x))?;
|
||||
let y = <EdwardsParameters as ModelParameters>::BaseField::from_str(&y)
|
||||
.map_err(|_| GroupError::InvalidGroup(y))?;
|
||||
|
||||
Ok(EdwardsGroupType::Constant(GroupAffine::new(x, y)))
|
||||
}
|
||||
|
||||
// fn add<CS: ConstraintSystem<Fq>>(&self, cs: CS, other: &Self) -> Result<Self, GroupElementError> {
|
||||
// match (self, other) {
|
||||
// (EdwardsGroupType::Constant(self_value), EdwardsGroupType::Constant(other_value)) =>
|
||||
// Ok(EdwardsGroupType::Constant(self_value.add(other_value))),
|
||||
//
|
||||
// (EdwardsGroupType::Allocated(self_value), EdwardsGroupType::Allocated(other_value)) => {
|
||||
// let result = <AffineGadget<EdwardsParameters, Fq, FqGadget> as GroupGadget<GroupAffine<EdwardsParameters>, Fq>>::add(self_value, cs, other_value)?;
|
||||
// Ok(EdwardsGroupType::Allocated(result))
|
||||
// }
|
||||
//
|
||||
// (EdwardsGroupType::Constant(constant_value), EdwardsGroupType::Allocated(allocated_value))
|
||||
// | (EdwardsGroupType::Allocated(allocated_value), EdwardsGroupType::Constant(constant_value)) =>
|
||||
// Ok(EdwardsGroupType::Allocated(allocated_value.add_constant(cs, constant_value)?)),
|
||||
// }
|
||||
// }
|
||||
}
|
9
compiler/src/group/mod.rs
Normal file
9
compiler/src/group/mod.rs
Normal file
@ -0,0 +1,9 @@
|
||||
use crate::errors::GroupError;
|
||||
use snarkos_models::curves::Field;
|
||||
use std::fmt::Debug;
|
||||
|
||||
pub mod edwards_bls12;
|
||||
|
||||
pub trait GroupType<NativeF: Field, F: Field>: Sized + Clone + Debug {
|
||||
fn constant(x: String, y: String) -> Result<Self, GroupError>;
|
||||
}
|
@ -22,6 +22,9 @@ pub use self::constraints::*;
|
||||
|
||||
pub mod errors;
|
||||
|
||||
pub mod group;
|
||||
pub use self::group::*;
|
||||
|
||||
pub mod imports;
|
||||
pub use self::imports::*;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user