diff --git a/Cargo.lock b/Cargo.lock index 5242f17bdd..eff9abd4af 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -576,7 +576,19 @@ dependencies = [ ] [[package]] -name = "language" +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "lazycell" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f" + +[[package]] +name = "leo" version = "0.1.0" dependencies = [ "from-pest", @@ -592,18 +604,6 @@ dependencies = [ "snarkos-models", ] -[[package]] -name = "lazy_static" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" - -[[package]] -name = "lazycell" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f" - [[package]] name = "libc" version = "0.2.67" diff --git a/Cargo.toml b/Cargo.toml index 8056347752..fbf4a1cba7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,27 +1,27 @@ [package] -name = "language" +name = "leo" version = "0.1.0" -authors = ["howardwu "] +authors = ["The Aleo Team "] edition = "2018" [lib] -name = "language" +name = "leo" path = "src/lib.rs" [[bin]] -name = "snarkLang" +name = "leo" path = "src/main.rs" [dependencies] -from-pest = "0.3.1" -lazy_static = "1.3.0" -pest = "2.0" -pest_derive = "2.0" -pest-ast = "0.3.3" -rand = { version = "0.7" } +snarkos-algorithms = { path = "../snarkOS/algorithms", version = "0.8.0" } +snarkos-curves = { path = "../snarkOS/curves", version = "0.8.0" } +snarkos-errors = { path = "../snarkOS/errors", version = "0.8.0" } +snarkos-gadgets = { path = "../snarkOS/gadgets", version = "0.8.0" } +snarkos-models = { path = "../snarkOS/models", version = "0.8.0" } -snarkos-algorithms = { path = "../snarkOS/algorithms" } -snarkos-curves = { path = "../snarkOS/curves" } -snarkos-errors = { path = "../snarkOS/errors" } -snarkos-gadgets = { path = "../snarkOS/gadgets" } -snarkos-models = { path = "../snarkOS/models" } +from-pest = { version = "0.3.1" } +lazy_static = { version = "1.3.0" } +pest = { version = "2.0" } +pest-ast = { version = "0.3.3" } +pest_derive = { version = "2.0" } +rand = { version = "0.7" } diff --git a/README.md b/README.md index de4dc40014..e5fc3ef269 100644 --- a/README.md +++ b/README.md @@ -1 +1 @@ -# language +# leo diff --git a/numbers.csv b/numbers.csv deleted file mode 100644 index 20a98c958e..0000000000 --- a/numbers.csv +++ /dev/null @@ -1,5 +0,0 @@ -65279,1179403647,1463895090 -3.1415927,2.7182817,1.618034 --40,-273.15 -13,42 -65537 diff --git a/simple.program b/simple.leo similarity index 100% rename from simple.program rename to simple.leo diff --git a/simple_import.program b/simple_import.leo similarity index 100% rename from simple_import.program rename to simple_import.leo diff --git a/src/ast.rs b/src/ast.rs index ed280a5d9d..d9e5438ce8 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -1,4 +1,4 @@ -//! Abstract syntax tree (ast) representation from language.pest. +//! Abstract syntax tree (ast) representation from leo.pest. //! //! @file zokrates_program.rs //! @author Howard Wu @@ -15,7 +15,7 @@ use pest_ast::FromPest; use std::fmt; #[derive(Parser)] -#[grammar = "language.pest"] +#[grammar = "leo.pest"] pub struct LanguageParser; pub fn parse(input: &str) -> Result, Error> { diff --git a/src/csv.pest b/src/csv.pest deleted file mode 100644 index bb9af516ff..0000000000 --- a/src/csv.pest +++ /dev/null @@ -1,3 +0,0 @@ -field = { (ASCII_DIGIT | "." | "-")+ } -record = { field ~ ("," ~ field)* } -file = { SOI ~ (record ~ ("\r\n" | "\n"))* ~ EOI } diff --git a/src/csv_main.rs b/src/csv_main.rs deleted file mode 100644 index 13cd808d0d..0000000000 --- a/src/csv_main.rs +++ /dev/null @@ -1,44 +0,0 @@ -extern crate pest; -#[macro_use] -extern crate pest_derive; - -use pest::Parser; -use std::fs; - -#[derive(Parser)] -#[grammar = "csv.pest"] -pub struct CSVParser; - -fn main() { - let unparsed_file = fs::read_to_string("numbers.csv").expect("cannot read file"); - - let file = CSVParser::parse(Rule::file, &unparsed_file) - .expect("unsuccessful parse") // unwrap the parse result - .next().unwrap(); // get and unwrap the `file` rule; never fails - - let mut field_sum: f64 = 0.0; - let mut record_count: u64 = 0; - - for record in file.into_inner() { - match record.as_rule() { - Rule::record => { - record_count += 1; - - for field in record.into_inner() { - field_sum += field.as_str().parse::().unwrap(); - } - } - Rule::EOI => (), - _ => unreachable!(), - } - } - - println!("Sum of fields: {}", field_sum); - println!("Number of records: {}", record_count); - - // let successful_parse = CSVParser::parse(Rule::field, "-273.15"); - // println!("{:?}", successful_parse); - // - // let unsuccessful_parse = CSVParser::parse(Rule::field, "this is not a number"); - // println!("{:?}", unsuccessful_parse); -} diff --git a/src/language.pest b/src/leo.pest similarity index 96% rename from src/language.pest rename to src/leo.pest index d1b926f7bb..cada48a885 100644 --- a/src/language.pest +++ b/src/leo.pest @@ -1,4 +1,3 @@ -// file = { SOI ~ NEWLINE* ~ import_section* ~ NEWLINE* ~ EOI } /// Visibility visibility_public = { "public" } @@ -48,6 +47,7 @@ operation_binary = _ { // operation_div_assign = { "/=" } /// Types + ty_u32 = {"u32"} ty_field = {"fe"} ty_bool = {"bool"} @@ -59,6 +59,7 @@ ty = {ty_array | ty_basic | ty_struct} type_list = _{(ty ~ ("," ~ ty)*)?} /// Values + value_number = @{ "-"? ~ ("0" | ASCII_NONZERO_DIGIT ~ ASCII_DIGIT*)} value_u32 = { value_number ~ ty_u32} value_field = { value_number ~ ty_field } @@ -81,12 +82,15 @@ expression_primitive = { value | variable } from_expression = { expression } to_expression = { expression } + range = { from_expression? ~ ".." ~ to_expression } range_or_expression = { range | expression } + access_array = { "[" ~ range_or_expression ~ "]" } access_call = { "(" ~ expression_tuple ~ ")" } access_member = { "." ~ variable } access = { access_array | access_call | access_member } + expression_postfix = { variable ~ access+ } assignee_access = { access_array | access_member } @@ -117,7 +121,6 @@ expression_conditional = { "if" ~ expression ~ "then" ~ expression ~ "else" ~ ex /// Expressions -// Consider structs, conditionals, postfix, primary, inline array, array initializer, and unary expression_term = { ("(" ~ expression ~ ")") | expression_inline_struct @@ -170,6 +173,6 @@ from_import = { "from" ~ "\"" ~ import_source ~ "\"" ~ "import" ~ variable ~ ("a main_import = {"import" ~ "\"" ~ import_source ~ "\"" ~ ("as" ~ variable)? ~ NEWLINE+} import_source = @{(!"\"" ~ ANY)*} -/// Abstract Syntax Tree File +/// Program File file = { SOI ~ NEWLINE* ~ import* ~ NEWLINE* ~ struct_definition* ~ NEWLINE* ~ function_definition* ~ NEWLINE* ~ EOI } diff --git a/src/lib.rs b/src/lib.rs index b63467e415..2a09da9bab 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,16 +1,11 @@ +extern crate from_pest; extern crate pest; +extern crate pest_ast; #[macro_use] extern crate pest_derive; -extern crate from_pest; -// #[macro_use] -extern crate pest_ast; - #[macro_use] extern crate lazy_static; pub mod ast; - -pub mod aleo_program; - -// pub mod zokrates_program; +pub mod program; diff --git a/src/main.rs b/src/main.rs index e1f20ddbf0..d807d6fb46 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,25 +1,23 @@ -use language::*; +use leo::*; + +use snarkos_algorithms::snark::{ + create_random_proof, generate_random_parameters, prepare_verifying_key, verify_proof, +}; +use snarkos_curves::bls12_377::{Bls12_377, Fr}; +use snarkos_errors::gadgets::SynthesisError; +use snarkos_models::{ + curves::{Field, PrimeField}, + gadgets::r1cs::{ConstraintSynthesizer, ConstraintSystem} +}; use from_pest::FromPest; +use rand::thread_rng; use std::{ fs, marker::PhantomData, time::{Duration, Instant}, }; -use snarkos_curves::bls12_377::{Bls12_377, Fr}; -use snarkos_errors::gadgets::SynthesisError; -use snarkos_models::curves::{Field, PrimeField}; -use snarkos_models::gadgets::r1cs::{ConstraintSynthesizer, ConstraintSystem}; - -use snarkos_algorithms::snark::{ - create_random_proof, generate_random_parameters, prepare_verifying_key, verify_proof, -}; - -use rand::thread_rng; - -// use std::env; - pub struct Benchmark { _engine: PhantomData, } @@ -38,20 +36,20 @@ impl ConstraintSynthesizer for Benchmark { cs: &mut CS, ) -> Result<(), SynthesisError> { // Read in file as string - let unparsed_file = fs::read_to_string("simple.program").expect("cannot read file"); + let unparsed_file = fs::read_to_string("simple.leo").expect("cannot read file"); - // Parse the file using langauge.pest + // Parse the file using leo.pest let mut file = ast::parse(&unparsed_file).expect("unsuccessful parse"); // Build the abstract syntax tree let syntax_tree = ast::File::from_pest(&mut file).expect("infallible"); // println!("{:#?}", syntax_tree); - let program = aleo_program::Program::<'_, F>::from(syntax_tree); + let program = program::Program::<'_, F>::from(syntax_tree); println!(" compiled: {:#?}", program); let program = program.name("simple".into()); - aleo_program::ResolvedProgram::generate_constraints(cs, program); + program::ResolvedProgram::generate_constraints(cs, program); Ok(()) } @@ -67,8 +65,8 @@ fn main() { let start = Instant::now(); let params = { - let c = Benchmark::::new(); - generate_random_parameters::(c, rng).unwrap() + let circuit = Benchmark::::new(); + generate_random_parameters::(circuit, rng).unwrap() }; let prepared_verifying_key = prepare_verifying_key::(¶ms.vk); @@ -87,13 +85,16 @@ fn main() { let start = Instant::now(); - let _ = verify_proof(&prepared_verifying_key, &proof, &[]).unwrap(); + let is_success = verify_proof(&prepared_verifying_key, &proof, &[]).unwrap(); verifying += start.elapsed(); - println!(" Setup time : {:?} seconds", setup.as_secs()); - println!(" Proving time : {:?} seconds", proving.as_secs()); - println!(" Verifying time: {:?} seconds", verifying.as_secs()); + println!(" "); + println!(" Setup time : {:?} milliseconds", setup.as_millis()); + println!(" Prover time : {:?} milliseconds", proving.as_millis()); + println!(" Verifier time : {:?} milliseconds", verifying.as_millis()); + println!(" Verifier output : {}", is_success); + println!(" "); // let mut cs = TestConstraintSystem::::new(); // diff --git a/src/aleo_program/constraints/boolean.rs b/src/program/constraints/boolean.rs similarity index 98% rename from src/aleo_program/constraints/boolean.rs rename to src/program/constraints/boolean.rs index b97d8204fc..ff20c10ed9 100644 --- a/src/aleo_program/constraints/boolean.rs +++ b/src/program/constraints/boolean.rs @@ -4,8 +4,8 @@ //! @author Collin Chin //! @date 2020 -use crate::aleo_program::constraints::{new_scope_from_variable, ResolvedProgram, ResolvedValue}; -use crate::aleo_program::{ +use crate::program::constraints::{new_scope_from_variable, ResolvedProgram, ResolvedValue}; +use crate::program::{ new_variable_from_variable, BooleanExpression, BooleanSpreadOrExpression, Parameter, Variable, }; diff --git a/src/aleo_program/constraints/constraints.rs b/src/program/constraints/constraints.rs similarity index 97% rename from src/aleo_program/constraints/constraints.rs rename to src/program/constraints/constraints.rs index e46daf2bb1..58ecfe73d4 100644 --- a/src/aleo_program/constraints/constraints.rs +++ b/src/program/constraints/constraints.rs @@ -4,9 +4,9 @@ //! @author Collin Chin //! @date 2020 -use crate::aleo_program::constraints::{new_scope_from_variable, ResolvedProgram, ResolvedValue}; -use crate::aleo_program::{Expression, Function, Import, Program, Statement, Type}; use crate::ast; +use crate::program::constraints::{new_scope_from_variable, ResolvedProgram, ResolvedValue}; +use crate::program::{Expression, Function, Import, Program, Statement, Type}; use from_pest::FromPest; use snarkos_models::curves::{Field, PrimeField}; diff --git a/src/aleo_program/constraints/expression.rs b/src/program/constraints/expression.rs similarity index 98% rename from src/aleo_program/constraints/expression.rs rename to src/program/constraints/expression.rs index 59ee185396..f36dfae8fa 100644 --- a/src/aleo_program/constraints/expression.rs +++ b/src/program/constraints/expression.rs @@ -4,8 +4,8 @@ //! @author Collin Chin //! @date 2020 -use crate::aleo_program::constraints::{new_scope_from_variable, ResolvedProgram, ResolvedValue}; -use crate::aleo_program::{ +use crate::program::constraints::{new_scope_from_variable, ResolvedProgram, ResolvedValue}; +use crate::program::{ Expression, IntegerExpression, IntegerRangeOrExpression, StructMember, Variable, }; diff --git a/src/aleo_program/constraints/field_element.rs b/src/program/constraints/field_element.rs similarity index 98% rename from src/aleo_program/constraints/field_element.rs rename to src/program/constraints/field_element.rs index d299c48d13..d3d0b97710 100644 --- a/src/aleo_program/constraints/field_element.rs +++ b/src/program/constraints/field_element.rs @@ -4,8 +4,8 @@ //! @author Collin Chin //! @date 2020 -use crate::aleo_program::constraints::{new_scope_from_variable, ResolvedProgram, ResolvedValue}; -use crate::aleo_program::{ +use crate::program::constraints::{new_scope_from_variable, ResolvedProgram, ResolvedValue}; +use crate::program::{ new_variable_from_variable, FieldExpression, FieldSpreadOrExpression, Parameter, Variable, }; diff --git a/src/aleo_program/constraints/integer.rs b/src/program/constraints/integer.rs similarity index 97% rename from src/aleo_program/constraints/integer.rs rename to src/program/constraints/integer.rs index a8101f9a08..e84bef1c68 100644 --- a/src/aleo_program/constraints/integer.rs +++ b/src/program/constraints/integer.rs @@ -4,16 +4,13 @@ //! @author Collin Chin //! @date 2020 -use crate::aleo_program::constraints::{new_scope_from_variable, ResolvedProgram, ResolvedValue}; -use crate::aleo_program::{ - new_variable_from_variable, Integer, IntegerExpression, IntegerSpreadOrExpression, Parameter, - Variable, -}; +use crate::program::constraints::{new_scope_from_variable, ResolvedProgram, ResolvedValue}; +use crate::program::{Integer, IntegerExpression, IntegerSpreadOrExpression, Variable, Parameter, new_variable_from_variable}; use snarkos_models::curves::{Field, PrimeField}; use snarkos_models::gadgets::{ r1cs::ConstraintSystem, - utilities::{ boolean::Boolean, eq::ConditionalEqGadget, uint32::UInt32}, + utilities::{boolean::Boolean, eq::ConditionalEqGadget, uint32::UInt32}, }; impl> ResolvedProgram { diff --git a/src/aleo_program/constraints/mod.rs b/src/program/constraints/mod.rs similarity index 100% rename from src/aleo_program/constraints/mod.rs rename to src/program/constraints/mod.rs diff --git a/src/aleo_program/constraints/resolved_program.rs b/src/program/constraints/resolved_program.rs similarity index 95% rename from src/aleo_program/constraints/resolved_program.rs rename to src/program/constraints/resolved_program.rs index 43ebf59a5d..f006198ac0 100644 --- a/src/aleo_program/constraints/resolved_program.rs +++ b/src/program/constraints/resolved_program.rs @@ -4,8 +4,8 @@ //! @author Collin Chin //! @date 2020 -use crate::aleo_program::constraints::ResolvedValue; -use crate::aleo_program::types::Variable; +use crate::program::constraints::ResolvedValue; +use crate::program::types::Variable; use snarkos_models::curves::{Field, PrimeField}; use snarkos_models::gadgets::r1cs::ConstraintSystem; diff --git a/src/aleo_program/constraints/resolved_value.rs b/src/program/constraints/resolved_value.rs similarity index 97% rename from src/aleo_program/constraints/resolved_value.rs rename to src/program/constraints/resolved_value.rs index cf9d469484..3888060ed8 100644 --- a/src/aleo_program/constraints/resolved_value.rs +++ b/src/program/constraints/resolved_value.rs @@ -4,7 +4,7 @@ //! @author Collin Chin //! @date 2020 -use crate::aleo_program::types::{Function, Struct, StructMember, Variable}; +use crate::program::types::{Function, Struct, StructMember, Variable}; use snarkos_models::curves::{Field, PrimeField}; use snarkos_models::gadgets::{utilities::boolean::Boolean, utilities::uint32::UInt32}; diff --git a/src/aleo_program/constraints/statement.rs b/src/program/constraints/statement.rs similarity index 98% rename from src/aleo_program/constraints/statement.rs rename to src/program/constraints/statement.rs index 71cd754f5b..5567ddeae8 100644 --- a/src/aleo_program/constraints/statement.rs +++ b/src/program/constraints/statement.rs @@ -4,8 +4,8 @@ //! @author Collin Chin //! @date 2020 -use crate::aleo_program::constraints::{new_scope_from_variable, ResolvedProgram, ResolvedValue}; -use crate::aleo_program::{ +use crate::program::constraints::{new_scope_from_variable, ResolvedProgram, ResolvedValue}; +use crate::program::{ Assignee, Expression, IntegerExpression, IntegerRangeOrExpression, Statement, Variable, }; diff --git a/src/aleo_program/imports.rs b/src/program/imports.rs similarity index 98% rename from src/aleo_program/imports.rs rename to src/program/imports.rs index 4688a0815c..49020fac9f 100644 --- a/src/aleo_program/imports.rs +++ b/src/program/imports.rs @@ -47,7 +47,7 @@ impl<'ast> Import<'ast> { pub fn get_file(&self) -> String { let path = self.get_source().to_str().unwrap(); - format!("{}.program", path) + format!("{}.leo", path) } } diff --git a/src/aleo_program/mod.rs b/src/program/mod.rs similarity index 100% rename from src/aleo_program/mod.rs rename to src/program/mod.rs index c861ac3753..274f6b930f 100644 --- a/src/aleo_program/mod.rs +++ b/src/program/mod.rs @@ -4,15 +4,15 @@ //! @author Collin Chin //! @date 2020 -pub mod types; -pub use self::types::*; - pub mod constraints; pub use self::constraints::*; pub mod imports; pub use self::imports::*; +pub mod types; +pub use self::types::*; + pub mod types_display; pub use self::types_display::*; diff --git a/src/aleo_program/types.rs b/src/program/types.rs similarity index 99% rename from src/aleo_program/types.rs rename to src/program/types.rs index 278d4b62db..33b20da0b9 100644 --- a/src/aleo_program/types.rs +++ b/src/program/types.rs @@ -5,7 +5,7 @@ //! @author Collin Chin //! @date 2020 -use crate::aleo_program::Import; +use crate::program::Import; use snarkos_models::curves::{Field, PrimeField}; use std::collections::HashMap; diff --git a/src/aleo_program/types_display.rs b/src/program/types_display.rs similarity index 99% rename from src/aleo_program/types_display.rs rename to src/program/types_display.rs index aca420f059..4e890f2c97 100644 --- a/src/aleo_program/types_display.rs +++ b/src/program/types_display.rs @@ -4,7 +4,7 @@ //! @author Collin Chin //! @date 2020 -use crate::aleo_program::{ +use crate::program::{ Assignee, BooleanExpression, BooleanSpreadOrExpression, Expression, FieldExpression, FieldSpreadOrExpression, Function, FunctionName, Integer, IntegerExpression, IntegerRangeOrExpression, IntegerSpreadOrExpression, Parameter, Statement, Struct, StructField, diff --git a/src/aleo_program/types_from.rs b/src/program/types_from.rs similarity index 99% rename from src/aleo_program/types_from.rs rename to src/program/types_from.rs index 1b9c986fca..fe409e416a 100644 --- a/src/aleo_program/types_from.rs +++ b/src/program/types_from.rs @@ -4,7 +4,7 @@ //! @author Collin Chin //! @date 2020 -use crate::aleo_program::{types, Import, PathString}; +use crate::program::{types, Import, PathString}; use crate::ast; use snarkos_models::curves::{Field, PrimeField};