Skip to content

Commit

Permalink
Merge pull request #375 from AleoHQ/update/5-28-24
Browse files Browse the repository at this point in the history
[Update] Core Devs Call 5-28-24 and documentation updates.
  • Loading branch information
d0cd authored May 28, 2024
2 parents baf1b64 + 0593f4b commit 42cb098
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 88 deletions.
2 changes: 1 addition & 1 deletion documentation/00_leo_overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ title: The Leo Programming Language
sidebar_label: Overview
---

Welcome to the Leo programming language. Leo is a functional, statically-typed programming language built
Welcome to the Leo programming language. Leo is a statically-typed programming language built
for writing private applications. Leo is a high-level programming language that compiles down to low-level Aleo Instructions.

:::info
Expand Down
23 changes: 11 additions & 12 deletions documentation/00_overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,7 @@ An index of all pages available in this documentation.
- [TicTacToe](https://github.com/AleoHQ/workshop/tree/master/tictactoe)
- [Battleship](https://github.com/AleoHQ/workshop/tree/master/battleship)

### Chapter 3: Concepts

- [Accounts](./concepts/00_accounts.md)
- [Programs](./concepts/01_programs.md)
- [Records](./concepts/02_records.md)
- [Transactions](./concepts/03_transactions.md)
- [Transaction Fees](./concepts/03A_transaction_fees.md)
- [Transitions](./concepts/04_transitions.md)
- [Blocks](./concepts/05_blocks.md)


### Chapter 4: Aleo Instructions
### Chapter 3: Aleo Instructions

- [Overview](./00_aleo_overview.md)
- [Installation](./aleo/01_installation.md)
Expand All @@ -56,6 +45,16 @@ An index of all pages available in this documentation.
- [Aleo Instructions Grammar](./aleo/06_grammar.md)
- [Aleo Instructions Code Editor Plugins](./aleo/07_tooling.md)

### Chapter 4: Concepts

- [Accounts](./concepts/00_accounts.md)
- [Programs](./concepts/01_programs.md)
- [Records](./concepts/02_records.md)
- [Transactions](./concepts/03_transactions.md)
- [Transaction Fees](./concepts/03A_transaction_fees.md)
- [Transitions](./concepts/04_transitions.md)
- [Blocks](./concepts/05_blocks.md)

## Testnet III

### Chapter 5: Getting Started
Expand Down
4 changes: 2 additions & 2 deletions documentation/aleo/02_hello.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ You will see output like this:

⛓ Constraints

'foo.aleo/hello' - 35 constraints (called 1 time)
'foo.aleo/hello' - 33 constraints (called 1 time)

➡️ Output

Expand All @@ -69,7 +69,7 @@ When the execution is finished, you should see the following output:

⛓ Constraints

'foo.aleo/hello' - 35 constraints (called 1 time)
'foo.aleo/hello' - 33 constraints (called 1 time)

➡️ Output

Expand Down
2 changes: 1 addition & 1 deletion documentation/aleo/03_language.md
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ function new_token:

A mapping is declared as `mapping {name}:`.
Mappings contain key-value pairs.
Mappings must be defined within a program scope.
Mappings must be defined within a program.
Mappings are stored publicly on-chain. It is not possible to store data privately in a mapping.

```aleo showLineNumbers
Expand Down
2 changes: 1 addition & 1 deletion documentation/leo/01_installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ cargo --version

You can build and install Leo from the source code as follows:

```bash
```
# Download the source code
git clone https://github.com/AleoHQ/leo
cd leo
Expand Down
66 changes: 15 additions & 51 deletions documentation/leo/02_hello.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,30 @@ This creates a directory with the following structure:

```bash
hello/
├── .env # Your program environment
├── program.json # Your program manifest
├── README.md # Your program description
├── build/
├── inputs/
│ ├── hello.in # Your program inputs
├── .gitignore # A default `.gitignore` file for Leo projects
├── .env # The environment, containing the `NETWORK` and `PRIVATE_KEY` variables.
├── program.json # The manifest for the Leo project
├── README.md # The project description and documentation
├── build/ # The build directory, containing compiled code
└── src/
└── main.leo # Your program file
└── main.leo # The Leo source code
```

Let's run the project.

## Zero Knowledge in one line
## Zero Knowledge in One Line

The `leo run` command will compile and run the program.
In your terminal, run:
```bash
leo run main
leo run main 1u32 2u32
```

```bash title="console output:"
Leo Compiled 'main.leo' into Aleo instructions

⛓ Constraints
'hello.aleo/main' - 35 constraints (called 1 time)
'hello.aleo/main' - 33 constraints (called 1 time)

➡️ Output
• 3u32
Expand Down Expand Up @@ -73,7 +72,7 @@ All files in the current package will be compiled with the specified Leo `versio
"version": "0.0.0",
```

## Syntax to circuits
## Syntax to Circuits
Open up **src/main.leo**.
The **main.leo** file is the entry point of a Leo project. It often contains a function named `main`.
Let's break down the structure of a Leo file.
Expand All @@ -90,7 +89,7 @@ program hello.aleo {
`program hello.aleo {` defines the name of the [program](03_language.md#program-scope) inside the Leo file.
The program ID must match the `program.json` manifest file.
The keyword `transition` indicates a [transition](03_language.md#transition-function) function definition in Leo.
Our **hello** `main` function takes an input `a` with type `u32` and `public` visibility, and an input `b` with type `u32` and `private` visibility (by default).
The `main` transition takes an input `a` with type `u32` and `public` visibility, and an input `b` with type `u32` and `private` visibility (by default).
The program returns one result with type `u32`.
The transition function body is enclosed in curly braces `{ }`. It is a common convention in Leo to place the opening curly
brace on the same line as the function definition, adding one space in between.
Expand All @@ -105,7 +104,7 @@ let c: u32 = a + b;
```

:::info
We designed Leo with the belief that developers are human and can make mistakes.
Leo is designed to detect many errors at compile time, via statically checked strong types.
Try changing the type of any variable and seeing what Leo recommends with helpful error messages.
:::

Expand All @@ -115,43 +114,8 @@ Leo will check that `c`'s type matches the function return type `u32`.
return c;
```

## Wiring program inputs
Leo's compiler will build a **circuit** out of the **main.leo** program. Open up **inputs/hello.in**.
Files ending in **.in** provide inputs to the program. You can also specify program arguments via the [command line](05_commands.md#leo-run).
```leo title="inputs/hello.in"
// The program input for hello/src/main.leo
[main]
public a: u32 = 1u32;
b: u32 = 2u32;
```

An input file begins with a section enclosed in square brackets `[ ]`.
The `main` inside the square brackets indicates that we are defining the inputs to the transition function `main`.
You can only define inputs to [transition functions](03_language.md#transition-function).

```leo
[main]
```

An input assignment shares syntax with an explicit variable assignment in normal `.leo` files.
Here we assign the value `1` of type `u32` to the `public` input named `a`.
We also assign the value `2` of type `u32` to the (private, by default) input named `b`.
Leo's compiler will fetch these values and provide them as inputs to the circuit at proving time.

```leo
public a: u32 = 1u32;
b: u32 = 2u32;
```

Now let us use the Leo CLI and see what other commands we can run on our program.


Previously we ran the program with `leo run`.
This command builds and runs the program natively.
```bash
leo run
```

## Step by step

### 1. Clean
Expand All @@ -171,21 +135,21 @@ leo update
```

```bash title="console output:"
Leo ✅ Updated to version 1.9.0
Leo ✅ Updated to version 1.12.0
```

### 2. Execute

The `leo execute` command executes the Leo program and outputs a transaction object
```bash
leo execute main
leo execute main 1u32 2u32
```

```bash title="console output:"
Leo ✅ Compiled 'main.leo' into Aleo instructions

⛓ Constraints
'hello.aleo/main' - 35 constraints (called 1 time)
'hello.aleo/main' - 33 constraints (called 1 time)

➡️ Output
• 3u32
Expand Down
28 changes: 14 additions & 14 deletions documentation/leo/03_language.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Leo will not default to an integer type. The definition of an integer **must** i
```leo
let a: u8 = 2u8; // explicit type
let b: u16 = a as u16; // type casting
let b: u8 = 2; // implicit type -- not supported
let c: u8 = 2; // implicit type -- not supported
```

### Field Elements
Expand Down Expand Up @@ -94,8 +94,7 @@ let g: group = group::GEN; // the group generator
### Scalar Elements

Leo supports the `scalar` type for elements of the scalar field defined by the elliptic curve subgroup.
These are unsigned integers less than the modulus of the scalar field. Showing the smallest and largest
scalars.
These are unsigned integers less than the modulus of the scalar field. The following are the smallest and largest scalars.

```leo
let a: scalar = 0scalar;
Expand All @@ -113,9 +112,9 @@ let receiver: address = aleo1ezamst4pjgj9zfxqq0fwfj8a4cjuqndmasgata3hggzqygggnyf

### Signatures

Aleo uses a Schnorr signatures scheme to sign messages with an Aleo private key.
Signatures in Leo have their own type `signature` and can be declared as literals `sign069ju4e8s66unu25celqycvsv3k9chdyz4n4sy62tx6wxj0u25vqp58hgu9hwyqc63qzxvjwesf2wz0krcvvw9kd9x0rsk4lwqn2acqhp9v0pdkhx6gvkanuuwratqmxa3du7l43c05253hhed9eg6ppzzfnjt06fpzp6msekdjxd36smjltndmxjndvv9x2uecsgngcwsc2qkns4afd`.
Signatures can be verified in Leo using the [`signature::verify` or `s.verify`](./04_operators.md#signatureverify) operators.
Aleo uses the Schnorr signature scheme to sign messages with an Aleo private key.
Signatures are a native type in Leo, and can be declared with the keyword `signature`.
Signatures can be verified in Leo using the [`signature::verify`](./04_operators.md#signatureverify) or [`s.verify`](./04_operators.md#signatureverify) operators.

```leo
program test.aleo {
Expand All @@ -141,16 +140,17 @@ program test.aleo {

## Layout of a Leo Program

A Leo program contains declarations of a [Program Scope](#program-scope), [Constants](#constant), [Imports](#import)
A Leo program contains declarations of a [Program](#program), [Constants](#constant), [Imports](#import)
, [Transition Functions](#transition-function), [Async Functions](#async-function), [Helper Functions](#helper-function), [Structs](#struct)
, [Records](#record), and [Mappings](#mapping).
Declarations are locally accessible within a program file.
If you need a declaration from another Leo file, you must import it.

### Program Scope
### Program

A program scope in the sense of Leo is a collection of code (its functions) and data (its types) that resides at a
[program ID](#program-id) on the Aleo blockchain.
A program is a collection of code (its functions) and data (its types) that resides at a
[program ID](#program-id) on the Aleo blockchain. A program is declared as `program {name}.{network} { ... }`.
The body of the program is delimited by curly braces `{}`.

```leo
import foo.aleo;
Expand Down Expand Up @@ -192,7 +192,7 @@ program hello.aleo {
}
```

The following must be declared inside the program scope in a Leo file:
The following must be declared inside the scope of a program in a Leo file:

- constants
- mappings
Expand All @@ -202,14 +202,14 @@ The following must be declared inside the program scope in a Leo file:
- helper functions
- async functions

The following must be declared outside the program scope in a Leo file:
The following must be declared outside the scope of a program in a Leo file:

- imports

#### Program ID

A program ID is declared as `{name}.{network}`.
The first character of a `name` must be lowercase.
The first character of a `name` must be a lowercase letter.
`name` can contain lowercase letters, numbers, and underscores.
Currently, `aleo` is the only supported `network` domain.

Expand All @@ -227,7 +227,7 @@ program _foo.aleo; // invalid

A constant is declared as `const {name}: {type} = {expression};`.
Constants are immutable and must be assigned a value when declared.
Constants can be declared in the global program scope or in a local function scope.
Constants can be declared in the global scope or in a local function scope.

```leo
program foo.aleo {
Expand Down
6 changes: 3 additions & 3 deletions documentation/leo/05_commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ This command does not synthesize the program circuit or generate proving and ver
Leo ✅ Compiled 'main.leo' into Aleo instructions

⛓ Constraints
'hello.aleo/main' - 35 constraints (called 1 time)
'hello.aleo/main' - 33 constraints (called 1 time)

➡️ Output
• 3u32
Expand All @@ -154,7 +154,7 @@ This command synthesizes the program circuit and generates proving and verifying
Leo ✅ Compiled 'main.leo' into Aleo instructions

⛓ Constraints
'hello.aleo/main' - 35 constraints (called 1 time)
'hello.aleo/main' - 33 constraints (called 1 time)

➡️ Output
• 3u32
Expand Down Expand Up @@ -270,4 +270,4 @@ Options:
-q Suppress CLI output
--path <PATH> Optional path to Leo program root folder
-h, --help Print help
```
```
1 change: 1 addition & 0 deletions documentation/leo/16_core_devs_call.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@ We welcome everyone to join!

## Past Meetings
The slides from each call will be available for review shortly after the meeting.
- [May 28, 2024](https://docs.google.com/presentation/d/1h3NaDqu6Lzu5an9qXie7xHcrcPWOZma3ytWS8tlFFrk/edit?usp=sharing)
- [May 21, 2024](https://docs.google.com/presentation/d/1M1zNuA0Xc2Qzi3PjdnmUnaFUYDjizskFcQHPT0NY8J8/edit?usp=sharing)

2 changes: 1 addition & 1 deletion documentation/leo/17_testnet_beta.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ If you haven't updated Leo in a while, you're probably used to using `.leo` in y
**The updated rules are:**
- all files containing Leo programs must end with a `.leo` file extension.
- all imports must be defined with the `.aleo` prefix.
- all program scopes must be declared with the `.aleo` prefix.
- all programs must be declared with the `.aleo` prefix.
- all external calls must be made with the `.aleo` prefix.

For example, if you originally had following file:
Expand Down
4 changes: 2 additions & 2 deletions documentation/sdk/create-aleo-app/01_create_aleo_app.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ leo help ## you know what this does
You can try it yourself and observe the outputs in the terminal.

```bash
leo run main
leo execute main
leo run main 1u32 2u32
leo execute main 1u32 2u32
```

Let's get back to deploying!
Expand Down

0 comments on commit 42cb098

Please sign in to comment.