Skip to content

Commit

Permalink
chore: Remove TypeScript tooling from noir-projects. (#4867)
Browse files Browse the repository at this point in the history
As title.
  • Loading branch information
charlielye authored Feb 29, 2024
1 parent c7c24b2 commit 15c5399
Show file tree
Hide file tree
Showing 224 changed files with 60 additions and 262 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/mirror_repos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ jobs:
nargo_files="$(find $SUBREPO_PATH -name 'Nargo.toml' | xargs grep --files-with-matches 'noir-protocol-circuits')"
# match lines like this:
# protocol_types = { path = "../../noir-protocol-circuits/src/crates/types" }
# protocol_types = { path = "../../noir-protocol-circuits/crates/types" }
# and replace with
# protocol_types = { git="https://github.com/aztecprotocol/aztec-packages", tag="aztec-packages-v0.16.9", directory="noir-projects/noir-protocol-circuits/src/crates/types" }
# protocol_types = { git="https://github.com/aztecprotocol/aztec-packages", tag="aztec-packages-v0.16.9", directory="noir-projects/noir-protocol-circuits/crates/types" }
for nargo_file in $nargo_files; do
sed --regexp-extended --in-place \
"s;path\s*=\s*\".*noir-protocol-circuits(.*)\";git=\"$monorepo_url\", tag=\"$monorepo_tag\", directory=\"$monorepo_protocol_circuits_path\1\";" \
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/protocol-circuits-gate-diff.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ jobs:
run: nargo --version

- name: Generate gates report
working-directory: ./noir-projects/noir-protocol-circuits/src
working-directory: ./noir-projects/noir-protocol-circuits
run: |
nargo info --json > protocol_circuits_report.json
mv protocol_circuits_report.json ../../../protocol_circuits_report.json
nargo info --json --silence-warnings > protocol_circuits_report.json
mv protocol_circuits_report.json ../../protocol_circuits_report.json
env:
NARGO_BACKEND_PATH: ../../../barretenberg/cpp/build/bin/bb
NARGO_BACKEND_PATH: ../../barretenberg/cpp/build/bin/bb

- name: Compare gates reports
id: gates_diff
Expand Down
2 changes: 2 additions & 0 deletions build-system/scripts/build
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ function try_fetch_image() {
return 0
}

NOREPO=$(query_manifest noRepo $REPOSITORY)

# Login to ECR and ensure repository exists.
retry ensure_repo $REPOSITORY $ECR_REGION refresh_lifecycle
# Login to dockerhub.
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/developers/contracts/references/globals.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ context.version();

## Public Global Variables

#include_code global-variables /noir-projects/noir-protocol-circuits/src/crates/types/src/abis/global_variables.nr rust
#include_code global-variables /noir-projects/noir-protocol-circuits/crates/types/src/abis/global_variables.nr rust

The public global variables contain the values present in the `private global variables` described above, with the addition of:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ A note should implement the following traits:

#include_code note_interface /noir-projects/aztec-nr/aztec/src/note/note_interface.nr rust

#include_code serialize /noir-projects/noir-protocol-circuits/src/crates/types/src/traits.nr rust
#include_code serialize /noir-projects/noir-protocol-circuits/crates/types/src/traits.nr rust

#include_code deserialize /noir-projects/noir-protocol-circuits/src/crates/types/src/traits.nr rust
#include_code deserialize /noir-projects/noir-protocol-circuits/crates/types/src/traits.nr rust

The interplay between a private state variable and its notes can be confusing. Here's a summary to aid intuition:

Expand Down Expand Up @@ -226,7 +226,7 @@ An example of how to use this operation is visible in the `easy_private_state`:

This function returns the notes the account has access to.

The kernel circuits are constrained to a maximum number of notes this function can return at a time. Check [here](https://github.com/AztecProtocol/aztec-packages/blob/#include_aztec_version/noir-projects/noir-protocol-circuits/src/crates/types/src/constants.nr) and look for `MAX_READ_REQUESTS_PER_CALL` for the up-to-date number.
The kernel circuits are constrained to a maximum number of notes this function can return at a time. Check [here](https://github.com/AztecProtocol/aztec-packages/blob/#include_aztec_version/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr) and look for `MAX_READ_REQUESTS_PER_CALL` for the up-to-date number.

Because of this limit, we should always consider using the second argument `NoteGetterOptions` to limit the number of notes we need to read and constrain in our programs. This is quite important as every extra call increases the time used to prove the program and we don't want to spend more time than necessary.

Expand All @@ -240,7 +240,7 @@ Functionally similar to [`get_notes`](#get_notes), but executed unconstrained an

#include_code view_notes /noir-projects/aztec-nr/value-note/src/balance_utils.nr rust

There's also a limit on the maximum number of notes that can be returned in one go. To find the current limit, refer to [this file](https://github.com/AztecProtocol/aztec-packages/blob/#include_aztec_version/noir-projects/noir-protocol-circuits/src/crates/types/src/constants.nr) and look for `MAX_NOTES_PER_PAGE`.
There's also a limit on the maximum number of notes that can be returned in one go. To find the current limit, refer to [this file](https://github.com/AztecProtocol/aztec-packages/blob/#include_aztec_version/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr) and look for `MAX_NOTES_PER_PAGE`.

The key distinction is that this method is unconstrained. It does not perform a check to verify if the notes actually exist, which is something the [`get_notes`](#get_notes) method does under the hood. Therefore, it should only be used in an unconstrained contract function.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ For a higher level overview of the state model in Aztec, see the [state model](.

The `PublicMutable` (formerly known as `PublicState`) struct is generic over the variable type `T`. The type _must_ implement Serialize and Deserialize traits, as specified here:

#include_code serialize /noir-projects/noir-protocol-circuits/src/crates/types/src/traits.nr rust
#include_code deserialize /noir-projects/noir-protocol-circuits/src/crates/types/src/traits.nr rust
#include_code serialize /noir-projects/noir-protocol-circuits/crates/types/src/traits.nr rust
#include_code deserialize /noir-projects/noir-protocol-circuits/crates/types/src/traits.nr rust

The struct contains a `storage_slot` which, similar to Ethereum, is used to figure out _where_ in storage the variable is located. Notice that while we don't have the exact same [state model](../../../../learn/concepts/hybrid_state/main.md) as EVM chains it will look similar from the contract developers point of view.

Expand Down
4 changes: 2 additions & 2 deletions docs/docs/developers/contracts/resources/dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ This is an abstraction library for using private variables like [`EasyPrivateUin
## Protocol Types

```toml
protocol_types = { git="https://github.com/AztecProtocol/aztec-packages/", tag="#include_aztec_version", directory="noir-projects/noir-protocol-circuits/src/crates/types"}
protocol_types = { git="https://github.com/AztecProtocol/aztec-packages/", tag="#include_aztec_version", directory="noir-projects/noir-protocol-circuits/crates/types"}
```

This library contains types that are used in the Aztec protocol. Find it on [GitHub](https://github.com/AztecProtocol/aztec-packages/tree/master/noir-projects/noir-protocol-circuits/src/crates/types/src).
This library contains types that are used in the Aztec protocol. Find it on [GitHub](https://github.com/AztecProtocol/aztec-packages/tree/master/noir-projects/noir-protocol-circuits/crates/types/src).

## Value note

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ As shown in the snippet, the application context is made up of 4 main structures

First of all, the call context.

#include_code call-context /noir-projects/noir-protocol-circuits/src/crates/types/src/abis/call_context.nr rust
#include_code call-context /noir-projects/noir-protocol-circuits/crates/types/src/abis/call_context.nr rust

The call context contains information about the current call being made:

Expand Down Expand Up @@ -75,13 +75,13 @@ Another structure that is contained within the context is the Header object.
In the private context this is a header of a block which used to generate proofs against.
In the public context this header is set by sequencer (sequencer executes public calls) and it is set to 1 block before the block in which the transaction is included.

#include_code header /noir-projects/noir-protocol-circuits/src/crates/types/src/header.nr rust
#include_code header /noir-projects/noir-protocol-circuits/crates/types/src/header.nr rust

### Contract Deployment Data

Just like with the `is_contract_deployment` flag mentioned earlier. This data will only be set to true when the current transaction is one in which a contract is being deployed.

#include_code contract-deployment-data /noir-projects/noir-protocol-circuits/src/crates/types/src/contrakt/contract_deployment_data.nr rust
#include_code contract-deployment-data /noir-projects/noir-protocol-circuits/crates/types/src/contrakt/contract_deployment_data.nr rust

### Private Global Variables

Expand Down Expand Up @@ -145,4 +145,4 @@ In the current version of the system, the public context is almost a clone of th

The public global variables are provided by the rollup sequencer and consequently contain some more values than the private global variables.

#include_code global-variables /noir-projects/noir-protocol-circuits/src/crates/types/src/abis/global_variables.nr rust
#include_code global-variables /noir-projects/noir-protocol-circuits/crates/types/src/abis/global_variables.nr rust
2 changes: 1 addition & 1 deletion docs/docs/developers/debugging/sandbox-errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ Circuits work by having a fixed size array. As such, we have limits on how many
- too many transient read requests in one tx
- too many transient read request membership witnesses in one tx

You can have a look at our current constants/limitations in [constants.nr](https://github.com/AztecProtocol/aztec-packages/blob/master/noir-projects/noir-protocol-circuits/src/crates/types/src/constants.nr)
You can have a look at our current constants/limitations in [constants.nr](https://github.com/AztecProtocol/aztec-packages/blob/master/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr)

#### 7008 - MEMBERSHIP_CHECK_FAILED

Expand Down
2 changes: 1 addition & 1 deletion docs/docs/developers/limitations/main.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ Due to the rigidity of zk-SNARK circuits, there are upper bounds on the amount o
Here are the current constants:

#include_code constants /noir-projects/noir-protocol-circuits/src/crates/types/src/constants.nr rust
#include_code constants /noir-projects/noir-protocol-circuits/crates/types/src/constants.nr rust

#### What are the consequences?

Expand Down
12 changes: 7 additions & 5 deletions docs/docs/misc/migration_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ Historically developers have been required to include a `compute_note_hash_and_n
It is possible to provide a user-defined implementation, in which case auto-generation will be skipped (though there are no known use cases for this).

### Updated naming of state variable wrappers

We have decided to change the naming of our state variable wrappers because the naming was not clear.
The changes are as follows:

1. `Singleton` -> `PrivateMutable`
2. `ImmutableSingleton` -> `PrivateImmutable`
3. `StablePublicState` -> `SharedImmutable`
5. `PublicState` -> `PublicMutable`
4. `PublicState` -> `PublicMutable`

This is the meaning of "private", "public" and "shared":
Private: read (R) and write (W) from private, not accessible from public
Expand Down Expand Up @@ -112,7 +114,7 @@ Aztec contracts are now moved outside of the `yarn-project` folder and into `noi
Before:

```rust
easy_private_token_contract = {git = "https://github.com/AztecProtocol/aztec-packages/", tag ="v0.23.0", directory = "yarn-project/noir-contracts/src/contracts/easy_private_token_contract"}
easy_private_token_contract = {git = "https://github.com/AztecProtocol/aztec-packages/", tag ="v0.23.0", directory = "yarn-project/noir-contracts/contracts/easy_private_token_contract"}
```

Now, update the `yarn-project` folder for `noir-projects`:
Expand Down Expand Up @@ -649,7 +651,7 @@ const tokenBigInt = (await bridge.methods.token().view()).inner;

```toml
aztec = { git="https://github.com/AztecProtocol/aztec-packages/", tag="#include_aztec_version", directory="yarn-project/aztec-nr/aztec" }
protocol_types = { git="https://github.com/AztecProtocol/aztec-packages/", tag="#include_aztec_version", directory="yarn-project/noir-protocol-circuits/src/crates/types"}
protocol_types = { git="https://github.com/AztecProtocol/aztec-packages/", tag="#include_aztec_version", directory="yarn-project/noir-protocol-circuits/crates/types"}
```

### [Aztec.nr] moving compute_address func to AztecAddress
Expand Down Expand Up @@ -703,11 +705,11 @@ Aztec contracts are now moved outside of the `src` folder, so you need to update
Before:

```rust
easy_private_token_contract = {git = "https://github.com/AztecProtocol/aztec-packages/", tag ="v0.16.9", directory = "yarn-project/noir-contracts/src/contracts/easy_private_token_contract"}
easy_private_token_contract = {git = "https://github.com/AztecProtocol/aztec-packages/", tag ="v0.16.9", directory = "noir-projects/noir-contracts/contracts/easy_private_token_contract"}
```

Now, just remove the `src` folder,:

```rust
easy_private_token_contract = {git = "https://github.com/AztecProtocol/aztec-packages/", tag ="v0.17.0", directory = "yarn-project/noir-contracts/contracts/easy_private_token_contract"}
easy_private_token_contract = {git = "https://github.com/AztecProtocol/aztec-packages/", tag ="v0.17.0", directory = "noir-projects/noir-contracts/contracts/easy_private_token_contract"}
```
6 changes: 3 additions & 3 deletions noir-projects/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ WORKDIR /usr/src/noir-projects
COPY . .
# Build
WORKDIR /usr/src/noir-projects/noir-contracts
RUN ./scripts/compile.sh && ./scripts/transpile.sh && nargo test --silence-warnings
RUN ./bootstrap.sh && nargo test --silence-warnings
WORKDIR /usr/src/noir-projects/noir-protocol-circuits
RUN cd src && nargo compile --silence-warnings && nargo test --silence-warnings
RUN ./bootstrap.sh && nargo test --silence-warnings
WORKDIR /usr/src/noir-projects/aztec-nr
RUN nargo compile --silence-warnings && nargo test --silence-warnings
RUN nargo test --silence-warnings

FROM scratch
COPY --from=builder /usr/src/noir-projects /usr/src/noir-projects
2 changes: 1 addition & 1 deletion noir-projects/aztec-nr/aztec/Nargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ compiler_version = ">=0.18.0"
type = "lib"

[dependencies]
protocol_types = { path = "../../noir-protocol-circuits/src/crates/types" }
protocol_types = { path = "../../noir-protocol-circuits/crates/types" }
2 changes: 1 addition & 1 deletion noir-projects/bootstrap_cache.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ source ../build-system/scripts/setup_env '' '' mainframe_$USER > /dev/null
echo -e "\033[1mRetrieving noir projects from remote cache...\033[0m"
extract_repo noir-projects \
/usr/src/noir-projects/noir-contracts/target ./noir-contracts \
/usr/src/noir-projects/noir-protocol-circuits/src/target ./noir-protocol-circuits/src
/usr/src/noir-projects/noir-protocol-circuits/target ./noir-protocol-circuits

remove_old_images noir-projects
3 changes: 1 addition & 2 deletions noir-projects/noir-contracts/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
target/
/src
target
145 changes: 2 additions & 143 deletions noir-projects/noir-contracts/README.md
Original file line number Diff line number Diff line change
@@ -1,144 +1,3 @@
# Aztec.nr contracts
# Aztec Example Contracts

This package contains the source code and the Aztec ABIs for the example contracts used in tests.

## Disclaimer

Please note that any example contract set out herein is provided solely for informational purposes only and does not constitute any inducement to use or deploy. Any implementation of any such contract with an interface or any other infrastructure should be used in accordance with applicable laws and regulations.

## Setup

### Installing Noir

An essential tool for managing noir versions is noirup.

- Install [noirup](https://github.com/noir-lang/noirup)
```
curl -L https://raw.githubusercontent.com/noir-lang/noirup/main/install | bash
```

### Happy Path

Currently we all work from a single `aztec` tagged noir release. This release updates independently from noir's regular cadence to allow us to rapidly prototype new features.
It has prebuilt binaries and is super easy to install using `noirup`

- Install [noirup](https://github.com/noir-lang/noirup)
```
curl -L https://raw.githubusercontent.com/noir-lang/noirup/main/install | bash
```
- Install `aztec` tagged nargo
```
noirup -v aztec
```

> Pinning Aztec flavoured noir releases
> Aztec noir is released with semver alongside noir. If you would like to pin to a specific version you can run:
>
> ```bash
> noirup -v <noir-version>-aztec.<patch version>
> ```
>
> e.g `noirup -v 0.11.1-aztec.0`
### Building from source (If working with custom features)
- Install [noirup](https://github.com/noir-lang/noirup)
```
curl -L https://raw.githubusercontent.com/noir-lang/noirup/main/install | bash
```
- Nix is already globally installed but path to this installation needs to be added in $HOME/.zshenv so correct configuration can be found by VSCode, do so with:
```
echo -e '\n# Nix path set globally\nexport PATH="$HOME/.nix-profile/bin:/nix/var/nix/profiles/default/bin:$PATH"' >> $HOME/.zshenv
```
- Enable nix flake command in ~/.config/nix/nix.conf with commands:
```
mkdir -p $HOME/.config/nix && echo -e '\nexperimental-features = nix-command\nextra-experimental-features = flakes' >> $HOME/.config/nix/nix.conf
```
- Install direnv into your Nix profile by running:
```
nix profile install nixpkgs#direnv
```
- Add direnv to your shell following their guide
```
echo -e '\n# Adds direnv initialization\neval "$(direnv hook zsh)"' >> $HOME/.zshenv
```
- VSCode needs to be restarted so direnv plugin can notice env changes with:
```
kill -9 ps aux | grep $(whoami)/.vscode-server | awk '{print $2}'
```
- Restart shell

- Clone noir repo:

```
git clone https://github.com/noir-lang/noir.git
```

- Checkout your target noir branch

```
cd noir
git checkout <branch>
```

- Enable direnv

```
direnv allow
```

- Restart shell

- Go to the noir dir and install Noir:
```
cd noir
noirup -p ./
```

### Building the contracts

- In the aztec-packages repository, go to the directory noir-contracts

- Use the `noir:build:all` script to compile the contracts you want and prepare the ABI for consumption

```
yarn noir:build:all
```

Alternatively you can run `yarn noir:build CONTRACT1 CONTRACT2...` to build a subset of contracts:

```
yarn noir:build private_token public_token
```

To view compilation output, including errors, run with the `VERBOSE=1` flag:

```
VERBOSE=1 yarn noir:build private_token public_token
```

## Creating a new contract package

1. Go to `src/contracts` folder.
2. Create a new package whose name has to end with **\_contract**. E.g.:
```
nargo new --contract example_contract
```
3. Add the aztec dependency to `nargo.toml`:

```
[package]
authors = [""]
compiler_version = "0>=.18.0"
[dependencies]
aztec = { path = "../../../../aztec-nr/aztec" }
```

4. Replace the content of the generated `example_contract/src/main.nr` file with your contract code.
5. Go to `noir-contracts` root folder and run `yarn noir:build example` to compile the contract.
6. Export the abi in `src/artifacts/index.ts` to be able to use the contract in the rest of the project:
```
import ExampleContractJson from './example_contract.json' assert { type: 'json' };
export const ExampleContractArtifact = ExampleContractJson as ContractArtifact;
```
You're smart enough to figure it out.
10 changes: 8 additions & 2 deletions noir-projects/noir-contracts/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,11 @@ if [ -n "$CMD" ]; then
fi
fi

# Build the contracts. `yarn build` handles cleaning as well
yarn build
echo "Compiling contracts..."
../../noir/noir-repo/target/release/nargo compile --silence-warnings

echo "Transpiling avm contracts..."
for contract_json in target/avm_test_*.json; do
echo Transpiling $contract_json...
../../avm-transpiler/target/release/avm-transpiler $contract_json $contract_json
done
Loading

0 comments on commit 15c5399

Please sign in to comment.