Skip to content
This repository has been archived by the owner on Oct 17, 2023. It is now read-only.

Jc/workspaces #342

Merged
merged 25 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
3de4cba
update commands
critesjosh Aug 16, 2023
2c48357
start workspaces page
critesjosh Aug 17, 2023
9f4f8d7
add nargo.toml example
critesjosh Aug 18, 2023
4958fb5
toml to yaml highlighting
critesjosh Aug 18, 2023
3fe6ccc
updates
critesjosh Aug 22, 2023
5bc2e0b
update title
critesjosh Aug 22, 2023
8c7d3df
add nargo check contract note
critesjosh Aug 22, 2023
5dd0930
Update docs/getting_started/02_breakdown.md
critesjosh Aug 25, 2023
f075aa3
Update docs/getting_started/02_breakdown.md
critesjosh Aug 25, 2023
56b3bef
Update docs/getting_started/02_breakdown.md
critesjosh Aug 25, 2023
9b5c141
Update versioned_docs/version-0.3.2/getting_started/hello_world/01_br…
critesjosh Aug 25, 2023
c9dd170
Update versioned_docs/version-0.9.0/modules_packages_crates/dependenc…
critesjosh Aug 25, 2023
9506708
Update versioned_docs/version-0.9.0/modules_packages_crates/dependenc…
critesjosh Aug 25, 2023
2f8ff4e
add toml
critesjosh Aug 25, 2023
0d400f6
Merge branch 'jc/workspaces' of https://github.com/noir-lang/docs int…
critesjosh Aug 25, 2023
3e449e9
Update docs/modules_packages_crates/dependencies.md
critesjosh Aug 25, 2023
19aad58
Update versioned_docs/version-0.9.0/getting_started/02_breakdown.md
critesjosh Aug 25, 2023
9917a45
remove prove and verify args
critesjosh Aug 25, 2023
8030a25
Merge branch 'jc/workspaces' of https://github.com/noir-lang/docs int…
critesjosh Aug 25, 2023
941a26d
fix formatting
critesjosh Aug 25, 2023
9514255
note on libs in workspaces
critesjosh Aug 25, 2023
0b8c4b2
add nargo.toml details
critesjosh Aug 25, 2023
4279f0e
add contract crate type
critesjosh Aug 25, 2023
b4ab9eb
Update docs/modules_packages_crates/workspaces.md
critesjosh Aug 28, 2023
2643c05
Update docs/modules_packages_crates/workspaces.md
critesjosh Aug 28, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions docs/getting_started/01_hello_world.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,14 @@ x = "1"
y = "2"
```

Prove the valid execution of your Noir program with your preferred proof name, for example `p`:
Prove the valid execution of your Noir program:

```sh
nargo prove p
nargo prove
```

A new folder _proofs_ would then be generated in your project directory, containing the proof file
`p.proof`.
`<project-name>.proof`, where the project name is defined in Nargo.toml.

The _Verifier.toml_ file would also be updated with the public values computed from program
execution (in this case the value of `y`):
Expand All @@ -133,10 +133,10 @@ y = "0x0000000000000000000000000000000000000000000000000000000000000002"
Once a proof is generated, we can verify correct execution of our Noir program by verifying the
proof file.

Verify your proof of name `p` by running:
Verify your proof by running:

```sh
nargo verify p
nargo verify
```

The verification will complete in silence if it is successful. If it fails, it will log the
Expand Down
57 changes: 37 additions & 20 deletions docs/getting_started/02_breakdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,30 +35,48 @@ _Verifier.toml_ contains public in/output values computed when executing the Noi

_Nargo.toml_ contains the environmental options of your project. It contains a "package" section and a "dependencies" section.

#### Package section

The package section requires a number of fields including:

- name - the name of the package
- type - can be "bin", "lib", or "contract" to specify whether its a binary, library or Aztec contract
- authors
- compiler_version - specifies the version of the compiler to use. This is not currently enforced by the compiler, but will be in future versions.

For example:
Example Nargo.toml:

```toml
[package]
name = "noirstarter"
type = "bin"
authors = ["Alice"]
compiler_version = "0.9.0"
description = "Getting started with Noir"
entry = "circuit/main.nr"
license = "MIT"

[dependencies]
ecrecover = {tag = "v0.9.0", git = "https://github.com/colinnielsen/ecrecover-noir.git"}
```

Nargo.toml for a [workspace](../modules_packages_crates/workspaces) will look a bit different. For example:

```toml
[workspace]
members = ["crates/a", "crates/b"]
default-member = "crates/a"
```

#### Package section

The package section requires a number of fields including:

- `name` (**required**) - the name of the package
- `type` (**required**) - can be "bin", "lib", or "contract" to specify whether its a binary, library or Aztec contract
- `authors` (optional) - authors of the project
- `compiler_version` (optional) - specifies the version of the compiler to use. This is not currently enforced by the compiler, but will be in future versions.
- `description` (optional)
- `entry` (optional) - a relative filepath to use as the entry point into your package (overrides the default of `src/lib.nr` or `src/main.nr`)
- `backend` (optional)
- `license` (optional)

#### Dependencies section

This is where you will specify any dependencies for your project. See the [Dependencies page](../modules_packages_crates/dependencies) for more info.

_proofs_ and _contract_ directories will not be immediately visible until you create a proof or
`./proofs/` and `./contract/` directories will not be immediately visible until you create a proof or
verifier contract respectively.

### main.nr
Expand Down Expand Up @@ -95,13 +113,12 @@ x = "1"
y = "2"
```

When the command `nargo prove my_proof` is executed, two processes happen:
When the command `nargo prove` is executed, two processes happen:

1. Noir creates a proof that `x` which holds the value of `1` and `y` which holds the value of `2`
is not equal. This not equal constraint is due to the line `assert(x != y)`.

2. Noir creates and stores the proof of this statement in the _proofs_ directory and names the proof
file _my_proof_. Opening this file will display the proof in hex format.
2. Noir creates and stores the proof of this statement in the _proofs_ directory in a file called your-project.proof. So if your project is named "private_voting" (defined in the project Nargo.toml), the proof will be saved at `./proofs/private_voting.proof`. Opening this file will display the proof in hex format.

#### Arrays of Structs

Expand Down Expand Up @@ -139,23 +156,23 @@ baz = 2

You can specify a `toml` file with a different name to use for proving by using the `--prover-name` or `-p` flags.

This command looks for proof inputs in the default **Prover.toml** and generates proof `p`:
This command looks for proof inputs in the default **Prover.toml** and generates the proof and saves it at `./proofs/<project-name>.proof`:

```bash
nargo prove p
nargo prove
```

This command looks for proof inputs in the custom **OtherProver.toml** and generates proof `pp`:
This command looks for proof inputs in the custom **OtherProver.toml** and generates proof and saves it at `./proofs/<project-name>.proof`:

```bash
nargo prove -p OtherProver pp
nargo prove -p OtherProver
```

## Verifying a Proof

When the command `nargo verify my_proof` is executed, two processes happen:
When the command `nargo verify` is executed, two processes happen:

1. Noir checks in the _proofs_ directory for a file called _my_proof_
1. Noir checks in the _proofs_ directory for a proof file with the project name (eg. test_project.proof)

2. If that file is found, the proof's validity is checked

Expand Down
13 changes: 10 additions & 3 deletions docs/modules_packages_crates/crates_and_packages.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
title: Crates and Packages
description:
Learn how to use Crates and Packages in your Noir project
description: Learn how to use Crates and Packages in your Noir project
keywords: [Nargo, dependencies, package management, crates, package]
---

Expand All @@ -12,12 +11,20 @@ Crates can contain modules, and the modules may be defined in other files that g

### Crate Types

A Noir crate can come in one of two forms: a binary crate or a library crate.
A Noir crate can come in several forms: binaries, libraries or contracts.

#### Binaries

_Binary crates_ are programs which you can compile to an ACIR circuit which you can then create proofs against. Each must have a function called `main` that defines the ACIR circuit which is to be proved.

#### Libraries
critesjosh marked this conversation as resolved.
Show resolved Hide resolved

_Library crates_ don't have a `main` function and they don't compile down to ACIR. Instead they define functionality intended to be shared with multiple projects, and eventually included in a binary crate.

#### Contracts
critesjosh marked this conversation as resolved.
Show resolved Hide resolved

Contract crates are similar to binary crates in that they compile to ACIR which you can create proofs against. They are different in that they do not have a single `main` function, but are a collection of functions to be deployed to the [Aztec network](https://aztec.network). You can learn more about the technical details of Aztec in the [monorepo](https://github.com/AztecProtocol/aztec-packages) or contract [examples](https://github.com/AztecProtocol/aztec-packages/tree/master/yarn-project/noir-contracts/src/contracts).

### Crate Root

Every crate has a root, which is the source file that the compiler starts, this is also known as the root module. The Noir compiler does not enforce any conditions on the name of the file which is the crate root, however if you are compiling via Nargo the crate root must be called `lib.nr` or `main.nr` for library or binary crates respectively.
Expand Down
8 changes: 6 additions & 2 deletions docs/modules_packages_crates/dependencies.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: Managing Dependencies
title: Dependencies
description:
Learn how to specify and manage dependencies in Nargo, allowing you to upload packages to GitHub
and use them easily in your project.
Expand Down Expand Up @@ -34,7 +34,7 @@ You can also specify dependencies that are local to your machine.

For example, this file structure has a library and binary crate

```
```tree
├── binary_crate
│   ├── Nargo.toml
│   └── src
Expand Down Expand Up @@ -79,6 +79,10 @@ can import multiple items in the same line by enclosing them in curly braces:
use dep::std::ec::tecurve::affine::{Curve, Point};
```

We don't have a way to consume libraries from inside a [workspace](./workspaces) as external dependencies right now.

Inside a workspace, these are consumed as `{ path = "../to_lib" }` dependencies in Nargo.toml.

## Dependencies of Dependencies

Note that when you import a dependency, you also get access to all of the dependencies of that package.
Expand Down
10 changes: 5 additions & 5 deletions docs/modules_packages_crates/modules.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
---
title: Understanding Modules
title: Modules
description:
Learn how to organize your files using modules in Noir, following the same convention as Rust's
module system. Examples included.
keywords: [Noir, Rust, modules, organizing files, sub-modules]
---

# Modules

Noir's module system follows the same convention as the _newer_ version of Rust's module system.

## Purpose of Modules
Expand Down Expand Up @@ -51,7 +49,8 @@ crate
```

### Importing a module throughout the tree
All modules are accessible from the ``crate::`` namespace.

All modules are accessible from the `crate::` namespace.

```
crate
Expand All @@ -60,7 +59,8 @@ crate
└── main

```
In the above snippet, if ``bar`` would like to use functions in ``foo``, it can do so by ``use crate::foo::function_name``.

In the above snippet, if `bar` would like to use functions in `foo`, it can do so by `use crate::foo::function_name`.

### Sub-modules

Expand Down
39 changes: 39 additions & 0 deletions docs/modules_packages_crates/workspaces.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
title: Workspaces
---

Workspaces are a feature of nargo that allow you to manage multiple related Noir packages in a single repository. A workspace is essentially a group of related projects that share common build output directories and configurations.

Each Noir project (with it's own Nargo.toml file) can be thought of as a package. Each package is expected to contain exactly one "named circuit", being the "name" defined in Nargo.toml with the program logic defined in `./src/main.nr`.

For a project with the following structure:

```tree
├── crates
│   ├── a
│   │   ├── Nargo.toml
│   │   └── src
│   │   └── main.nr
│   └── b
│   ├── Nargo.toml
│   └── src
│   └── main.nr
├── Nargo.toml
└── Prover.toml
```

You can define a workspace in Nargo.toml like so:

```toml
[workspace]
members = ["crates/a", "crates/b"]
default-member = "crates/a"
```

`members` indicates which packages are included in the workspace. As such, all member packages of a workspace will be processed when the `--workspace` flag is used with various commands or if a `default-member` is not specified.

`default-member` indicates which package various commands process by default.

Libraries can be defined in a workspace. We just don't have a way to consume libraries from inside a workspace as external dependencies right now.

Inside a workspace, these are consumed as `{ path = "../to_lib" }` dependencies in Nargo.toml.
Loading