From 9eca8f83b47aa3c1e163b2d822d71aa38f629fd8 Mon Sep 17 00:00:00 2001 From: collin Date: Mon, 3 Aug 2020 11:30:47 -0700 Subject: [PATCH 1/7] fix pest statement rule --- ast/src/leo.pest | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/ast/src/leo.pest b/ast/src/leo.pest index 5836b95602..b640df819b 100644 --- a/ast/src/leo.pest +++ b/ast/src/leo.pest @@ -294,12 +294,11 @@ statement = { (statement_return | statement_conditional | statement_for - | (statement_multiple_assignment - | statement_macro - | statement_definition - | statement_assign - | statement_expression - ) + | statement_multiple_assignment + | statement_macro + | statement_definition + | statement_assign + | statement_expression ) ~ NEWLINE* } From f49d04c1265b1a2a96c132b613242a3d77b0a6b0 Mon Sep 17 00:00:00 2001 From: collin Date: Mon, 3 Aug 2020 11:55:49 -0700 Subject: [PATCH 2/7] require addresses to contain at least one character in pest --- ast/src/errors/syntax.rs | 1 + ast/src/leo.pest | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/ast/src/errors/syntax.rs b/ast/src/errors/syntax.rs index 253a416149..fa255b07f7 100644 --- a/ast/src/errors/syntax.rs +++ b/ast/src/errors/syntax.rs @@ -15,6 +15,7 @@ impl From> for SyntaxError { Rule::type_integer => "`u32`".to_owned(), Rule::type_field => "`field`".to_owned(), Rule::type_group => "`group`".to_owned(), + Rule::address => "an aleo address: `aleo1...`".to_owned(), Rule::file => "an import, circuit, or function".to_owned(), Rule::identifier => "a variable name".to_owned(), Rule::type_ => "a type".to_owned(), diff --git a/ast/src/leo.pest b/ast/src/leo.pest index 5836b95602..0b79243f95 100644 --- a/ast/src/leo.pest +++ b/ast/src/leo.pest @@ -206,7 +206,7 @@ group_tuple = {"(" ~ value_number ~ "," ~ value_number ~ ")"} group_single_or_tuple = {value_number | group_tuple} // Declared in values/address.rs -address = @{ (LOWERCASE_LETTER | ASCII_DIGIT)* } +address = @{ (LOWERCASE_LETTER | ASCII_DIGIT)+ } // Declared in values/address_value.rs value_address = { type_address ~ "(" ~ address ~ ")" } From e7ad1595a76e445b890455c1285db3b6315435eb Mon Sep 17 00:00:00 2001 From: collin Date: Mon, 3 Aug 2020 12:01:09 -0700 Subject: [PATCH 3/7] add empty address test --- compiler/tests/address/empty.leo | 3 +++ compiler/tests/address/mod.rs | 8 ++++++++ 2 files changed, 11 insertions(+) create mode 100644 compiler/tests/address/empty.leo diff --git a/compiler/tests/address/empty.leo b/compiler/tests/address/empty.leo new file mode 100644 index 0000000000..e5c06d0def --- /dev/null +++ b/compiler/tests/address/empty.leo @@ -0,0 +1,3 @@ +function main() { + let owner = address(); +} \ No newline at end of file diff --git a/compiler/tests/address/mod.rs b/compiler/tests/address/mod.rs index b905056baa..32fd58cfe4 100644 --- a/compiler/tests/address/mod.rs +++ b/compiler/tests/address/mod.rs @@ -20,6 +20,14 @@ fn test_invalid() { let _output = expect_compiler_error(program); } +#[test] +fn test_empty() { + let bytes = include_bytes!("empty.leo"); + let syntax_error = parse_program(bytes).is_err(); + + assert!(syntax_error); +} + #[test] fn test_implicit_valid() { let bytes = include_bytes!("implicit_valid.leo"); From febdf51ca5a011bd38b5a79e3afa21a7a55f1db5 Mon Sep 17 00:00:00 2001 From: collin Date: Mon, 3 Aug 2020 14:50:18 -0700 Subject: [PATCH 4/7] use positive_integer rule for array type and array initializer size --- .../array_initializer_expression.rs | 4 +-- ast/src/leo.pest | 7 ++-- ast/src/types/array_type.rs | 4 +-- ast/src/values/mod.rs | 3 ++ ast/src/values/positive_number.rs | 25 +++++++++++++ typed/src/expression.rs | 35 ++++++++++--------- typed/src/types/type_.rs | 2 +- 7 files changed, 57 insertions(+), 23 deletions(-) create mode 100644 ast/src/values/positive_number.rs diff --git a/ast/src/expressions/array_initializer_expression.rs b/ast/src/expressions/array_initializer_expression.rs index 10b8b2bf1b..53308977a3 100644 --- a/ast/src/expressions/array_initializer_expression.rs +++ b/ast/src/expressions/array_initializer_expression.rs @@ -1,4 +1,4 @@ -use crate::{ast::Rule, common::SpreadOrExpression, values::Value, SpanDef}; +use crate::{ast::Rule, common::SpreadOrExpression, values::PositiveNumber, SpanDef}; use pest::Span; use pest_ast::FromPest; @@ -8,7 +8,7 @@ use serde::Serialize; #[pest_ast(rule(Rule::expression_array_initializer))] pub struct ArrayInitializerExpression<'ast> { pub expression: Box>, - pub count: Value<'ast>, + pub count: PositiveNumber<'ast>, #[pest_ast(outer())] #[serde(with = "SpanDef")] pub span: Span<'ast>, diff --git a/ast/src/leo.pest b/ast/src/leo.pest index 5836b95602..f85a3cb42d 100644 --- a/ast/src/leo.pest +++ b/ast/src/leo.pest @@ -169,7 +169,7 @@ type_self = { "Self" } type_circuit = { identifier } // Declared in types/array_type.rs -type_array = { type_data ~ ("[" ~ value ~ "]")+ } +type_array = { type_data ~ ("[" ~ positive_number ~ "]")+ } type_list = _{ (type_ ~ ("," ~ type_)*)? } @@ -188,6 +188,9 @@ value = { // Declared in values/number_value.rs value_number = @{ (("-" ~ ASCII_NONZERO_DIGIT) | "0" | ASCII_NONZERO_DIGIT) ~ ASCII_DIGIT* } +// Declared in values/number_positive.rs +positive_number = @{ ("0" | ASCII_NONZERO_DIGIT) ~ ASCII_DIGIT*} + // Declared in values/number_implicit_value.rs value_implicit = { value_number } @@ -271,7 +274,7 @@ expression_tuple = _{ (expression ~ ("," ~ expression)*)? } expression = { expression_term ~ (operation_binary ~ expression_term)* } // Declared in expressions/array_initializer_expression.rs -expression_array_initializer = { "[" ~ spread_or_expression ~ ";" ~ value ~ "]" } +expression_array_initializer = { "[" ~ spread_or_expression ~ ";" ~ positive_number ~ "]" } // Declared in expressions/array_inline_expression.rs expression_array_inline = { "[" ~ NEWLINE* ~ inline_array_inner ~ NEWLINE* ~ "]"} diff --git a/ast/src/types/array_type.rs b/ast/src/types/array_type.rs index bc5b04dd7b..2795020e7c 100644 --- a/ast/src/types/array_type.rs +++ b/ast/src/types/array_type.rs @@ -1,4 +1,4 @@ -use crate::{ast::Rule, types::DataType, values::Value, SpanDef}; +use crate::{ast::Rule, types::DataType, values::PositiveNumber, SpanDef}; use pest::Span; use pest_ast::FromPest; @@ -8,7 +8,7 @@ use serde::Serialize; #[pest_ast(rule(Rule::type_array))] pub struct ArrayType<'ast> { pub _type: DataType, - pub dimensions: Vec>, + pub dimensions: Vec>, #[pest_ast(outer())] #[serde(with = "SpanDef")] pub span: Span<'ast>, diff --git a/ast/src/values/mod.rs b/ast/src/values/mod.rs index d3c957c48e..ab289284f1 100644 --- a/ast/src/values/mod.rs +++ b/ast/src/values/mod.rs @@ -22,5 +22,8 @@ pub use number_implicit_value::*; pub mod number_value; pub use number_value::*; +pub mod positive_number; +pub use positive_number::*; + pub mod value; pub use value::*; diff --git a/ast/src/values/positive_number.rs b/ast/src/values/positive_number.rs new file mode 100644 index 0000000000..2ebd822454 --- /dev/null +++ b/ast/src/values/positive_number.rs @@ -0,0 +1,25 @@ +use crate::{ + ast::{span_into_string, Rule}, + span::SpanDef, +}; + +use pest::Span; +use pest_ast::FromPest; +use serde::Serialize; +use std::fmt; + +#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] +#[pest_ast(rule(Rule::positive_number))] +pub struct PositiveNumber<'ast> { + #[pest_ast(outer(with(span_into_string)))] + pub value: String, + #[pest_ast(outer())] + #[serde(with = "SpanDef")] + pub span: Span<'ast>, +} + +impl<'ast> fmt::Display for PositiveNumber<'ast> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{}", self.value) + } +} diff --git a/typed/src/expression.rs b/typed/src/expression.rs index c13c19bff9..95ad64d0bf 100644 --- a/typed/src/expression.rs +++ b/typed/src/expression.rs @@ -13,11 +13,19 @@ use leo_ast::{ TernaryExpression, }, operations::BinaryOperation, - values::{BooleanValue, FieldValue, GroupValue, IntegerValue, NumberImplicitValue, Value}, + values::{ + AddressValue, + BooleanValue, + FieldValue, + GroupValue, + IntegerValue, + NumberImplicitValue, + PositiveNumber as LeoPositiveNumber, + Value, + }, }; - -use leo_ast::values::AddressValue; use leo_input::values::NumberValue; + use serde::{Deserialize, Serialize}; use std::fmt; @@ -104,21 +112,16 @@ impl Expression { } impl<'ast> Expression { - pub(crate) fn get_count_from_value(count: Value<'ast>) -> usize { - match count { - Value::Integer(integer) => integer - .number - .value - .parse::() - .expect("Unable to read array size"), - Value::Implicit(number) => number.number.value.parse::().expect("Unable to read array size"), - size => unimplemented!("Array size should be an integer {}", size), - } - } - pub(crate) fn get_count_from_number(number: NumberValue<'ast>) -> usize { number.value.parse::().expect("Unable to read array size") } + + pub(crate) fn get_count_from_positive_number(number: LeoPositiveNumber<'ast>) -> usize { + number + .value + .parse::() + .expect("Array size should be a positive number") + } } impl<'ast> fmt::Display for Expression { @@ -403,7 +406,7 @@ impl<'ast> From> for Expression { impl<'ast> From> for Expression { fn from(array: ArrayInitializerExpression<'ast>) -> Self { - let count = Expression::get_count_from_value(array.count); + let count = Expression::get_count_from_positive_number(array.count); let expression = Box::new(SpreadOrExpression::from(*array.expression)); Expression::Array(vec![expression; count], Span::from(array.span)) diff --git a/typed/src/types/type_.rs b/typed/src/types/type_.rs index b34b1d60a2..87ca87557c 100644 --- a/typed/src/types/type_.rs +++ b/typed/src/types/type_.rs @@ -101,7 +101,7 @@ impl<'ast> From> for Type { let dimensions = array_type .dimensions .into_iter() - .map(|row| Expression::get_count_from_value(row)) + .map(|row| Expression::get_count_from_positive_number(row)) .collect(); Type::Array(element_type, dimensions) From 1f1a49a5d3c9c11534f5128570303b3220330816 Mon Sep 17 00:00:00 2001 From: collin Date: Mon, 3 Aug 2020 14:56:45 -0700 Subject: [PATCH 5/7] add tests for invalid integers in array size --- compiler/tests/array/initializer_fail.leo | 3 +++ compiler/tests/array/mod.rs | 17 +++++++++++++++++ compiler/tests/array/type_fail.leo | 3 +++ 3 files changed, 23 insertions(+) create mode 100644 compiler/tests/array/initializer_fail.leo create mode 100644 compiler/tests/array/type_fail.leo diff --git a/compiler/tests/array/initializer_fail.leo b/compiler/tests/array/initializer_fail.leo new file mode 100644 index 0000000000..a912075c44 --- /dev/null +++ b/compiler/tests/array/initializer_fail.leo @@ -0,0 +1,3 @@ +function main(a: u8[3]) { + assert_eq!(a, [1u8; -3]); +} \ No newline at end of file diff --git a/compiler/tests/array/mod.rs b/compiler/tests/array/mod.rs index 2667402334..63090e2bb7 100644 --- a/compiler/tests/array/mod.rs +++ b/compiler/tests/array/mod.rs @@ -42,6 +42,14 @@ fn test_registers() { // Expressions +#[test] +fn test_type_fail() { + let program_bytes = include_bytes!("type_fail.leo"); + let syntax_error = parse_program(program_bytes).is_err(); + + assert!(syntax_error); +} + #[test] fn test_inline() { let program_bytes = include_bytes!("inline.leo"); @@ -68,6 +76,15 @@ fn test_initializer() { assert_satisfied(program); } +#[test] +fn test_initializer_fail() { + let program_bytes = include_bytes!("initializer_fail.leo"); + let input_bytes = include_bytes!("input/three_ones.in"); + let syntax_error = parse_program_with_input(program_bytes, input_bytes).is_err(); + + assert!(syntax_error); +} + #[test] fn test_spread() { let program_bytes = include_bytes!("spread.leo"); diff --git a/compiler/tests/array/type_fail.leo b/compiler/tests/array/type_fail.leo new file mode 100644 index 0000000000..c21a6d7b13 --- /dev/null +++ b/compiler/tests/array/type_fail.leo @@ -0,0 +1,3 @@ +let main() { + let a: u32[-2] = [0u32; 2]; +} \ No newline at end of file From a0d294591e9ca09e69a3de0bcfda839f1e93f079 Mon Sep 17 00:00:00 2001 From: collin Date: Mon, 3 Aug 2020 23:22:11 -0700 Subject: [PATCH 6/7] enforce aleo prefix and character length --- ast/src/leo.pest | 2 +- compiler/tests/address/invalid_length.leo | 3 +++ .../address/{invalid.leo => invalid_prefix.leo} | 0 compiler/tests/address/mod.rs | 16 ++++++++++++---- 4 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 compiler/tests/address/invalid_length.leo rename compiler/tests/address/{invalid.leo => invalid_prefix.leo} (100%) diff --git a/ast/src/leo.pest b/ast/src/leo.pest index f7f3d7bb57..ef6fd8d01c 100644 --- a/ast/src/leo.pest +++ b/ast/src/leo.pest @@ -206,7 +206,7 @@ group_tuple = {"(" ~ value_number ~ "," ~ value_number ~ ")"} group_single_or_tuple = {value_number | group_tuple} // Declared in values/address.rs -address = @{ (LOWERCASE_LETTER | ASCII_DIGIT)+ } +address = @{ "aleo" ~ ASCII_DIGIT ~ (LOWERCASE_LETTER | ASCII_DIGIT){58} } // Declared in values/address_value.rs value_address = { type_address ~ "(" ~ address ~ ")" } diff --git a/compiler/tests/address/invalid_length.leo b/compiler/tests/address/invalid_length.leo new file mode 100644 index 0000000000..c1b7f719be --- /dev/null +++ b/compiler/tests/address/invalid_length.leo @@ -0,0 +1,3 @@ +function main() { + let public_key_string = address(aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j88); +} \ No newline at end of file diff --git a/compiler/tests/address/invalid.leo b/compiler/tests/address/invalid_prefix.leo similarity index 100% rename from compiler/tests/address/invalid.leo rename to compiler/tests/address/invalid_prefix.leo diff --git a/compiler/tests/address/mod.rs b/compiler/tests/address/mod.rs index 32fd58cfe4..6c3996c30e 100644 --- a/compiler/tests/address/mod.rs +++ b/compiler/tests/address/mod.rs @@ -13,11 +13,19 @@ fn test_valid() { } #[test] -fn test_invalid() { - let bytes = include_bytes!("invalid.leo"); - let program = parse_program(bytes).unwrap(); +fn test_invalid_prefix() { + let bytes = include_bytes!("invalid_prefix.leo"); + let syntax_error = parse_program(bytes).is_err(); - let _output = expect_compiler_error(program); + assert!(syntax_error); +} + +#[test] +fn test_invalid_length() { + let bytes = include_bytes!("invalid_length.leo"); + let syntax_error = parse_program(bytes).is_err(); + + assert!(syntax_error); } #[test] From d39d50a7a2a96a31e8cbaff78a6ee5de013d2106 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Wed, 5 Aug 2020 10:40:20 +0000 Subject: [PATCH 7/7] Bump snarkos-dpc from `c1bab10` to `90d41a9` Bumps [snarkos-dpc](https://github.com/AleoHQ/snarkOS) from `c1bab10` to `90d41a9`. - [Release notes](https://github.com/AleoHQ/snarkOS/releases) - [Commits](https://github.com/AleoHQ/snarkOS/compare/c1bab103254631c892fade02662eaa66cc145d58...90d41a91b6a431a6cf506a395247e22a3e98b488) Signed-off-by: dependabot-preview[bot] --- Cargo.lock | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1808aa9982..9253e641e0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1284,7 +1284,7 @@ checksum = "3757cb9d89161a2f24e1cf78efa0c1fcff485d18e3f55e0aa3480824ddaa0f3f" [[package]] name = "snarkos-algorithms" version = "0.8.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#c1bab103254631c892fade02662eaa66cc145d58" +source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#90d41a91b6a431a6cf506a395247e22a3e98b488" dependencies = [ "blake2", "derivative", @@ -1304,7 +1304,7 @@ dependencies = [ [[package]] name = "snarkos-curves" version = "0.8.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#c1bab103254631c892fade02662eaa66cc145d58" +source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#90d41a91b6a431a6cf506a395247e22a3e98b488" dependencies = [ "derivative", "rand", @@ -1319,7 +1319,7 @@ dependencies = [ [[package]] name = "snarkos-derives" version = "0.1.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#c1bab103254631c892fade02662eaa66cc145d58" +source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#90d41a91b6a431a6cf506a395247e22a3e98b488" dependencies = [ "proc-macro2 1.0.19", "quote 1.0.7", @@ -1329,7 +1329,7 @@ dependencies = [ [[package]] name = "snarkos-dpc" version = "0.8.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#c1bab103254631c892fade02662eaa66cc145d58" +source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#90d41a91b6a431a6cf506a395247e22a3e98b488" dependencies = [ "blake2", "derivative", @@ -1350,7 +1350,7 @@ dependencies = [ [[package]] name = "snarkos-errors" version = "0.8.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#c1bab103254631c892fade02662eaa66cc145d58" +source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#90d41a91b6a431a6cf506a395247e22a3e98b488" dependencies = [ "base58", "bech32", @@ -1363,7 +1363,7 @@ dependencies = [ [[package]] name = "snarkos-gadgets" version = "0.8.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#c1bab103254631c892fade02662eaa66cc145d58" +source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#90d41a91b6a431a6cf506a395247e22a3e98b488" dependencies = [ "derivative", "digest 0.8.1", @@ -1378,7 +1378,7 @@ dependencies = [ [[package]] name = "snarkos-models" version = "0.8.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#c1bab103254631c892fade02662eaa66cc145d58" +source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#90d41a91b6a431a6cf506a395247e22a3e98b488" dependencies = [ "bincode", "derivative", @@ -1394,7 +1394,7 @@ dependencies = [ [[package]] name = "snarkos-objects" version = "0.8.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#c1bab103254631c892fade02662eaa66cc145d58" +source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#90d41a91b6a431a6cf506a395247e22a3e98b488" dependencies = [ "base58", "bech32", @@ -1415,7 +1415,7 @@ dependencies = [ [[package]] name = "snarkos-parameters" version = "0.8.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#c1bab103254631c892fade02662eaa66cc145d58" +source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#90d41a91b6a431a6cf506a395247e22a3e98b488" dependencies = [ "hex", "snarkos-algorithms", @@ -1427,12 +1427,12 @@ dependencies = [ [[package]] name = "snarkos-profiler" version = "0.8.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#c1bab103254631c892fade02662eaa66cc145d58" +source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#90d41a91b6a431a6cf506a395247e22a3e98b488" [[package]] name = "snarkos-utilities" version = "0.8.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#c1bab103254631c892fade02662eaa66cc145d58" +source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#90d41a91b6a431a6cf506a395247e22a3e98b488" dependencies = [ "bincode", "rand",