From 69336dd8f2c55a87be630ea26a4d9f87c9baff7e Mon Sep 17 00:00:00 2001 From: franfiuba Date: Thu, 4 Aug 2022 04:43:54 +0200 Subject: [PATCH 01/10] created a root readme in the examples folder --- examples/README.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 examples/README.md diff --git a/examples/README.md b/examples/README.md new file mode 100644 index 0000000000..39e4806b68 --- /dev/null +++ b/examples/README.md @@ -0,0 +1,25 @@ +# Leo Examples + +This directory includes the following Leo code examples: + +1. Hello World -> Basic Sum of two u32 +2. Groups -> Basic operations over groups +3. Core -> Core circuits functions over a field type +4. Bubblesort -> Sorting algorithms over a tuple +5. Import point -> Import code from an other file +6. Message -> Initialization of a circuit type +7. Token -> Record example + +## Build Guide + +To compile each example, run: +```bash +leo build +``` +When you run this command for the first time the snarkvm parameters (universal setup) will be downloaded, these are necessary to run the circuits. + +To run each program, run: +```bash +leo run main +``` +This command will look in the input file inputs/*.in where should find a section [main] and use the variables as inputs to the program. \ No newline at end of file From 8d2b0c00fc293383f1e73ef5151b4639af97ef39 Mon Sep 17 00:00:00 2001 From: franfiuba Date: Thu, 4 Aug 2022 04:44:46 +0200 Subject: [PATCH 02/10] update group example readme --- examples/groups/README.md | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/examples/groups/README.md b/examples/groups/README.md index a1a8a58c67..251772baf0 100644 --- a/examples/groups/README.md +++ b/examples/groups/README.md @@ -9,5 +9,27 @@ leo build To run this program, run: ```bash -leo run -``` \ No newline at end of file +leo run main +``` + +## Overview + +This example shows how to do basic operations over groups. + +It takes the input data from inputs/groups.in + + +## Documentation Group Element + +The set of affine points on the elliptic curve passed into the Leo compiler forms a group. Leo supports this set as a primitive data type. Group elements are special since their values can be defined as coordinate pairs ```(x, y)group```. The group type keyword group must be used when specifying a pair of group coordinates since implicit syntax would collide with normal tuple (a, b) values. + +``` +let b = 0group; // the zero of the group + +let a = 1group; // the group generator + +let c = 2group; // 2 * the group generator + +let d = (0, 1)group; // coordinate notation +``` + From f2367962d65f53217d3755bc9d30a74e04852fde Mon Sep 17 00:00:00 2001 From: franfiuba Date: Thu, 4 Aug 2022 04:45:47 +0200 Subject: [PATCH 03/10] update helloworld readme example --- examples/helloworld/README.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/examples/helloworld/README.md b/examples/helloworld/README.md index e04a14969b..0a9324edb5 100644 --- a/examples/helloworld/README.md +++ b/examples/helloworld/README.md @@ -9,5 +9,10 @@ leo build To run this program, run: ```bash -leo run -``` \ No newline at end of file +leo run main +``` +## Overview + +This example shows how to sum two u32 numbers. + +It takes the input data from inputs/helloworld.in \ No newline at end of file From f39e616c6343b933cbe983dc6f9bc4aadcb2db66 Mon Sep 17 00:00:00 2001 From: franfiuba Date: Thu, 4 Aug 2022 04:46:44 +0200 Subject: [PATCH 04/10] first update of the bubble sort readme --- examples/bubblesort/README.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/examples/bubblesort/README.md b/examples/bubblesort/README.md index 34d507afc8..15bc6bfbd1 100644 --- a/examples/bubblesort/README.md +++ b/examples/bubblesort/README.md @@ -9,5 +9,11 @@ leo build To run this program, run: ```bash -leo run -``` \ No newline at end of file +leo run main +``` + +## Overview + +This example shows how to sort an array. + +It takes the input data from inputs/bubblesort.in From 8f3b813c70559302975686bacc848f7298b792bc Mon Sep 17 00:00:00 2001 From: Pranav Gaddamadugu Date: Thu, 4 Aug 2022 12:08:59 -0700 Subject: [PATCH 05/10] Add offline option to Leo CLI --- leo/commands/build.rs | 10 +++++++--- leo/commands/run.rs | 1 + 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/leo/commands/build.rs b/leo/commands/build.rs index 514f1cfed2..a091da9b4a 100644 --- a/leo/commands/build.rs +++ b/leo/commands/build.rs @@ -42,6 +42,8 @@ use tracing::span::Span; /// require Build command output as their input. #[derive(StructOpt, Clone, Debug, Default)] pub struct BuildOptions { + #[structopt(long, help = "Enables offline mode.")] + pub offline: bool, #[structopt(long, help = "Enable spans in AST snapshots.")] pub enable_spans: bool, #[structopt(long, help = "Writes all AST snapshots for the different compiler phases.")] @@ -115,7 +117,7 @@ impl Command for Build { let build_directory = BuildDirectory::open(&package_path)?; // Initialize error handler - let handler = leo_errors::emitter::Handler::default(); + let handler = Handler::default(); // Fetch paths to all .leo files in the source directory. let source_files = SourceDirectory::files(&package_path)?; @@ -178,8 +180,10 @@ impl Command for Build { std::env::set_current_dir(&build_directory) .map_err(|err| PackageError::failed_to_set_cwd(build_directory.display(), err))?; - // Call the `aleo build` command from the Aleo SDK. - let command = AleoBuild::try_parse_from(&[ALEO_CLI_COMMAND]).map_err(CliError::failed_to_execute_aleo_build)?; + // Call the `aleo build` command with the appropriate from the Aleo SDK. + let mut args = vec![ALEO_CLI_COMMAND]; + if self.compiler_options.offline { args.push("--offline"); } + let command = AleoBuild::try_parse_from(&args).map_err(CliError::failed_to_execute_aleo_build)?; let result = command.parse().map_err(CliError::failed_to_execute_aleo_build)?; // Log the result of the build diff --git a/leo/commands/run.rs b/leo/commands/run.rs index ddfe6954e2..6ca875a835 100644 --- a/leo/commands/run.rs +++ b/leo/commands/run.rs @@ -76,6 +76,7 @@ impl Command for Run { .map_err(|err| PackageError::failed_to_set_cwd(build_directory.display(), err))?; // Call the `aleo run` command from the Aleo SDK. + if self.compiler_options.offline { arguments.push(String::from("--offline")); } let command = AleoRun::try_parse_from(&arguments).map_err(CliError::failed_to_parse_aleo_run)?; let res = command.parse().map_err(CliError::failed_to_execute_aleo_run)?; From aeff08c96b8251ff8d4bbd1f4d840a4e34b4cc51 Mon Sep 17 00:00:00 2001 From: collin <16715212+collinc97@users.noreply.github.com> Date: Thu, 4 Aug 2022 12:30:34 -0700 Subject: [PATCH 06/10] cargo fmt --- leo/commands/build.rs | 4 +++- leo/commands/run.rs | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/leo/commands/build.rs b/leo/commands/build.rs index a091da9b4a..714a794087 100644 --- a/leo/commands/build.rs +++ b/leo/commands/build.rs @@ -182,7 +182,9 @@ impl Command for Build { // Call the `aleo build` command with the appropriate from the Aleo SDK. let mut args = vec![ALEO_CLI_COMMAND]; - if self.compiler_options.offline { args.push("--offline"); } + if self.compiler_options.offline { + args.push("--offline"); + } let command = AleoBuild::try_parse_from(&args).map_err(CliError::failed_to_execute_aleo_build)?; let result = command.parse().map_err(CliError::failed_to_execute_aleo_build)?; diff --git a/leo/commands/run.rs b/leo/commands/run.rs index 6ca875a835..77232bb0fa 100644 --- a/leo/commands/run.rs +++ b/leo/commands/run.rs @@ -76,7 +76,9 @@ impl Command for Run { .map_err(|err| PackageError::failed_to_set_cwd(build_directory.display(), err))?; // Call the `aleo run` command from the Aleo SDK. - if self.compiler_options.offline { arguments.push(String::from("--offline")); } + if self.compiler_options.offline { + arguments.push(String::from("--offline")); + } let command = AleoRun::try_parse_from(&arguments).map_err(CliError::failed_to_parse_aleo_run)?; let res = command.parse().map_err(CliError::failed_to_execute_aleo_run)?; From 79bef6627ae53c4f09705c2282f8cb08e406d49e Mon Sep 17 00:00:00 2001 From: Alessandro Coglio Date: Thu, 4 Aug 2022 21:01:05 -0700 Subject: [PATCH 07/10] [ABNF] Add compound assignments. --- docs/grammar/abnf-grammar.txt | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/docs/grammar/abnf-grammar.txt b/docs/grammar/abnf-grammar.txt index 4fbdbbcb66..acffb7edcf 100644 --- a/docs/grammar/abnf-grammar.txt +++ b/docs/grammar/abnf-grammar.txt @@ -184,13 +184,18 @@ atomic-literal = numeric-literal / address-literal / string-literal -symbol = "!" / "&&" / "||" +symbol = "!" + / "&&" / "||" / "==" / "!=" / "<" / "<=" / ">" / ">=" / "&" / "|" / "^" / "<<" / ">>" / "+" / "-" / "*" / "/" / "%" / "**" / "=" + / "+=" / "-=" / "*=" / "/=" / "%=" / "**=" + / "<<=" / ">>=" + / "&=" / "|=" / "^=" + / "&&=" / "||=" / "(" / ")" / "[" / "]" / "{" / "}" @@ -375,6 +380,19 @@ loop-statement = %s"for" identifier ":" type block assignment-operator = "=" + / "+=" + / "-=" + / "*=" + / "/=" + / "%=" + / "**=" + / "<<=" + / ">>=" + / "&=" + / "|=" + / "^=" + / "&&=" + / "||=" assignment-statement = expression assignment-operator expression ";" From 19f51875b9f737ef449bd2c7d1e93dfc74c53374 Mon Sep 17 00:00:00 2001 From: collin <16715212+collinc97@users.noreply.github.com> Date: Fri, 5 Aug 2022 11:06:17 -0700 Subject: [PATCH 08/10] update config.yml --- .circleci/config.yml | 173 ++++++++----------------------------------- 1 file changed, 30 insertions(+), 143 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 4f3c59a64c..426ef14306 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -136,124 +136,32 @@ jobs: paths: project/ - clear_environment: cache_key: leo-executable-cache -# -# leo-new: -# docker: -# - image: cimg/rust:1.62 -# resource_class: xlarge -# steps: -# - attach_workspace: -# at: /home/circleci/project/ -# - run: -# name: leo new -# command: | -# export LEO=/home/circleci/project/project/bin/leo -# ./project/.circleci/leo-new.sh -# -# leo-init: -# docker: -# - image: cimg/rust:1.62 -# resource_class: xlarge -# steps: -# - attach_workspace: -# at: /home/circleci/project/ -# - run: -# name: leo init -# command: | -# export LEO=/home/circleci/project/project/bin/leo -# ./project/.circleci/leo-init.sh -# -# leo-clean: -# docker: -# - image: cimg/rust:1.62 -# resource_class: xlarge -# steps: -# - attach_workspace: -# at: /home/circleci/project/ -# - run: -# name: leo clean -# command: | -# export LEO=/home/circleci/project/project/bin/leo -# ./project/.circleci/leo-clean.sh -# -# leo-setup: -# docker: -# - image: cimg/rust:1.62 -# resource_class: xlarge -# steps: -# - attach_workspace: -# at: /home/circleci/project/ -# - run: -# name: leo setup -# command: | -# export LEO=/home/circleci/project/project/bin/leo -# ./project/.circleci/leo-setup.sh - # leo-add-remove: - # docker: - # - image: cimg/rust:1.62 - # resource_class: xlarge - # steps: - # - attach_workspace: - # at: /home/circleci/project/ - # - run: - # name: leo add & remove - # command: | - # export LEO=/home/circleci/project/project/bin/leo - # ./project/.circleci/leo-add-remove.sh + leo-new: + docker: + - image: cimg/rust:1.62 + resource_class: xlarge + steps: + - attach_workspace: + at: /home/circleci/project/ + - run: + name: leo new + command: | + export LEO=/home/circleci/project/project/bin/leo + ./project/.circleci/leo-new.sh -# todo (collin): uncomment after compiler refactor -# leo-check-constraints: -# docker: -# - image: cimg/rust:1.62 -# resource_class: xlarge -# steps: -# - attach_workspace: -# at: /home/circleci/project/ -# - run: -# name: leo check constraints for Pedersen Hash -# command: | -# export LEO=/home/circleci/project/project/bin/leo -# ./project/.circleci/leo-check-constraints.sh -# -# leo-login-logout: -# docker: -# - image: cimg/rust:1.62 -# resource_class: xlarge -# steps: -# - attach_workspace: -# at: /home/circleci/project/ -# - run: -# name: leo login & logout -# command: | -# export LEO=/home/circleci/project/project/bin/leo -# ./project/.circleci/leo-login-logout.sh -# -# leo-clone: -# docker: -# - image: cimg/rust:1.62 -# resource_class: xlarge -# steps: -# - attach_workspace: -# at: /home/circleci/project/ -# - run: -# name: leo clone -# command: | -# export LEO=/home/circleci/project/project/bin/leo -# ./project/.circleci/leo-clone.sh -# -# leo-publish: -# docker: -# - image: cimg/rust:1.62 -# resource_class: xlarge -# steps: -# - attach_workspace: -# at: /home/circleci/project/ -# - run: -# name: leo publish -# command: | -# export LEO=/home/circleci/project/project/bin/leo -# ./project/.circleci/leo-publish.sh + leo-clean: + docker: + - image: cimg/rust:1.62 + resource_class: xlarge + steps: + - attach_workspace: + at: /home/circleci/project/ + - run: + name: leo clean + command: | + export LEO=/home/circleci/project/project/bin/leo + ./project/.circleci/leo-clean.sh workflows: version: 2 @@ -262,30 +170,9 @@ workflows: - check-style - clippy - leo-executable -# - leo-new: -# requires: -# - leo-executable -# - leo-init: -# requires: -# - leo-executable -# - leo-clean: -# requires: -# - leo-executable -# - leo-setup: -# requires: -# - leo-executable -# - leo-add-remove: -# requires: -# - leo-executable -# - leo-check-constraints: -# requires: -# - leo-executable -# - leo-login-logout: -# requires: -# - leo-executable -# - leo-clone: -# requires: -# - leo-executable -# - leo-publish: -# requires: -# - leo-executable + - leo-new: + requires: + - leo-executable + - leo-clean: + requires: + - leo-executable From 8f9c7efbed4b5a80ec5989bd400a284391169e0f Mon Sep 17 00:00:00 2001 From: collin <16715212+collinc97@users.noreply.github.com> Date: Fri, 5 Aug 2022 11:14:58 -0700 Subject: [PATCH 09/10] fix program names --- .circleci/leo-clean.sh | 6 +++--- .circleci/leo-new.sh | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.circleci/leo-clean.sh b/.circleci/leo-clean.sh index 8448ae24c2..e40ab9ed04 100755 --- a/.circleci/leo-clean.sh +++ b/.circleci/leo-clean.sh @@ -1,8 +1,8 @@ -# leo new hello-world +# Create a new Leo program named `foo` and run `leo build`. -$LEO new hello-world +$LEO new foo ls -la -cd hello-world && ls -la +cd foo && ls -la $LEO build # Assert that the 'outputs' folder is not empty diff --git a/.circleci/leo-new.sh b/.circleci/leo-new.sh index 46d4e3790b..02a0c32f1a 100755 --- a/.circleci/leo-new.sh +++ b/.circleci/leo-new.sh @@ -1,7 +1,7 @@ -# Create a new foo project. +# Create a new Leo program named `foo`. $LEO new foo ls -la cd foo && ls -la -# Try to compile and run the template project. +# Try to run `leo build`. $LEO run From 7ffbee2952adfc7cb1c3ec11a46b96fcbcc99018 Mon Sep 17 00:00:00 2001 From: collin <16715212+collinc97@users.noreply.github.com> Date: Fri, 5 Aug 2022 11:30:53 -0700 Subject: [PATCH 10/10] patch leo-clean ci --- .circleci/leo-clean.sh | 33 +++++++++------------------------ 1 file changed, 9 insertions(+), 24 deletions(-) diff --git a/.circleci/leo-clean.sh b/.circleci/leo-clean.sh index e40ab9ed04..d2ede6a74d 100755 --- a/.circleci/leo-clean.sh +++ b/.circleci/leo-clean.sh @@ -1,38 +1,23 @@ -# Create a new Leo program named `foo` and run `leo build`. - +# Create a new Leo program named `foo`. $LEO new foo ls -la cd foo && ls -la + +# Run `leo build`. $LEO build -# Assert that the 'outputs' folder is not empty - -cd outputs || exit 1 -if [ "$(ls -A $DIR)" ]; then - echo "$DIR is not empty" +# Assert that the 'build' folder exists. +if [ "$(ls -A build)" ]; then + echo "build is not empty" else - echo "$DIR is empty" + echo "build is empty" exit 1 fi -cd .. - -# leo clean +# Run `leo clean` $LEO clean -cd outputs && ls -la -cd .. - -# Assert that the 'outputs' folder is empty - -if [ "$(ls -A outputs)" ]; then - echo "outputs is not empty" - exit 1 -else - echo "outputs is empty" -fi - -# Assert that the 'build' folder is empty +# Assert that the 'build' folder is empty. if [ "$(ls -A build)" ]; then echo "build is not empty" exit 1