Merge pull request #322 from AleoHQ/feature/n-group-notation

Feature/n group notation
This commit is contained in:
Howard Wu 2020-09-02 13:38:29 -07:00 committed by GitHub
commit 754725f5b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 8 deletions

4
Cargo.lock generated
View File

@ -1398,9 +1398,9 @@ dependencies = [
[[package]]
name = "libz-sys"
version = "1.1.0"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "af67924b8dd885cccea261866c8ce5b74d239d272e154053ff927dae839f5ae9"
checksum = "23b34178653005c1181711c333f0e5604a14a1b5115c814fd42304bdd16245e0"
dependencies = [
"cc",
"libc",

View File

@ -98,4 +98,10 @@ impl GroupError {
Self::new_from_span(message, span)
}
pub fn n_group(number: String, span: Span) -> Self {
let message = format!("cannot multiply group generator by \"{}\"", number);
Self::new_from_span(message, span)
}
}

View File

@ -24,7 +24,7 @@ use snarkos_curves::{
use snarkos_errors::gadgets::SynthesisError;
use snarkos_gadgets::curves::edwards_bls12::EdwardsBlsGadget;
use snarkos_models::{
curves::{AffineCurve, One, TEModelParameters, Zero},
curves::{AffineCurve, Fp256, One, TEModelParameters, Zero},
gadgets::{
curves::{FieldGadget, FpGadget, GroupGadget},
r1cs::ConstraintSystem,
@ -41,7 +41,7 @@ use snarkos_models::{
};
use std::{
borrow::Borrow,
ops::{Neg, Sub},
ops::{Mul, Neg, Sub},
str::FromStr,
};
@ -142,12 +142,14 @@ impl EdwardsGroupType {
}
pub fn edwards_affine_from_single(number: String, span: Span) -> Result<EdwardsAffine, GroupError> {
if number.eq("1") {
return Ok(edwards_affine_one());
} else if number.eq("0") {
if number.eq("0") {
return Ok(EdwardsAffine::zero());
} else {
Self::edwards_affine_from_x_str(number, span.clone(), None, span)
let one = edwards_affine_one();
let number_value = Fp256::from_str(&number).map_err(|_| GroupError::n_group(number, span))?;
let result: EdwardsAffine = one.mul(&number_value);
return Ok(result);
}
}