Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Onchain notes tutorial #604

Merged
merged 14 commits into from
Apr 26, 2024
Merged
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# Changelog

<<<<<<< HEAD
## 0.3.0 (TBD)
=======
## 0.2.2 (2024-04-23) - `miden-tx` crate only

* Added `with_debug_mode()` methods to `TransactionCompiler` and `TransactionExecutor` (#562).
>>>>>>> 1fb0ac6ce25f060645131e8614164ff942d14fb5

## 0.2.1 (2024-04-12)

Expand Down
10 changes: 7 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 7 additions & 5 deletions docs/introduction/get-started/create-account-use-faucet.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ The Miden client facilitates interaction with the Miden rollup and provides a wa
!!! tip
Check the [Miden client documentation](https://docs.polygon.technology/miden/miden-client/cli-reference/) for more information.

1. Clone the Miden client.
1. If you haven't already done so as part of another instruction set, clone the Miden client.

```shell
git clone https://github.com/0xPolygonMiden/miden-client
Expand Down Expand Up @@ -65,11 +65,11 @@ Save the account ID for a future step.

## Request tokens from the public faucet

1. To request funds from the faucet navigate to the following website: [Miden faucet website](https://ethdenver.polygonmiden.io/).
1. To request funds from the faucet navigate to the following website: [Miden faucet website](https://testnet.miden.io/).

2. Copy the **Account ID** printed by the `miden-client account -l` command in the previous step.

3. Paste this id into the **Request test POL tokens** input field on the faucet website and click **Send me 100 tokens!**.
3. Paste this id into the **Request test POL tokens** input field on the faucet website and click **Send me 333 tokens!**.

4. After a few seconds your browser should download - or prompt you to download - a file called `note.mno` (mno = Miden note). It contains the funds the faucet sent to your address.

Expand All @@ -80,7 +80,7 @@ Save the account ID for a future step.
1. Import the note that you have received using the following commands:

```shell
miden-client input-notes -i <path-to-note>
miden-client input-notes -i <path-to-note>/note.mno
```

2. You should see something like this:
Expand Down Expand Up @@ -145,7 +145,9 @@ State synced to block 179672
```

!!! tip
- You only need to use the first 7 characters of the Note-Id.
You only need to copy the top line of characters of the Note ID.

## View confirmations

5. View your updated account's vault containing the tokens sent by the faucet by running the following command:

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
In this section, we show you how to make off-chain transactions and send funds to another account using the Miden client.

!!! important "Prerequisite steps"
- You should have already followed all previous sections.
- You should have *not* reset the state of your local client.
- You should have already followed the [prerequisite steps](prerequisites.md) and [get started](create-account-use-faucet.md) documents.
- You should *not* have reset the state of your local client.

## Create a second account

Expand Down Expand Up @@ -32,7 +32,7 @@ In this section, we show you how to make off-chain transactions and send funds t
To do this, run:

```shell
miden-client tx new p2id <regular-account-id-A> <regular-account-id-B> <faucet-account-id> 50
miden-client tx new p2id <regular-account-id-A> <regular-account-id-B> <faucet-account-id> 50 --note-type private
```

!!! note
Expand All @@ -55,34 +55,32 @@ In this section, we show you how to make off-chain transactions and send funds t
4. Have the second account consume the note.

```sh
miden-client tx new consume-notes <regular-account-ID-B> <input-note-id>
miden-client tx new consume-notes <regular-account-ID-B> <input-note-id>
```

!!! tip
It's possible to use a short version of the note id: 7 characters after the `0x` is sufficient.

That's it!
You should now see both accounts containing faucet assets with half the amount transferred from `Account A` to `Account B`.

You should now see both accounts containing faucet assets with half the amount transferred from `Account A` to `Account B`.

!!! tip
Remember. The original amount was 100 POL.
!!! tip
Remember. The original amount was 100 POL.

Check the second account:
5. Check the second account:

```shell
miden-client account show <regular-account-ID-B> -v # Show account B's vault assets (50 fungible tokens)
```
```shell
miden-client account show <regular-account-ID-B> -v # Show account B's vault assets (50 fungible tokens)
```

![Result of listing miden accounts](../../img/get-started/account-b.png)
![Result of listing miden accounts](../../img/get-started/account-b.png)

Check the original account:
6. Check the original account:

```sh
miden-client account show <regular-account-ID-A> -v # Show account A's vault assets (950 fungible tokens)
```
```sh
miden-client account show <regular-account-ID-A> -v # Show account A's vault assets (950 fungible tokens)
```

![Result of listing miden accounts](../../img/get-started/account-a.png)
![Result of listing miden accounts](../../img/get-started/account-a.png)

## Clear state

Expand All @@ -94,7 +92,8 @@ To clear all state, delete this file. It recreates on any command execution.

You have successfully configured and used the Miden client to interact with a Miden rollup and faucet.

You have performed basic Miden rollup operations like sending transactions, generating and consuming notes.
You have performed basic Miden rollup operations like submitting proofs of transactions, generating and consuming notes.

For more information on the Miden client, refer to the [Miden client documentation](https://docs.polygon.technology/miden/miden-client/).

</br>
97 changes: 97 additions & 0 deletions docs/introduction/get-started/p2p-public.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
In this section, we show you how to execute transactions and send funds to another account using the Miden client and [public notes](https://docs.polygon.technology/miden/miden-base/architecture/notes/#note-storage-mode).

!!! important "Prerequisite steps"
- You should have already followed the [prerequisite steps](prerequisites.md) and [get started](create-account-use-faucet.md) documents.
- You should have *not* reset the state of your local client.

## Create a second client

!!! tip
Remember to use the [Miden client documentation](https://docs.polygon.technology/miden/miden-client/cli-reference/) for clarifications.

This is an alternative to the [private off-chain P2P transactions](p2p-private.md) process.

In this tutorial, we use two different clients to simulate two different remote users who don't share local state.

To do this, we use two terminals with their own state (using their own `miden-client.toml`).

1. Create a new directory to store the new client.

```sh
mkdir miden-client-2
cd miden-client-2
```

2. Initialize the client. This creates the `miden-client.toml` file line-by-line.

```sh
miden-client init
```

Accept the defaults for `Protocol`, `Node RPC Port`, and `Sqlite file path`by clicking enter.

When `Host` comes up, enter the IP that the Miden team supplies:

```sh
Host (default: localhost): xxx.xxx.xxx.xxx
```

3. On the new client, create a new [basic account](https://docs.polygon.technology/miden/miden-base/architecture/accounts/#account-types):

```shell
miden-client account new basic-mutable -s on-chain
```

We refer to this account as _Account B_. Note that we set the account's storage mode to `on-chain`, which means that the account details will be public and its latest state can be retrieved from the node.

4. List and view the account with the following command:

```shell
miden-client account -l
```

## Transfer assets between accounts

1. Now we can transfer some of the tokens we received from the faucet to our new account B.

To do this, from the first client run:

```shell
miden-client tx new p2id <basic-account-id-A> <basic-account-id-B> <faucet-account-id> 50 --note-type public
```

!!! note
The faucet account id can be found on the [Miden faucet website](https://testnet.miden.io/) under the title **Miden faucet**.

This generates a Pay-to-ID (`P2ID`) note containing `<amount>` assets, transferred from one account to the other. As the note is public, the second account can receive the necessary details by syncing with the node.

2. First, sync the account on the new client.

```shell
miden-client sync # Make sure we have an updated view of the state
```

3. At this point, we should have received the public note details.

```sh
miden-client input-notes list
```

Because the note was retrieved from the node, the commit height will be included and displayed.

4. Have the second account consume the note.

```sh
miden-client tx new consume-notes <regular-account-ID-B> <input-note-id>
```

!!! tip
It's possible to use a short version of the note id: 7 characters after the `0x` is sufficient.

That's it!

The second account will have now consumed the note and should have new assets in the account:

```sh
miden-client account show <account-ID> -v
```
4 changes: 3 additions & 1 deletion docs/introduction/get-started/prerequisites.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ Get the IP address of the running Miden node by contacting one of the Miden engi

### Miden client

Install the [Miden client](https://docs.polygon.technology/miden/miden-client/install-and-run/).
Install the [Miden client](https://docs.polygon.technology/miden/miden-client/install-and-run/).

</br>
6 changes: 3 additions & 3 deletions miden-lib/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "miden-lib"
version = "0.2.1"
version = "0.3.0"
description = "Standard library of the Miden rollup"
readme = "README.md"
categories = ["no-std"]
Expand Down Expand Up @@ -30,11 +30,11 @@ std = [
testing = ["miden-objects/testing"]

[dependencies]
miden-objects = { package = "miden-objects", path = "../objects", version = "0.2", default-features = false }
miden-objects = { package = "miden-objects", path = "../objects", version = "0.3", default-features = false }
miden-stdlib = { workspace = true }

[dev-dependencies]
miden-objects = { package = "miden-objects", path = "../objects", version = "0.2", default-features = false, features = [
miden-objects = { package = "miden-objects", path = "../objects", version = "0.3", default-features = false, features = [
"testing",
] }
mock = { package = "miden-mock", path = "../mock", default-features = false }
Expand Down
6 changes: 3 additions & 3 deletions miden-tx/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "miden-tx"
version = "0.2.2"
version = "0.3.0"
description = "Miden rollup transaction compiler, executor, and prover"
readme = "README.md"
categories = ["no-std"]
Expand All @@ -22,8 +22,8 @@ default = ["std"]
std = ["miden-lib/std", "miden-objects/std", "miden-prover/std", "miden-verifier/std", "vm-processor/std"]

[dependencies]
miden-lib = { package = "miden-lib", path = "../miden-lib", version = "0.2", default-features = false }
miden-objects = { package = "miden-objects", path = "../objects", version = "0.2", default-features = false }
miden-lib = { package = "miden-lib", path = "../miden-lib", version = "0.3", default-features = false }
miden-objects = { package = "miden-objects", path = "../objects", version = "0.3", default-features = false }
miden-prover = { workspace = true }
miden-verifier = { workspace = true }
vm-processor = { workspace = true }
Expand Down
6 changes: 3 additions & 3 deletions miden-tx/src/executor/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use alloc::vec::Vec;
use alloc::{rc::Rc, vec::Vec};

use miden_lib::transaction::{ToTransactionKernelInputs, TransactionKernel};
use miden_objects::{
Expand Down Expand Up @@ -35,7 +35,7 @@ pub use data::DataStore;
/// executor and produces an [ExecutedTransaction] for the transaction. The executed transaction
/// can then be used to by the prover to generate a proof transaction execution.
pub struct TransactionExecutor<D: DataStore> {
data_store: D,
data_store: Rc<D>,
compiler: TransactionCompiler,
exec_options: ExecutionOptions,
}
Expand All @@ -44,7 +44,7 @@ impl<D: DataStore> TransactionExecutor<D> {
// CONSTRUCTOR
// --------------------------------------------------------------------------------------------
/// Creates a new [TransactionExecutor] instance with the specified [DataStore].
pub fn new(data_store: D) -> Self {
pub fn new(data_store: Rc<D>) -> Self {
Self {
data_store,
compiler: TransactionCompiler::new(),
Expand Down
10 changes: 5 additions & 5 deletions miden-tx/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use alloc::vec::Vec;
use alloc::{sync::Arc, vec::Vec};

use miden_lib::transaction::{ToTransactionKernelInputs, TransactionKernel};
use miden_objects::{
Expand Down Expand Up @@ -43,7 +43,7 @@ use super::{

#[test]
fn transaction_executor_witness() {
let data_store = MockDataStore::default();
let data_store = Arc::new(MockDataStore::default());
let mut executor = TransactionExecutor::new(data_store.clone());

let account_id = data_store.account.id();
Expand Down Expand Up @@ -80,7 +80,7 @@ fn transaction_executor_witness() {

#[test]
fn executed_transaction_account_delta() {
let data_store = MockDataStore::new(AssetPreservationStatus::PreservedWithAccountVaultDelta);
let data_store = Arc::new(MockDataStore::new(AssetPreservationStatus::PreservedWithAccountVaultDelta));
let mut executor = TransactionExecutor::new(data_store.clone());
let account_id = data_store.account.id();
executor.load_account(account_id).unwrap();
Expand Down Expand Up @@ -276,7 +276,7 @@ fn executed_transaction_account_delta() {

#[test]
fn prove_witness_and_verify() {
let data_store = MockDataStore::default();
let data_store = Arc::new(MockDataStore::default());
let mut executor = TransactionExecutor::new(data_store.clone());

let account_id = data_store.account.id();
Expand Down Expand Up @@ -305,7 +305,7 @@ fn prove_witness_and_verify() {

#[test]
fn test_tx_script() {
let data_store = MockDataStore::default();
let data_store = Arc::new(MockDataStore::default());
let mut executor = TransactionExecutor::new(data_store.clone());

let account_id = data_store.account.id();
Expand Down
Loading