mirror of
https://github.com/AleoHQ/leo.git
synced 2024-12-01 18:56:38 +03:00
merge development
This commit is contained in:
commit
ccd6092ff3
26
Cargo.lock
generated
26
Cargo.lock
generated
@ -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"
|
||||
|
30
Cargo.toml
30
Cargo.toml
@ -1,27 +1,27 @@
|
||||
[package]
|
||||
name = "language"
|
||||
name = "leo"
|
||||
version = "0.1.0"
|
||||
authors = ["howardwu <howardwu@berkeley.edu>"]
|
||||
authors = ["The Aleo Team <hello@aleo.org>"]
|
||||
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" }
|
||||
|
@ -1,5 +0,0 @@
|
||||
65279,1179403647,1463895090
|
||||
3.1415927,2.7182817,1.618034
|
||||
-40,-273.15
|
||||
13,42
|
||||
65537
|
|
@ -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 <howard@aleo.org>
|
||||
@ -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<Pairs<Rule>, Error<Rule>> {
|
||||
|
@ -1,3 +0,0 @@
|
||||
field = { (ASCII_DIGIT | "." | "-")+ }
|
||||
record = { field ~ ("," ~ field)* }
|
||||
file = { SOI ~ (record ~ ("\r\n" | "\n"))* ~ EOI }
|
@ -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::<f64>().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);
|
||||
}
|
@ -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 }
|
11
src/lib.rs
11
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;
|
||||
|
49
src/main.rs
49
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<F: Field + PrimeField> {
|
||||
_engine: PhantomData<F>,
|
||||
}
|
||||
@ -38,20 +36,20 @@ impl<F: Field + PrimeField> ConstraintSynthesizer<F> for Benchmark<F> {
|
||||
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::<Fr>::new();
|
||||
generate_random_parameters::<Bls12_377, _, _>(c, rng).unwrap()
|
||||
let circuit = Benchmark::<Fr>::new();
|
||||
generate_random_parameters::<Bls12_377, _, _>(circuit, rng).unwrap()
|
||||
};
|
||||
|
||||
let prepared_verifying_key = prepare_verifying_key::<Bls12_377>(¶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::<Fr>::new();
|
||||
//
|
||||
|
@ -4,8 +4,8 @@
|
||||
//! @author Collin Chin <collin@aleo.org>
|
||||
//! @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,
|
||||
};
|
||||
|
@ -4,9 +4,9 @@
|
||||
//! @author Collin Chin <collin@aleo.org>
|
||||
//! @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};
|
@ -4,8 +4,8 @@
|
||||
//! @author Collin Chin <collin@aleo.org>
|
||||
//! @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,
|
||||
};
|
||||
|
@ -4,8 +4,8 @@
|
||||
//! @author Collin Chin <collin@aleo.org>
|
||||
//! @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,
|
||||
};
|
||||
|
@ -4,16 +4,13 @@
|
||||
//! @author Collin Chin <collin@aleo.org>
|
||||
//! @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<F: Field + PrimeField, CS: ConstraintSystem<F>> ResolvedProgram<F, CS> {
|
@ -4,8 +4,8 @@
|
||||
//! @author Collin Chin <collin@aleo.org>
|
||||
//! @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;
|
@ -4,7 +4,7 @@
|
||||
//! @author Collin Chin <collin@aleo.org>
|
||||
//! @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};
|
@ -4,8 +4,8 @@
|
||||
//! @author Collin Chin <collin@aleo.org>
|
||||
//! @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,
|
||||
};
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -4,15 +4,15 @@
|
||||
//! @author Collin Chin <collin@aleo.org>
|
||||
//! @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::*;
|
||||
|
@ -5,7 +5,7 @@
|
||||
//! @author Collin Chin <collin@aleo.org>
|
||||
//! @date 2020
|
||||
|
||||
use crate::aleo_program::Import;
|
||||
use crate::program::Import;
|
||||
|
||||
use snarkos_models::curves::{Field, PrimeField};
|
||||
use std::collections::HashMap;
|
@ -4,7 +4,7 @@
|
||||
//! @author Collin Chin <collin@aleo.org>
|
||||
//! @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,
|
@ -4,7 +4,7 @@
|
||||
//! @author Collin Chin <collin@aleo.org>
|
||||
//! @date 2020
|
||||
|
||||
use crate::aleo_program::{types, Import, PathString};
|
||||
use crate::program::{types, Import, PathString};
|
||||
use crate::ast;
|
||||
|
||||
use snarkos_models::curves::{Field, PrimeField};
|
Loading…
Reference in New Issue
Block a user