Skip to content

Commit

Permalink
fix(docs): Some docs updates (#8412)
Browse files Browse the repository at this point in the history
Included in this PR:
- updates to a key rotation page, closes
AztecProtocol/dev-rel#312
- update docs on unencrypted events, private functions cannot emit
unencrypted events. closes
AztecProtocol/dev-rel#377
- add detail on partial note use cases
AztecProtocol/dev-rel#382
- closes AztecProtocol/dev-rel#391
  • Loading branch information
critesjosh authored Sep 9, 2024
1 parent a9f2364 commit ad73f30
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 21 deletions.
2 changes: 1 addition & 1 deletion aztec-up/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# The Aztec Installation Script

```
bash -i <(curl -s install.aztec.network)
bash -i <(curl -s https://install.aztec.network)
```

That is all.
Expand Down
2 changes: 1 addition & 1 deletion aztec-up/bin/aztec-up
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ set -euo pipefail

export VERSION=${1:-${VERSION:-}}
export NON_INTERACTIVE=1
bash -i <(curl -s http://install.aztec.network)
bash -i <(curl -s https://install.aztec.network)
18 changes: 16 additions & 2 deletions docs/docs/aztec/concepts/storage/partial_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ Partial notes are a concept that allows users to commit to an encrypted value, a

Why is this useful?

Consider the case where a user wants to pay for a transaction fee, using a [fee-payment contract](../../../protocol-specs/gas-and-fees/index.md) and they want to do this privately. They can't be certain what the transaction fee will be because the state of the network will have progressed by the time the transaction is processed by the sequencer, and transaction fees are dynamic. So the user can commit to a value for the transaction fee, publicly post this commitment, the fee payer can update the public commitment, deducting the final cost of the transaction from the commitment and returning the unused value to the user.
Consider the case where a user wants to pay for a transaction fee, using a [fee-payment contract](../../../protocol-specs/gas-and-fees/index.md) and they want to do this privately. They can't be certain what the transaction fee will be because the state of the network will have progressed by the time the transaction is processed by the sequencer, and transaction fees are dynamic. So the user can commit to a value for the transaction fee, publicly post this commitment, the fee payer (aka paymaster) can update the public commitment, deducting the final cost of the transaction from the commitment and returning the unused value to the user.

So, in general, the user is:

- doing some computation in private
- encrypting/compressing that computation with a point
- passing that point as an argument to a public function

And the fee payer is:
And the paymaster is:

- updating that point in public
- treating/emitting the result(s) as a note hash(es)
Expand All @@ -32,6 +32,20 @@ To do this, we leverage the following properties of elliptic curve operations:

Property 1 allows us to be continually adding to a point on elliptic curve and property 2 allows us to pass the point to a public realm without revealing anything about the point preimage.

### DEXes

Currently private swaps require 2 transactions. One to start the swap and another to claim the swapped token from the DEX. With partial notes, you can create a note with zero value for the received amount and have another party complete it later from a public function, with the final swapped amount. This reduces the number of transactions needed to swap privately.

Comparing to the flow above, the user is doing some private computation to stage the swap, encrypting the computation with a point and passing the point as an argument to a public function. Then another party is updating that point in public and emitting the result as a note hash for the user doing the swap.

### Lending

A similar pattern can be used for a lending protocol. The user can deposit a certain amount of a token to the lending contract and create a partial note for the borrowed token that will be completed by another party. This reduces the number of required transactions from 2 to 1.

### Private Refunds

Private transaction refunds from paymasters are the original inspiration for partial notes. Without partial notes, you have to claim your refund note. But the act of claiming itself needs gas! What if you overpaid fees on the refund tx? Then you have another 2nd order refund that you need to claim. This creates a never ending cycle! Partial notes allow paymasters to refund users without the user needing to claim the refund.

Before getting to partial notes let's recap what is the flow of standard notes.

## Note lifecycle recap
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ You need two global dependencies in your machine:
Run:

```bash
bash -i <(curl -s install.aztec.network)
bash -i <(curl -s https://install.aztec.network)
```

This will install the following tools:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,34 @@ tags: [accounts, keys]

## Introduction

It is possible for users to rotate their keys, which can be helpful if some of their keys are leaked.
It is possible for users to rotate their keys, which can be helpful if some of their keys are leaked. Key rotation allows users to continue using the same account without having to create a new one.

Because of this, notes are associated with their `nullifier key` rather than any sort of 'owner' address.
Because of this, notes are often associated with their `nullifier key` (through a nullifier public key hash, often called `npk_m_hash`) rather than any sort of 'owner' address.

It is still possible to nullify the notes with the old nullifier key even after the key rotation.

## `TokenNote` example

See the structure of the `TokenNote` below:

#include_code TokenNote noir-projects/noir-contracts/contracts/token_contract/src/types/token_note.nr rust

In the `TokenNote` type, you can see that the nullifer computation gets the nullifier secret key specific to the contract from the PXE, based on the stored `npk_m_hash`, so a `TokenNote` is not inherently or permanently linked to a specific Aztec account.

#include_code nullifier noir-projects/noir-contracts/contracts/token_contract/src/types/token_note.nr rust

## Things to consider

- 'Owner' is arbitrary - as long as you know the nullifier secret, you can nullify a note
- Consider how key rotation can affect account contracts, eg you can add additional security checks for who or how the key rotation is called
- When using the `npk_m_hash`, used to represent ownership, whoever has the nullifier secret can nullify a note.
- Consider how key rotation can affect account contracts, e.g. you can add additional security checks for who or how the key rotation is called

## Resources

- End to end tests for key rotation can be found [here](https://github.com/AztecProtocol/aztec-packages/blob/#include_aztec_version/yarn-project/end-to-end/src/e2e_key_rotation.test.ts)

## Glossary

- `npk_m_hash`: master nullifying public key hash
- `nsk_app`: app nullifying secret key - the app-specific NSK (learn more about app-scoped keys [here](../../../../../aztec/concepts/accounts/keys.md#scoped-keys))
- `nsk_hash`: nullifying secret key hash
- `ivpk_m`: incoming view public key (master) (learn more about IVPKs [here](../../../../../aztec/concepts/accounts/keys.md#incoming-viewing-keys))
- `ivpk_m`: incoming view public key (master) (learn more about IVPKs [here](../../../../../aztec/concepts/accounts/keys.md#incoming-viewing-keys))
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,7 @@ Aztec.nr enables smart contract developers to design custom notes, meaning devel

## Unencrypted Events

Unencrypted events are events which can be read by anyone.
They can be emitted by both public and private functions.

:::danger

- Emitting unencrypted events from private function is a significant privacy leak and it should be considered by the developer whether it is acceptable.

:::
Unencrypted events are events which can be read by anyone. They can be emitted **only** by public functions.

### Call emit_unencrypted_log

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ trait OwnedNote {
global TOKEN_NOTE_LEN: Field = 3; // 3 plus a header.
global TOKEN_NOTE_BYTES_LEN: Field = 3 * 32 + 64;

// docs:start:TokenNote
#[aztec(note)]
struct TokenNote {
// The amount of tokens in the note
Expand All @@ -27,6 +28,7 @@ struct TokenNote {
// Randomness of the note to hide its contents
randomness: Field,
}
// docs:end:TokenNote

impl NoteInterface<TOKEN_NOTE_LEN, TOKEN_NOTE_BYTES_LEN> for TokenNote {
// docs:start:nullifier
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ The Aztec CLI `aztec-cli` is a command-line interface (CLI) tool for interacting
1. In your terminal, download the sandbox by running

```
bash -i <(curl -s install.aztec.network)
bash -i <(curl -s https://install.aztec.network)
```

2. Verify the installation: After the installation is complete, run the following command to verify that `aztec-cli` is installed correctly:
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/end-to-end/src/sample-dapp/connect.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ const { PXE_URL = 'http://localhost:8080' } = process.env;

async function main() {
const pxe = createPXEClient(PXE_URL);
const { chainId } = await pxe.getNodeInfo();
console.log(`Connected to chain ${chainId}`);
const { l1ChainId } = await pxe.getNodeInfo();
console.log(`Connected to chain ${l1ChainId}`);
}

main().catch(err => {
Expand Down

0 comments on commit ad73f30

Please sign in to comment.