Skip to content

Commit

Permalink
feat(docs): Aztec.nr errors in docs (#3113)
Browse files Browse the repository at this point in the history
Closes #2905
* Debugging section with aztec and sandbox errors (moved common errors
into here)
* Dependencies section 

still need to update after getting-started pr is merged

# Checklist:
Remove the checklist to signal you've completed it. Enable auto-merge if
the PR is ready to merge.
- [ ] If the pull request requires a cryptography review (e.g.
cryptographic algorithm implementations) I have added the 'crypto' tag.
- [ ] I have reviewed my diff in github, line by line and removed
unexpected formatting changes, testing logs, or commented-out code.
- [ ] Every change is related to the PR description.
- [ ] I have
[linked](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue)
this pull request to relevant issues (if any exist).
  • Loading branch information
catmcgee authored Nov 6, 2023
1 parent dbfb086 commit fb1e80b
Show file tree
Hide file tree
Showing 7 changed files with 270 additions and 122 deletions.
53 changes: 0 additions & 53 deletions docs/docs/dev_docs/contracts/common_errors.md

This file was deleted.

59 changes: 59 additions & 0 deletions docs/docs/dev_docs/contracts/resources/dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
title: Dependencies
---

On this page you will find information about Aztec.nr dependencies and up-to-date paths for use in your `Nargo.toml`.

## Aztec

```toml
aztec = { git="https://github.com/AztecProtocol/aztec-packages/", tag="#include_aztec_version", directory="yarn-project/aztec-nr/aztec" }
```

This is the core Aztec library that is required for every Aztec.nr smart contract.

## Authwit

```toml
authwit = { git="https://github.com/AztecProtocol/aztec-packages/", tag="#include_aztec_version", directory="yarn-project/aztec-nr/authwit"}
```

This allows you to use authentication witnesses in your contract. Find more about its usage [here](../resources/common_patterns/authwit.md).

## Address note

```toml
address_note = { git="https://github.com/AztecProtocol/aztec-packages/", tag="#include_aztec_version", directory="yarn-project/aztec-nr/address-note" }
```

## Assets

```toml
assets = { git="https://github.com/AztecProtocol/aztec-packages/", tag="#include_aztec_version", directory="yarn-project/aztec-nr/assets" }
```

This is a library for utilizing notes that hold addresses. Find it on [GitHub](https://github.com/AztecProtocol/aztec-packages/tree/master/yarn-project/aztec-nr/address-note/src).

## Easy private state

```toml
easy_private_state = { git="https://github.com/AztecProtocol/aztec-packages/", tag="#include_aztec_version", directory="yarn-project/aztec-nr/easy-private-state" }
```

This is an abstraction library for using private variables like [`EasyPrivateUint`](https://github.com/AztecProtocol/aztec-packages/blob/6c20b45993ee9cbd319ab8351e2722e0c912f427/yarn-project/aztec-nr/easy-private-state/src/easy_private_state.nr#L17).

## Safe math

```toml
safe_math = { git="https://github.com/AztecProtocol/aztec-packages/", tag="#include_aztec_version", directory="yarn-project/aztec-nr/safe-math" }
```

This is a library for safe arithmetic, similar to OpenZeppelin's safe math library. Find it on [GitHub](https://github.com/AztecProtocol/aztec-packages/tree/master/yarn-project/aztec-nr/safe-math).

## Value note

```toml
value_note = { git="https://github.com/AztecProtocol/aztec-packages/", tag="#include_aztec_version", directory="yarn-project/aztec-nr/value-note" }
```

This is a library for a note that stores one arbitrary value. You can see an example of how it might be used in the [token contract tutorial](../../tutorials/writing_token_contract.md).
78 changes: 78 additions & 0 deletions docs/docs/dev_docs/debugging/aztecnr-errors.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
---
title: Aztec.nr Errors
---

This section contains some errors that you may encounter when writing and compiling contracts in Aztec.nr. If you run into an error that is not listed here, please [create an issue](https://github.com/AztecProtocol/aztec-packages/issues/new).

#### `Aztec dependency not found. Please add aztec as a dependency in your Nargo.toml`

All smart contracts written in Aztec.nr need the `aztec` dependency. In your `Nargo.toml` under `[dependencies]`, add this:

```toml
aztec = { git="https://github.com/AztecProtocol/aztec-packages/", tag="#include_aztec_version", directory="yarn-project/aztec-nr/aztec" }
```

You can learn more about dependencies and their paths [here](../contracts/resources/dependencies.md).

#### `compute_note_hash_and_nullifier function not found. Define it in your contract`

Any smart contract that utilizes private varibles must include a [`compute_note_hash_and_nullifier`](https://github.com/AztecProtocol/aztec-packages/blob/6c20b45993ee9cbd319ab8351e2722e0c912f427/yarn-project/aztec-nr/aztec/src/note/utils.nr#L69) function to allow the PXE to process encrypted events.

This is an example of this function in the token contract:

#include_code compute_note_hash_and_nullifier yarn-project/noir-contracts/src/contracts/token_contract/src/main.nr rust

This error may also show if the `compute_note_hash_and_nullifier` function is not correct or sits outside of the contract.

#### `backend has encountered an error`

This is likely due to a version mismatch or bad install of barretenberg. Try [reinstalling nargo](../cli/updating.md) or uninstalling barretenberg:

```bash
nargo backend uninstall acvm-backend-barretenberg
```

It will then reinstall when you compile.

#### `Oracle callback {} not found` & `Oracle callback pedersenHash not found`

This can occasionally happen when there are breaking releases. Make sure that your dependencies in `Nargo.toml` are [updated to the latest release](../contracts/resources/dependencies.md).

#### `error: Failed constraint: 'Public state writes only supported in public functions`

Reading and writing to public state from private functions is currently not supported.
This is because public values may change before the private function execution is posted on-chain.

This may change in future versions.

#### `Simulation error: Assertion failed:...`

This is an assertion error that is thrown when a condition is not met.

To address the error. find the line in the contract that is throwing the error and investigate why the condition is not met.

#### `Unknown contract 0x0: add it to PXE by calling server.addContracts(...)`

This error occurs when you are trying to interact with a smart contract via an Private Execution Environment (PXE) that does not have the necessary information to execute a transaction.

To execute a transaction, the PXE needs to know the complete address of a contract, portal address (if portal is used) and contract artifacts.

To address the error, add the contract to the PXE by calling [`pxe.addContracts(...)`](../../apis/pxe/interfaces/PXE#addcontracts).

`Simulation error: No public key registered for address 0x0. Register it by calling pxe.registerRecipient(...) or pxe.registerAccount(...)`

This error occurs when your contract is trying to get a public key via the `get_public_key` oracle call, but the PXE does not have the Complete Address (Complete Address contains the public key).

Your contract typically needs a note recipient's public key when it wants to send a note to because the public key is used to encrypt notes.

:::info
Manually adding the recipient to the PXE should not be required in case the recipient contract has already been deployed and the PXE is fully synced.
This is because this information is submitted on-chain when the recipient contract is deployed.
:::

#### `Could not process note because of "Error: Unknown account.". Skipping note...`

This error occurs when your contract is trying to get a secret via the `get_secret` oracle call, but the PXE does not have the secret for the public key.

This error might occur when you register an account only as a recipient and not as an account.
To address the error, register the account by calling `server.registerAccount(...)`.
9 changes: 9 additions & 0 deletions docs/docs/dev_docs/debugging/main.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
title: Debugging
---

import DocCardList from '@theme/DocCardList';

On this section you can learn how to debug your Aztec.nr smart contracts and common errors that you may run into.

<DocCardList/>
Loading

0 comments on commit fb1e80b

Please sign in to comment.