-
Notifications
You must be signed in to change notification settings - Fork 266
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: some initial noir contract docs (#1449)
Apologies for the large and sweeping PR. It's the culmination of going back-and-forth between doc writing and tweaking noir contracts as I go. - Improved the preprocessor which embeds code into markdown files. - Split the old 'concepts' doc into the new filing structure, and added some content and code snippets. - Renamed instances of "zk token" to "private token" throughout the codebase (all cases: camel, pascal etc). - Moved `zk_token_contract` to a `private_token_airdrop_contract`, because it showcased some extra 'claim' functionality that might confuse someone expecting basic functions. - Created `private_token_contract` as a simpler version of `zk_token_contract` (by removing anything about claim notes). - Introduced an example contract demonstrating the basics of public state.
- Loading branch information
1 parent
912c1b4
commit a3514c3
Showing
68 changed files
with
1,098 additions
and
417 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
[package] | ||
name = "" | ||
authors = [""] | ||
compiler_version = "0.6.0" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
Discuss: | ||
- Public Inputs ABIs for functions. | ||
- Args & args hashes | ||
- return values and return values hashes | ||
- etc. | ||
|
||
|
||
## Limitations | ||
|
||
### Num reads and writes | ||
|
||
### Num function calls | ||
|
||
### Num logs | ||
|
||
### Num key pair validations | ||
|
||
### No gas or fees yet |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Not sure what this one's for? | ||
`assert`? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# `contract` | ||
|
||
A contract is a collection of persistent [state variables](#state-variables), and [functions](#functions) which may modify these persistent states. Functions and states within a contract's scope are said to belong to that contract. A contract can only access and modify its own state. If a contract wishes to access or modify another contract's state, it must make a [call](#calling-functions) to an external function of that other contract. For anything to happen on the Aztec network, an external function of a contract needs to be called. | ||
|
||
A contract may be declared and given a name using the `contract` keyword (see snippet below). By convention, contracts are named in `PascalCase`. | ||
|
||
```rust title="contract keyword" | ||
// highlight-next-line | ||
contract MyContract { | ||
|
||
// Functions and state variables belonging to this contract are not shown here. | ||
|
||
} | ||
``` | ||
|
||
|
||
> A note for vanilla Noir devs: There is no [`main()`](https://noir-lang.org/getting_started/breakdown/#mainnr) function within a Noir Contract scope. This is because more than one function of a contract may be called and proven as external (as opposed to inlined by the compiler). | ||
## Structure of a contract | ||
|
||
- Private state variables | ||
- Public state variables | ||
- Private functions | ||
- Public functions | ||
- Encrypted events | ||
- Unencrypted events |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
See sandbox section? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
## Events | ||
|
||
### Constraining events | ||
|
||
### Unencrypted Events | ||
|
||
### Encrypted Events | ||
|
||
### Costs | ||
|
||
Explain L1 cost to emit an event. | ||
|
||
## Processing events | ||
|
||
### Decrypting | ||
|
||
### Stev |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Functions | ||
|
||
## `constructor` | ||
|
||
- A special `constructor` function MUST be declared within a contract's scope. | ||
- A constructor doesn't have a name, because its purpose is clear: to initialise state. | ||
- In Aztec terminology, a constructor is always a 'private function' (i.e. it cannot be an `open` function). | ||
- A constructor behaves almost identically to any other function. It's just important for Aztec to be able to identify this function as special: it may only be called once, and will not be deployed as part of the contract. | ||
|
||
## secret functions | ||
|
||
## `open` functions | ||
|
||
## `unconstrained` functions | ||
|
||
|
||
|
||
# Calling functions | ||
|
||
## Inlining | ||
|
||
## Importing Contracts | ||
|
||
### Contract Interface | ||
|
||
## Constrained --> Unconstrained | ||
|
||
E.g. `get()` | ||
|
||
## Oracle calls | ||
|
||
## Private --> Private | ||
|
||
## Public --> Public | ||
|
||
## Private --> Public | ||
|
||
## `internal` keyword | ||
|
||
## Public --> Private | ||
|
||
## Recursive function calls | ||
|
||
## L1 --> L2 | ||
|
||
## L2 --> L1 | ||
|
||
## Delegatecall | ||
|
||
Talk a about the dangers of delegatecall too! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
- timestamp | ||
- block number | ||
- chain id | ||
- version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Layout | ||
## Directory structure | ||
|
||
Here's a common layout for a basic Noir Contract project: | ||
|
||
``` title="layout of an aztec contract project" | ||
─── my_aztec_contract_project | ||
├── src | ||
│ ├── main.nr <-- your contract | ||
│ └── storage.nr <-- state variable declarations (by convention) | ||
└── Nargo.toml <-- package and dependency management | ||
``` | ||
|
||
|
||
> See the vanilla Noir docs for [more info on packages](https://noir-lang.org/modules_packages_crates/crates_and_packages). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Access Control | ||
|
||
## msg_sender | ||
|
||
## slow updates tree (TBC!!!) |
Oops, something went wrong.