Skip to content

Commit a656034

Browse files
catmcgeecritesjoshrahul-kothari
authored
feat(docs): PXE docs (AztecProtocol#4021)
* explanation * custom oracles how-to * multiple pxe in sandbox how-to --------- Co-authored-by: josh crites <[email protected]> Co-authored-by: Rahul Kothari <[email protected]>
1 parent c051dac commit a656034

7 files changed

Lines changed: 169 additions & 12 deletions

File tree

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
---
2+
title: Private Execution Environment (PXE)
3+
---
4+
5+
The Private Execution Environment (or PXE, pronounced 'pixie') is a client-side library for the execution of private operations. It is a TypeScript library and can be run within Node, such as when you run the sandbox, within the browser, or any other environment in which TypeScript can run. For example, in future it could be run inside wallet software.
6+
7+
The PXE generates proofs of private function execution, and sends these proofs along with public function requests to the sequencer. Private inputs never leave the client-side PXE.
8+
9+
```mermaid
10+
graph TD;
11+
12+
subgraph client[Client]
13+
subgraph pxe [PXE]
14+
acirSim[ACIR Simulator]
15+
db[Database]
16+
keyStore[KeyStore]
17+
end
18+
end
19+
20+
subgraph server[Application Server]
21+
subgraph pxeService [PXE Service]
22+
acctMgmt[Account Management]
23+
contractTxInteract[Contract & Transaction Interactions]
24+
noteMgmt[Note Management]
25+
end
26+
end
27+
28+
pxe -->|interfaces| server
29+
30+
```
31+
32+
## PXE Service
33+
34+
The PXE is a client-side interface of the PXE Service, which is a set of server-side APIs for interacting with the network. It provides functions for account management, contract and transaction interactions, note management, and more. For a more extensive list of operations, refer to the [PXE reference](../../apis/pxe/interfaces/PXE.md).
35+
36+
## Components
37+
38+
### ACIR simulator
39+
40+
The ACIR (Abstract Circuit Intermediate Representation) simulator handles the accurate execution of smart contract functions by simulating transactions. It generates the required data and inputs for these functions. You can find more details about how it works [here](./acir_simulator.md).
41+
42+
### Database
43+
44+
The database stores transactional data and notes within the user's PXE. In the Aztec protocol, the database is implemented as a key-value database backed by LMDB. There is an interface ([GitHub](https://github.com/AztecProtocol/aztec-packages/blob/ca8b5d9dbff8d8062dbf1cb1bd39d93a4a636e86/yarn-project/pxe/src/database/pxe_database.ts)) for this PXE database that can be implemented in other ways, such as an in-memory database that can be used for testing.
45+
46+
The database stores various types of data, including:
47+
48+
- **Notes**: Encrypted representations of assets.
49+
- **Deferred Notes**: Notes that are intended for a user but cannot yet be decoded due to the associated contract not being present in the database. When new contracts are deployed, there may be some time before it is accessible from the PXE database. When the PXE database is updated, deferred note are decoded.
50+
- **Authentication Witnesses**: Data used to approve others from executing transactions on your behalf
51+
- **Capsules**: External data or data injected into the system via [oracles](#oracles).
52+
53+
### Note discovery
54+
55+
There is an open RFP for how note discovery will work on Aztec. You can find more information in the [forum](https://forum.aztec.network/t/request-for-proposals-note-discovery-protocol/2584).
56+
57+
Currently in the Aztec sandbox, users download every note, compute a secret, and generate the symmetric decryption key from that secret. If the note belongs to them, then the user will have derived the same secret and ultimately the required decryption key.
58+
59+
### Keystore
60+
61+
The keystore is a secure storage for private and public keys.
62+
63+
## Oracles
64+
65+
Oracles are pieces of data that are injected into a smart contract function from the client side. You can read more about why and how they work in the [functions section](../../dev_docs/contracts/syntax/functions.md).
66+
67+
## For developers
68+
To learn how to develop on top of the PXE, refer to these guides:
69+
* [Run more than one PXE on your local machine](../../dev_docs/cli/run_more_than_one_pxe_sandbox.md)
70+
* [Use in-built oracles including oracles for arbitrary data](../../dev_docs/contracts/syntax/oracles.md)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
title: How to run more than one PXE in the sandbox
3+
---
4+
5+
When you run the sandbox, the Aztec node and PXE have their own http server. This makes it possible to run two PXEs on your local machine, which can be useful for testing that notes are accurately stored and remaining private in their respective PXEs.
6+
7+
We are working on a better solution for this so expect an update soon, but currently you can follow this guide.
8+
9+
## Run the sandbox in one terminal
10+
11+
Rather than use the usual command, run:
12+
```bash
13+
cd ~/.aztec && docker-compose up
14+
```
15+
This removes any other arguments, allowing you to ensure an isolated environment for the sandbox so it doesn't interfere with another PXE.
16+
17+
## Run PXE mode in another terminal
18+
19+
In another terminal, run:
20+
21+
```bash
22+
docker-compose run -e MODE=pxe -e PXE_PORT=8085 -e AZTEC_NODE_URL='http://aztec-aztec-1:8079' -e TEST_ACCOUNTS='false' -p 8085:8085 aztec
23+
```
24+
This does a few things:
25+
* Starts in PXE mode
26+
* Passes the current Aztec node URL
27+
* Does not load new test accounts
28+
* Sets a port to listen on
29+
* Only runs Aztec PXE, not Ethereum
30+
31+
This command uses the default ports, so they might need to be changed depending on yuor configuration.
32+
33+
You can learn more about custom commands in the [sandbox reference](./sandbox-reference.md).
34+
35+

docs/docs/dev_docs/contracts/syntax/functions.md

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ On this page, you’ll learn more about:
1212
- How constructors work and remain private
1313
- The process of calling functions from within the same smart contract and from different contracts, including calling private functions from private functions, public from public, and even private from public
1414
- What oracles and how Aztec smart contracts might use them
15-
- Built-in oracles
1615

1716
## Visibility
1817

@@ -109,15 +108,7 @@ Oracles introduce **non-determinism** into a circuit, and thus are `unconstraine
109108
`Aztec.nr` has a module dedicated to its oracles. If you are interested, you can view them by following the link below:
110109
#include_code oracles-module /yarn-project/aztec-nr/aztec/src/oracle.nr rust
111110

112-
### A few useful inbuilt oracles
113-
114-
- [`debug_log`](https://github.com/AztecProtocol/aztec-packages/blob/master/yarn-project/aztec-nr/aztec/src/oracle/debug_log.nr) - Provides a couple of debug functions that can be used to log information to the console.
115-
- [`auth_witness`](https://github.com/AztecProtocol/aztec-packages/blob/master/yarn-project/aztec-nr/authwit/src/auth_witness.nr) - Provides a way to fetch the authentication witness for a given address. This is useful when building account contracts to support approve-like functionality.
116-
- [`get_l1_to_l2_message`](https://github.com/AztecProtocol/aztec-packages/blob/master/yarn-project/aztec-nr/aztec/src/oracle/get_l1_to_l2_message.nr) - Useful for application that receive messages from L1 to be consumed on L2, such as token bridges or other cross-chain applications.
117-
- [`notes`](https://github.com/AztecProtocol/aztec-packages/blob/master/yarn-project/aztec-nr/aztec/src/oracle/notes.nr) - Provides a lot of functions related to notes, such as fetches notes from storage etc, used behind the scenes for value notes and other pre-build note implementations.
118-
- [`logs`](https://github.com/AztecProtocol/aztec-packages/blob/master/yarn-project/aztec-nr/aztec/src/oracle/logs.nr) - Provides the to log encrypted and unencrypted data.
119-
120-
---
111+
You can learn how to use oracles in your smart contracts [here](../syntax/oracles.md).
121112

122113
## Calling functions from other functions
123114

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
title: Oracles
3+
---
4+
5+
On this page you will learn:
6+
7+
1. [A list of inbuilt oracles](#inbuilt-oracles)
8+
3. [How to use the debug_log oracle](#how-to-use-the-debug-oracle)
9+
3. [How to use the auth_witness oracle](#how-to-use-the-auth_witness-oracle)
10+
4. [How to use the pop_capsule oracle for arbitrary data](#how-to-use-the-popCapsule-oracle)
11+
4. [Reference](#oracles-reference)
12+
13+
## Inbuilt oracles
14+
15+
- [`debug_log`](https://github.com/AztecProtocol/aztec-packages/blob/master/yarn-project/aztec-nr/aztec/src/oracle/debug_log.nr) - Provides a couple of debug functions that can be used to log information to the console. Read more about debugging [here](../../debugging/main.md).
16+
- [`auth_witness`](https://github.com/AztecProtocol/aztec-packages/blob/master/yarn-project/aztec-nr/authwit/src/auth_witness.nr) - Provides a way to fetch the authentication witness for a given address. This is useful when building account contracts to support approve-like functionality.
17+
- [`get_l1_to_l2_message`](https://github.com/AztecProtocol/aztec-packages/blob/master/yarn-project/aztec-nr/aztec/src/oracle/get_l1_to_l2_message.nr) - Useful for application that receive messages from L1 to be consumed on L2, such as token bridges or other cross-chain applications.
18+
- [`notes`](https://github.com/AztecProtocol/aztec-packages/blob/master/yarn-project/aztec-nr/aztec/src/oracle/notes.nr) - Provides a lot of functions related to notes, such as fetches notes from storage etc, used behind the scenes for value notes and other pre-build note implementations.
19+
- [`logs`](https://github.com/AztecProtocol/aztec-packages/blob/master/yarn-project/aztec-nr/aztec/src/oracle/logs.nr) - Provides the to log encrypted and unencrypted data.
20+
21+
Find a full list [on GitHub](https://github.com/AztecProtocol/aztec-packages/tree/master/yarn-project/aztec-nr/aztec/src/oracle).
22+
23+
:::note
24+
Please note that it is **not** possible to write a custom oracle for your dapp. Oracles are implemented in the PXE, so all users of your dapp would have to use a PXE service with your custom oracle included. If you want to inject some arbitrary data that does not have a dedicated oracle, you can use [popCapsule](#how-to-use-the-pop_capsule-oracle).
25+
:::
26+
27+
## How to use the popCapsule oracle
28+
29+
`popCapsule` is used for passing artbitrary data. We have not yet included this in Aztec.nr, so it is a bit more complex than the other oracles. You can follow this how-to:
30+
31+
### 1. Define the pop_capsule function
32+
33+
In a new file on the same level as your `main.nr`, implement an unconstrained function that calls the pop_capsule oracle:
34+
35+
#include_code pop_capsule yarn-project/noir-contracts/contracts/slow_tree_contract/src/capsule.nr rust
36+
37+
### 2. Import this into your smart contract
38+
39+
If it lies in the same directory as your smart contract, you can import it like this:
40+
41+
#include_code import_pop_capsule yarn-project/noir-contracts/contracts/slow_tree_contract/src/main.nr rust
42+
43+
### 3. Use it as any other oracle
44+
45+
Now it becomes a regular oracle you can call like this:
46+
47+
#include_code pop_capsule yarn-project/noir-contracts/contracts/slow_tree_contract/src/main.nr rust
48+
49+

docs/sidebars.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ const sidebars = {
188188
},
189189
"concepts/advanced/public_vm",
190190
"concepts/advanced/contract_creation",
191+
"concepts/advanced/private_execution_environment",
191192
"concepts/advanced/sequencer_selection",
192193
"concepts/advanced/acir_simulator",
193194
],
@@ -294,7 +295,11 @@ const sidebars = {
294295
type: "doc",
295296
id: "dev_docs/cli/main",
296297
},
297-
items: ["dev_docs/cli/cli-commands", "dev_docs/cli/sandbox-reference"],
298+
items: [
299+
"dev_docs/cli/cli-commands",
300+
"dev_docs/cli/sandbox-reference",
301+
"dev_docs/cli/run_more_than_one_pxe_sandbox"
302+
],
298303
},
299304
{
300305
label: "Aztec.nr Contracts",
@@ -326,6 +331,7 @@ const sidebars = {
326331
},
327332
"dev_docs/contracts/syntax/events",
328333
"dev_docs/contracts/syntax/functions",
334+
"dev_docs/contracts/syntax/oracles",
329335
{
330336
label: "Proving Historical Blockchain Data",
331337
type: "category",
@@ -430,7 +436,6 @@ const sidebars = {
430436
},
431437
items: ["dev_docs/testing/cheat_codes"],
432438
},
433-
434439
{
435440
label: "Wallets",
436441
type: "category",
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
// docs:start:pop_capsule
12
#[oracle(popCapsule)]
23
fn pop_capsule_oracle<N>() -> [Field; N] {}
34

45
// A capsule is a "blob" of data that is passed to the contract through an oracle.
56
unconstrained pub fn pop_capsule<N>() -> [Field; N] {
67
pop_capsule_oracle()
78
}
9+
// docs:end:pop_capsule
10+

yarn-project/noir-contracts/contracts/slow_tree_contract/src/main.nr

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ contract SlowTree {
3131
SlowMap, Leaf, SlowUpdateProof, compute_merkle_root, deserialize_slow_update_proof
3232
};
3333

34+
// docs:start:import_pop_capsule
3435
use crate::capsule::pop_capsule;
36+
// docs:end:import_pop_capsule
3537
use crate::types::{MembershipProof, deserialize_membership_proof};
3638

3739
// docs:start:constants_and_storage
@@ -84,7 +86,9 @@ contract SlowTree {
8486
// docs:start:read_at_private
8587
#[aztec(private)]
8688
fn read_at(index: Field) -> Field {
89+
// docs:start:pop_capsule
8790
let fields = pop_capsule();
91+
// docs:end:pop_capsule
8892
let p: MembershipProof<TREE_HEIGHT, MEMBERSHIP_SIZE> = deserialize_membership_proof(fields);
8993
assert(index == p.index, "Index does not match expected");
9094

0 commit comments

Comments
 (0)