update field and group modules

This commit is contained in:
collin 2020-07-07 19:53:37 -07:00
parent a6092e9a2f
commit b0acd5ea5a
35 changed files with 54 additions and 40 deletions

View File

@ -111,7 +111,7 @@ type_u64 = { "u64" }
type_u128 = { "u128" }
// Declared in types/field_type.rs
type_field = { "value.field" }
type_field = { "field" }
// Declared in types/group_type.rs
type_group = { "group" }

View File

@ -3,9 +3,14 @@
use crate::{
address::Address,
constraints::{group::group_from_input, new_scope, ConstrainedProgram},
constraints::{new_scope, ConstrainedProgram},
errors::{FunctionError, StatementError},
value::{boolean::input::bool_from_input, field::input::field_from_input, ConstrainedValue},
value::{
boolean::input::bool_from_input,
field::input::field_from_input,
group::input::group_from_input,
ConstrainedValue,
},
GroupType,
Integer,
};

View File

@ -9,8 +9,6 @@ pub use self::expression::*;
pub mod generate_constraints;
pub use self::generate_constraints::*;
pub mod group;
pub mod program;
pub use self::program::*;

View File

@ -15,9 +15,6 @@ pub mod definitions;
pub mod errors;
pub mod group;
pub use self::group::*;
pub mod imports;
pub use self::imports::*;

View File

@ -1,4 +1,4 @@
//! Methods to enforce constraints on an input boolean value in a resolved Leo program.
//! Methods to enforce constraints on input boolean values in a resolved Leo program.
use crate::{errors::BooleanError, value::ConstrainedValue, GroupType};
use leo_types::{InputValue, Span};

View File

@ -1,4 +1,4 @@
//! A data type that represents a value.field value
//! A data type that represents a field value
use crate::{
comparator::{ComparatorGadget, EvaluateLtGadget},

View File

@ -1,4 +1,4 @@
//! Methods to enforce constraints on value.field elements in a resolved Leo program.
//! Methods to enforce constraints on input field values in a resolved Leo program.
use crate::{errors::FieldError, value::ConstrainedValue, FieldType, GroupType};
use leo_types::{InputValue, Span};

View File

@ -1,3 +1,5 @@
//! Methods to enforce constraints on fields in a resolved Leo program.
pub mod input;
pub mod field_type;

View File

@ -18,8 +18,6 @@ use snarkos_models::{
};
use std::fmt::{Debug, Display};
pub mod edwards_bls12;
pub trait GroupType<F: Field>:
Sized
+ Clone

View File

@ -0,0 +1,8 @@
//! Methods to enforce constraints on points in the affine group in a resolved Leo program.
pub mod input;
pub mod group_type;
pub use self::group_type::*;
pub mod targets;

View File

@ -0,0 +1 @@
pub mod edwards_bls12;

View File

@ -1,12 +1,17 @@
//! Methods to enforce constraints on values in a resolved Leo program.
pub mod boolean;
pub(crate) mod comparator;
pub mod integer;
pub use self::integer::*;
pub mod field;
pub use self::field::*;
pub mod group;
pub use self::group::*;
pub mod integer;
pub use self::integer::*;
pub mod value;
pub use self::value::*;

View File

@ -1,3 +1,3 @@
function main(a: value.field, b: value.field) -> value.field {
function main(a: field, b: field) -> field {
return a + b
}

View File

@ -1,3 +1,3 @@
function main(a: value.field, b: value.field) {
function main(a: field, b: field) {
assert_eq!(a, b);
}

View File

@ -1,3 +1,3 @@
function main(a: value.field, b: value.field) -> value.field {
function main(a: field, b: field) -> field {
return a / b
}

View File

@ -1,3 +1,3 @@
function main(a: value.field, b: value.field) -> bool {
function main(a: field, b: field) -> bool {
return a == b
}

View File

@ -1,3 +1,3 @@
function main(a: value.field, b: value.field) -> bool {
function main(a: field, b: field) -> bool {
return a >= b
}

View File

@ -1,3 +1,3 @@
function main(a: value.field, b: value.field) -> bool {
function main(a: field, b: field) -> bool {
return a > b
}

View File

@ -1,3 +1,3 @@
function main(f: value.field) -> value.field{
function main(f: field) -> field{
return f
}

View File

@ -1,3 +1,3 @@
function main(a: value.field, b: value.field) -> bool {
function main(a: field, b: field) -> bool {
return a <= b
}

View File

@ -1,3 +1,3 @@
function main(a: value.field, b: value.field) -> bool {
function main(a: field, b: field) -> bool {
return a < b
}

View File

@ -55,7 +55,7 @@ fn output_one(program: EdwardsTestCompiler) {
fn fail_field(program: EdwardsTestCompiler) {
match get_error(program) {
CompilerError::FunctionError(FunctionError::FieldError(FieldError::Error(_string))) => {}
error => panic!("Expected invalid value.field error, got {}", error),
error => panic!("Expected invalid field error, got {}", error),
}
}
@ -450,7 +450,7 @@ fn test_ternary() {
let mut program_1 = parse_program(bytes).unwrap();
let mut program_2 = program_1.clone();
// true -> value.field 1
// true -> field 1
program_1.set_inputs(vec![
Some(InputValue::Boolean(true)),
Some(InputValue::Field(r1.to_string())),
@ -459,7 +459,7 @@ fn test_ternary() {
output_expected_allocated(program_1, g1);
// false -> value.field 2
// false -> field 2
program_2.set_inputs(vec![
Some(InputValue::Boolean(false)),
Some(InputValue::Field(r1.to_string())),

View File

@ -1,3 +1,3 @@
function main(a: value.field, b: value.field) -> value.field {
function main(a: field, b: field) -> field {
return a * b
}

View File

@ -1,3 +1,3 @@
function main() -> value.field {
function main() -> field {
return 1field
}

View File

@ -1,3 +1,3 @@
function main(a: value.field, b: value.field) -> value.field {
function main(a: field, b: field) -> field {
return a - b
}

View File

@ -1,3 +1,3 @@
function main(b: bool, f1: value.field, f2: value.field) -> value.field {
function main(b: bool, f1: field, f2: field) -> field {
return if b ? f1 : f2
}

View File

@ -1,3 +1,3 @@
function main() -> value.field {
function main() -> field {
return 0field
}

View File

@ -1,8 +1,8 @@
function foo() -> value.field {
function foo() -> field {
return myGlobal
}
function main() -> value.field {
function main() -> field {
const myGlobal = 42field;
return foo()
}

View File

@ -6,7 +6,7 @@ use crate::{
EdwardsConstrainedValue,
EdwardsTestCompiler,
};
use leo_compiler::{group::edwards_bls12::EdwardsGroupType, ConstrainedValue};
use leo_compiler::{group::targets::edwards_bls12::EdwardsGroupType, ConstrainedValue};
use leo_types::InputValue;
use snarkos_curves::edwards_bls12::{EdwardsAffine, EdwardsParameters, Fq};

View File

@ -15,7 +15,7 @@ pub mod syntax;
use leo_compiler::{
compiler::Compiler,
errors::{CompilerError, FunctionError, StatementError},
group::edwards_bls12::EdwardsGroupType,
group::targets::edwards_bls12::EdwardsGroupType,
ConstrainedValue,
};

View File

@ -5,7 +5,7 @@ use crate::{
errors::CLIError,
files::{ChecksumFile, LibFile, MainFile, Manifest, LIB_FILE_NAME, MAIN_FILE_NAME},
};
use leo_compiler::{compiler::Compiler, group::edwards_bls12::EdwardsGroupType};
use leo_compiler::{compiler::Compiler, group::targets::edwards_bls12::EdwardsGroupType};
use snarkos_algorithms::snark::KeypairAssembly;
use snarkos_curves::{bls12_377::Bls12_377, edwards_bls12::Fq};

View File

@ -6,7 +6,7 @@ use crate::{
errors::{CLIError, RunError, VerificationKeyFileError},
files::{Manifest, ProvingKeyFile, VerificationKeyFile, MAIN_FILE_NAME},
};
use leo_compiler::{compiler::Compiler, group::edwards_bls12::EdwardsGroupType};
use leo_compiler::{compiler::Compiler, group::targets::edwards_bls12::EdwardsGroupType};
use snarkos_algorithms::snark::{generate_random_parameters, prepare_verifying_key, Parameters, PreparedVerifyingKey};
use snarkos_curves::{bls12_377::Bls12_377, edwards_bls12::Fq};

View File

@ -5,7 +5,7 @@ use crate::{
errors::{CLIError, TestError},
files::{MainFile, Manifest, MAIN_FILE_NAME},
};
use leo_compiler::{compiler::Compiler, group::edwards_bls12::EdwardsGroupType};
use leo_compiler::{compiler::Compiler, group::targets::edwards_bls12::EdwardsGroupType};
use snarkos_curves::edwards_bls12::Fq;
use snarkos_models::gadgets::r1cs::TestConstraintSystem;