You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: documentation/language/02_structure.md
+7-43Lines changed: 7 additions & 43 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,45 +15,11 @@ If you need a declaration from another Leo file, you must import it.
15
15
16
16
### Program
17
17
18
-
A program is a collection of code (its functions) and data (its types) that resides at a
19
-
[program ID](#program-id) on the Aleo blockchain. A program is declared as `program {name}.{network} { ... }`.
20
-
The body of the program is delimited by curly braces `{}`.
18
+
A program is a collection of code (its functions) and data (its types) that resides at a program ID on the Aleo blockchain. A program is declared as `program {name}.{network} { ... }`, with the body delimited by curly braces.
The following must be declared inside the scope of a program in a Leo file:
26
-
27
-
- mappings
28
-
- storage variables
29
-
- record types
30
-
- entry point `fn` declarations
31
-
32
-
The following must be declared outside the scope of a program in a Leo file:
33
-
34
-
- imports
35
-
- struct types
36
-
- helper `fn` definitions
37
-
-`final fn` definitions
38
-
-`interface` definitions
20
+
For the canonical list of which declarations belong inside vs. outside the `program { ... }` block, the program-ID naming rules, and import semantics, see [Project Layout](./01_layout.md#programs).
39
21
40
-
#### Program ID
41
-
42
-
A program ID is declared as `{name}.{network}`.
43
-
44
-
The first character of a `name` must be a lowercase letter.
45
-
`name` can only contain lowercase letters, numbers, and underscores, and must not contain a double underscore (`__`) or the keyword `aleo` in it.
46
-
47
-
Currently, `aleo` is the only supported `network` domain.
@@ -63,10 +29,10 @@ Constants are immutable, and the right-hand side must be an expression evaluatab
63
29
64
30
Constants can be declared in four scopes:
65
31
66
-
-**Global scope** (outside all program blocks in a program file): accessible anywhere in the same file.
32
+
-**Global scope** (outside the `program` block in `main.leo`): accessible anywhere in the same file.
67
33
-**Program scope** (inside a `program` block, outside any function): accessible within that program.
68
34
-**Local scope** (inside a function body): accessible only within that function.
69
-
-**Module scope** (in a module file within the same package, i.e. a `.leo` file with no `program` block): accessible within the same package via `path::to::module::CONST_NAME`. See [Modules](./01_layout.md#modules) for details.
35
+
-**Module scope** (any non-`main.leo` source file in the package; module files do not contain a `program` block and may only declare `const`, `struct`, `fn`, and `interface`): accessible within the same package via `path::to::module::CONST_NAME`. See [Modules](./01_layout.md#modules) for details.
70
36
71
37
Constants are also supported in [libraries](./06_libraries.md), which are separate packages containing reusable code. A library's root file and its submodules may declare constants, accessible from any dependent package as `library::CONST_NAME` or `library::path::to::submodule::CONST_NAME`.
72
38
@@ -94,9 +60,7 @@ See [ProvableHQ/leo#29274](https://github.com/ProvableHQ/leo/issues/29274).
94
60
95
61
### Import
96
62
97
-
You can import dependencies that are downloaded to the `imports` directory.
98
-
An import is declared as `import {filename}.aleo;`
99
-
The dependency resolver will pull the imported program from the network or the local filesystem.
63
+
An import is declared as `import {filename}.aleo;`. See [Imports](./01_layout.md#imports) for resolution rules and the `imports/` directory layout.
A [record](https://developer.aleo.org/concepts/fundamentals/records) data type is declared as `record {name} {}`. A record name must not contain the keyword `aleo`, and must not be a prefix of any other record name.
98
+
A [record](https://developer.aleo.org/concepts/fundamentals/records) data type is declared as `record {name} {}`. A record name must not contain the keyword `aleo`, and must not be a prefix of any other record name**declared in the same program** (the check does not extend across imported programs). The constraint exists because records lower to Aleo identifiers with a `.record` suffix, and prefix collisions would produce ambiguous lowered names.
135
99
136
100
Records contain component declarations `{visibility} {name}: {type},`. Names of record components must not contain the keyword `aleo`.
Copy file name to clipboardExpand all lines: documentation/language/07_style.md
+10-33Lines changed: 10 additions & 33 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -128,10 +128,7 @@ The goal is to only have the interface of the program in `main.leo`. Every funct
128
128
129
129
### Blank lines
130
130
131
-
A single blank line should separate the top-level declarations in a `program` scope,
132
-
namely `fn`, `record`, and `mapping` declarations, as well as module-level `struct` and helper `fn` declarations.
133
-
Multiple imports can be optionally separated by a single blank line;
134
-
the last import at the top of the file should be followed by a blank line.
131
+
A single blank line should separate top-level declarations within a `program` scope (entry `fn`, `record`, and `mapping` declarations) and module-level declarations (`struct`, helper `fn`, `final fn`, `interface`). For the canonical ordering of these categories within a file, see [Layout](#layout) below. Multiple imports may optionally be separated by a single blank line; the last import at the top of the file should be followed by a blank line.
135
132
136
133
```leo title="Yes:"
137
134
import std.io.Write;
@@ -237,37 +234,17 @@ Start by forking off of the `mainnet` branch to make your changes. Commit messag
237
234
If you need to pull in any changes from the `mainnet` branch after making your fork (for example, to resolve potential merge conflicts),
238
235
please avoid using git merge and instead, git rebase your branch. Rebasing will help us review your changes easily.
239
236
240
-
#### Tools Required
237
+
For build, formatting, test, and grammar conventions, see [`CONTRIBUTING.md`](https://github.com/ProvableHQ/leo/blob/mainnet/CONTRIBUTING.md) in the repository root. The canonical commands for validation are:
241
238
242
-
To build Leo from source you will need the following tools:
243
-
244
-
- The latest Rust stable version and nightly version.
245
-
- Recommend that you install multiple versions using `rustup`.
246
-
- Cargo
247
-
- Rusty Hook install via `cargo install rusty-hook`.
248
-
- Clippy
249
-
- Via rustup, if you didn't do the default rustup install `rustup component add clippy`.
250
-
251
-
#### Formatting
252
-
253
-
Please do the following before opening a PR.
254
-
255
-
-`cargo +nightly fmt --all` will format all your code.
If your code adds new functionality, please write tests to confirm the new features function as expected. Refer to existing tests for examples of how tests are expected to be written. Please refer to the [parser tests section](#parser-tests). To run the tests please use the following command `cargo test --all --features ci_skip --no-fail-fast`.
261
-
262
-
##### **Parser Tests**
263
-
264
-
In the root directory of the repository, there is a "tests" directory.
265
-
To add a parser test, look at the Example Leo files in the parser sub-directory.
266
-
Then when running the test command, make sure you have the environment variable `CLEAR_LEO_TEST_EXPECTATIONS` set to true. For example, on a UNIX environment, you could run the following command `CLEAR_LEO_TEST_EXPECTATIONS=true cargo test --all --features ci_skip --no-fail-fast`.
239
+
```bash
240
+
cargo check
241
+
cargo clippy -- -D warnings
242
+
cargo +nightly fmt --check
243
+
cargo test
244
+
```
267
245
268
-
#### Grammar
246
+
To update parser expectation files after intentional grammar changes, run `UPDATE_EXPECT=1 cargo test -p leo-parser`.
269
247
270
-
[The `grammars` repository](https://github.com/ProvableHQ/grammars) contains a file [`leo.abnf`](https://github.com/ProvableHQ/grammars/blob/master/leo.abnf) that has the Leo grammar rules in the ABNF format.
271
-
If your changes affect a grammar rule, we may ask you to modify it in that `.abnf` file.
248
+
The Leo grammar is maintained in the [`grammars` repository](https://github.com/ProvableHQ/grammars) (`leo.abnf`).
Copy file name to clipboardExpand all lines: documentation/language/operators/standard_operators.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -983,7 +983,7 @@ height in a program.
983
983
984
984
:::info
985
985
986
-
- The `block.height` operator can only be used inside a `final { }` block or inside a `final fn`. Using it outside will result in a compilation error.
986
+
- The `block.height` operator can only be used inside a `final { }` block or a `final fn`. It is rejected in entry `fn` bodies, helper `fn`s, and constant initialisers, since chain state is only observable in the finalization context.
987
987
- The `block.height` operator doesn't take any parameters.
988
988
989
989
:::
@@ -1001,7 +1001,7 @@ The `block.timestamp` operator is used to fetch the UNIX timestamp of the latest
1001
1001
1002
1002
:::info
1003
1003
1004
-
- The `block.timestamp` operator can only be used inside a `final { }` block or inside a `final fn`. Using it outside will result in a compilation error.
1004
+
- The `block.timestamp` operator can only be used inside a `final { }` block or a `final fn`. It is rejected in entry `fn` bodies, helper `fn`s, and constant initialisers, since chain state is only observable in the finalization context.
1005
1005
- The `block.timestamp` operator doesn't take any parameters.
Copy file name to clipboardExpand all lines: documentation/language/programs_in_practice/limitations.md
+12-13Lines changed: 12 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,25 +8,24 @@ toc_max_heading_level: 3
8
8
9
9
snarkVM imposes the following limits on Aleo programs:
10
10
11
-
- the maximum size of the program is 100 KB, by the number of characters.
12
-
- the maximum number of mappings is 31.
13
-
- the maximum number of imports is 64.
14
-
- the maximum length of a program name is 30 characters (excluding the `.aleo` suffix).
15
-
- the maximum import depth is 64.
16
-
- the maximum call depth is 31.
17
-
- the maximum number of functions is 31.
18
-
- the maximum number of structs is 310.
19
-
- the maximum number of records is 310.
20
-
- the maximum number of closures is 62.
11
+
- the maximum size of the compiled program is **512 KB** by character count (was 100 KB before consensus version V14).
12
+
- the maximum number of mappings is **31**. Each `storage` singleton consumes one mapping slot, and each `storage` vector consumes two (one for values, one for length), so storage declarations share this budget with explicit `mapping` declarations.
13
+
- the maximum number of imports is **64**.
14
+
- the maximum length of a program name is **30 characters** (excluding the `.aleo` suffix). Identifiers (including struct, record, mapping, and function names) are limited to **31 ASCII alphanumeric or underscore characters** by the Aleo identifier rules.
15
+
- the maximum number of functions is **31** (entry `fn`s plus the synthesised on-chain functions produced by `final { }` blocks and `constructor`).
16
+
- the maximum number of structs is **310** (`10 × MAX_FUNCTIONS`).
17
+
- the maximum number of records is **310**.
18
+
- the maximum number of closures is **62** (`2 × MAX_FUNCTIONS`).
19
+
- the maximum number of inputs and outputs **per entry point** is **16** each.
21
20
22
21
**If your _compiled_ Leo program exceeds these limits, then consider modularizing or rearchitecting your program.** The only way these limits can be increased is through a formal protocol upgrade via the governance process defined by the Aleo Network Foundation.
23
22
24
23
Some other protocol-level limits to be aware of are:
25
24
26
-
-**the maximum transaction size is 128 KB.** If your program exceeds this, perhaps by requiring large inputs or producing large outputs, consider optimizing the data types in your Leo code.
27
-
-**the maximum number of micro-credits your transaction can consume for on-chain execution is `100_000_000`.**. If your program exceeds this, consider optimizing on-chain components of your Leo code.
25
+
-**the maximum transaction size is 768 KB**(was 128 KB before consensus version V14). If your program exceeds this — for example by requiring large inputs or producing large outputs — consider optimizing the data types in your Leo code.
26
+
-**the maximum number of micro-credits your transaction can consume for on-chain execution is `100_000_000`.** If your program exceeds this, consider optimizing on-chain components of your Leo code.
28
27
29
-
As with the above restrictions, these limits can only be increased via the governance process.
28
+
As with the above restrictions, these limits can only be increased via the governance process. Authoritative values live in `snarkvm-console-network` (`MAX_PROGRAM_SIZE`, `MAX_MAPPINGS`, `MAX_FUNCTIONS`, etc.).
0 commit comments