add partial grouptype module

This commit is contained in:
collin 2020-05-29 16:09:27 -07:00
parent 19f6e64c48
commit 1232481219
3 changed files with 54 additions and 0 deletions

View 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)?)),
// }
// }
}

View 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>;
}

View File

@ -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::*;