Skip to content

Commit 2299046

Browse files
committing some more changes
1 parent dec8968 commit 2299046

File tree

7 files changed

+66
-52
lines changed

7 files changed

+66
-52
lines changed

.vscode/settings.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{
22
"cSpell.words": [
3-
"Miden"
3+
"Merkle",
4+
"Miden",
5+
"rollups"
46
]
57
}

docs/miden/architecture/accounts.md

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,33 @@ The diagram below illustrates basic components of an account. In Miden every acc
1010

1111
In the above picture, you can see:
1212

13-
* **Account ID →** a unique identifier of an account which does not change throughout its lifetime
14-
* **Storage →** user-defined data which can be stored in an account
15-
* **Nonce →** a counter which must be incremented whenever the account state changes
16-
* **Vault →** a collection of assets stored in an account
17-
* **Code →** a collection of functions which define the external interface for an account
13+
* **Account ID →** a unique identifier of an account which does not change throughout its lifetime.
14+
* **Storage →** user-defined data which can be stored in an account.
15+
* **Nonce →** a counter which must be incremented whenever the account state changes.
16+
* **Vault →** a collection of assets stored in an account.
17+
* **Code →** a collection of functions which define the external interface for an account.
1818

1919
### Account ID
20-
~63 bits (1 field element) long identifier for the account. The four most significant bits specify its [account type](https://0xpolygonmiden.github.io/miden-base/architecture/accounts.html#account-types) - regular, immutable, faucet - and the [storage mode](https://0xpolygonmiden.github.io/miden-base/architecture/accounts.html#account-storage-modes) - public or private.
2120

22-
### Account Storage
21+
~63 bits (1 field element) long identifier for the account. The four most significant bits specify its [account type](accounts.md#account-types) - regular, immutable, faucet - and the [storage mode](accounts.md#account-storage-modes) - public or private.
22+
23+
### Account storage
24+
2325
Storage for user-defined data. `AccountStorage` is composed of two components.
2426

2527
The first component is a simple sparse Merkle tree of depth `8` which is index addressable. This provides the user with `256` `Word` slots.
2628

2729
Users requiring additional storage can use the second component a `MerkleStore`. It allows users to store any Merkle structures they need. The root of the Merkle structure can be stored as a leaf in a simple sparse Merkle tree. When `AccountStorage` is serialized it will check if any of the leafs in the simple sparse Merkle tree are Merkle roots of other Merkle structures. If any Merkle roots are found then the Merkle structures will be persisted in the `AccountStorage` `MerkleStore`.
2830

2931
### Nonce
32+
3033
Counter which must be incremented whenever the account state changes. Nonce values must be strictly monotonically increasing and can be incremented by any value smaller than 2^{32} for every account update.
3134

3235
### Vault
36+
3337
Asset container for an account.
3438

35-
An account vault can contain an unlimited number of [assets](https://0xpolygonmiden.github.io/miden-base/architecture/assets.html). The assets are stored in a sparse
39+
An account vault can contain an unlimited number of [assets](assets.md). The assets are stored in a sparse
3640
Merkle tree as follows:
3741

3842
* For fungible assets, the index of a node is defined by the issuing faucet ID, and the value
@@ -44,28 +48,31 @@ Merkle tree as follows:
4448
An account vault can be reduced to a single hash which is the root of the sparse Merkle tree.
4549

4650
### Code
51+
4752
Interface for accounts. In Miden every account is a smart contract. It has an interface that exposes functions that can be called by note scripts. Functions exposed by the account have the following properties:
4853

4954
* Functions are actually roots of [Miden program MASTs](https://0xpolygonmiden.github.io/miden-vm/user_docs/assembly/main.html) (i.e., a 32-byte hash). Thus, function identifier is a commitment to the code which is executed when a function is invoked.
5055
* Only account functions have mutable access to an account's storage and vault. Therefore, the only way to modify an account's internal state is through one of the account's functions.
5156
* Account functions can take parameters and can create new notes.
5257

53-
*Note: Since code in Miden is expresed as MAST, every function is a commitment to the underlying code. The code cannot change unnoticed to the user because its hash would change. Behind any MAST root there can only be `256` functions*
58+
!!! note
59+
Since code in Miden is expressed as MAST, every function is a commitment to the underlying code. The code cannot change unnoticed to the user because its hash would change. Behind any MAST root there can only be `256` functions*
5460

5561
## Account creation
56-
For an account to exist it must be present in the [Account DB](https://0xpolygonmiden.github.io/miden-base/architecture/state.html#account-database) kept by the Miden Node(s). However, new accounts can be created locally by users using a wallet.
5762

58-
The process is as follows:
63+
For an account to exist it must be present in the [Account DB](state.md#account-database) kept by the Miden Node(s). However, new accounts can be created locally by users using a wallet.
5964

60-
* Alice grinds a new Account ID (according to the account types) using a wallet
61-
* Alice's Miden Client requests the Miden Node to check if new Account ID already exists
62-
* Alice shares the new Account ID to Bob (eg. when Alice wants to receive funds)
63-
* Bob executes a transaction and creates a note that contains an asset for Alice
64-
* Alice consumes Bob's note to receive the asset in a transaction
65-
* Depending on the account storage mode (private vs. public) and transaction type (local vs. network) the Operator receives the new Account ID eventually and - if the transaction is correct - adds the ID to the Account DB
65+
The process is as follows:
6666

67+
* Alice grinds a new Account ID (according to the account types) using a wallet.
68+
* Alice's Miden Client requests the Miden Node to check if new Account ID already exists.
69+
* Alice shares the new Account ID to Bob (eg. when Alice wants to receive funds).
70+
* Bob executes a transaction and creates a note that contains an asset for Alice.
71+
* Alice consumes Bob's note to receive the asset in a transaction.
72+
* Depending on the account storage mode (private vs. public) and transaction type (local vs. network) the Operator receives the new Account ID eventually and - if the transaction is correct - adds the ID to the Account DB.
6773

6874
## Account types
75+
6976
There are four types of accounts in Miden:
7077

7178
| | Regular updatable account | Regular immutable account | Faucet for fungible assets | Faucet for non-fungible assets |
@@ -75,7 +82,8 @@ There are four types of accounts in Miden:
7582
| **Most significant bits** | `00` | `01` | `10` | `11` |
7683

7784
## Account storage mode
78-
Account data - stored by the Miden Node - can be public, private, or encrypted. The third and fourth most significant bits of the account ID specifies whether the account data is public `00`, encrypted `01`, or private `11`.
85+
86+
Account data - stored by the Miden node - can be public, private, or encrypted. The third and fourth most significant bits of the account ID specifies whether the account data is public `00`, encrypted `01`, or private `11`.
7987

8088
* Accounts with **public state**, where the actual state is stored onchain. These would be similar to how accounts work in public blockchains. Smart contracts that depend on public shared state should be stored public on Miden, e.g., DEX contract.
8189
* Accounts with **private state**, where only the hash of the account is stored onchain. Users who want stay private and take care of their own data should choose this mode. The hash is defined as: `hash([account ID, 0, 0, nonce], [vault root], [storage root], [code root])`.

docs/miden/architecture/assets.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Native assets are data structures that follow the Miden asset model (encoding, i
1717

1818
### Issuance
1919

20-
Only specialized accounts called faucets can issue assets. Just like with regular accounts, anyone can create a faucet account. Faucets can issue only either fungible or non-fungible assets - but not both. The `faucet_id` identifies the faucet and is starts with a different sequence depending on the asset type, see [here](./accounts/#account-id). The faucet's code defines rules for how assets can be minted, who can mint them etc. Conceptually, faucet accounts on Miden are similar to ERC20 contracts on Ethereum. But, there is no ownership tracking in Miden faucets.
20+
Only specialized accounts called faucets can issue assets. Just like with regular accounts, anyone can create a faucet account. Faucets can issue only either fungible or non-fungible assets - but not both. The `faucet_id` identifies the faucet and is starts with a different sequence depending on the asset type, see [here](accounts.md/#account-id). The faucet's code defines rules for how assets can be minted, who can mint them etc. Conceptually, faucet accounts on Miden are similar to ERC20 contracts on Ethereum. But, there is no ownership tracking in Miden faucets.
2121

2222
Faucets can create assets and immediately distribute them by producing notes. However, assets can also stay in the faucet after creation to be sent later, e.g., in a bundle. That way, one can mint a million NFTs locally in a single transaction and then send them out as needed in separate transactions in the future.
2323

@@ -39,7 +39,7 @@ Examples of non-fungible assets are all NFTs, e.g., a DevCon ticket. The ticket'
3939

4040
### Storage
4141

42-
[Accounts](./accounts) and [notes](./notes) contain asset vaults that are used to store assets. Accounts can keep unlimited assets in a [tiered sparse Merkle tree](../crypto-primitives/tsmt) called `account vault`. Notes can only store up to `255` distinct assets.
42+
[Accounts](accounts.md) and [notes](notes.md) contain asset vaults that are used to store assets. Accounts can keep unlimited assets in a [tiered sparse Merkle tree](../crypto-primitives/tsmt.md) called `account vault`. Notes can only store up to `255` distinct assets.
4343

4444
<center>
4545
![Asset storage](../../img/miden/architecture/asset/asset_storage.png){ width="50%" }

docs/miden/architecture/execution.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Polygon Miden is an Ethereum rollup. It batches transactions - or more precisely
88

99
Every transaction will result in a zkProof that attests to its correctness.
1010

11-
As mentioned in [transactions](./transactions), there are two types of transactions: local and network. For every transaction there is a proof which is either created by the user in the Miden Client or by the Operator using the Miden Node.
11+
As mentioned in [transactions](transactions.md), there are two types of transactions: local and network. For every transaction there is a proof which is either created by the user in the Miden Client or by the Operator using the Miden Node.
1212

1313
## Transaction batching
1414

@@ -37,6 +37,7 @@ A block produced by the Miden Node looks somewhat like this:
3737
* The block also contains full account and note data for public accounts and notes. For example, if account `123` is a public account which was updated, in the state updates section we'd have a records for it as `(123, 0x456..)`. The full new state of this account (which should hash to `0x456..`) would be included in a separate section.
3838

3939
To verify that a block describes a valid state transition, we do the following:
40+
4041
1. Compute hashes of public account and note states.
4142
2. Make sure these hashes match records in the *state updates* section.
4243
3. Verify the included ZKP against the following public inputs:

docs/miden/architecture/notes.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Asset container for a note. A note vault can contain up to `255` assets stored i
2121

2222
### Script
2323

24-
Unlike an account, a note has a single executable script. This script will be executed in a [transaction](./transactions). This script is also the root of a [Miden program MAST](https://0xpolygonmiden.github.io/miden-vm/user_docs/assembly/main.html). A script is always executed in the context of a single account, and thus, may invoke account's functions. A note's script can call zero or more of an account's function.
24+
Unlike an account, a note has a single executable script. This script will be executed in a [transaction](transactions.md). This script is also the root of a [Miden program MAST](https://0xpolygonmiden.github.io/miden-vm/user_docs/assembly/main.html). A script is always executed in the context of a single account, and thus, may invoke account's functions. A note's script can call zero or more of an account's function.
2525

2626
!!! note
2727
Since code in Miden is expressed as MAST, every function is a commitment to the underlying code. The code cannot change unnoticed to the user because its hash would change.*
@@ -44,7 +44,7 @@ For every note the Miden operator stores metadata in the note DB. This metadata
4444

4545
## Note storage modes
4646

47-
Similar to accounts, there are two storage modes for notes in Miden. Notes can be stored privately in the [Notes DB](./state/#note-database) with only the note hash. Or notes can be stored publicly with all data.
47+
Similar to accounts, there are two storage modes for notes in Miden. Notes can be stored privately in the [Notes DB](state.md/#note-database) with only the note hash. Or notes can be stored publicly with all data.
4848

4949
Privately stored notes can only be consumed if the note data is known to the consumer. That means, there must be some off-chain communication to transmit the note's data from the sender to the recipient.
5050

@@ -65,7 +65,7 @@ the VM.
6565

6666
## Note nullifier
6767

68-
The nullifier is the note's index in the [Nullifier DB](./notes/#note-nullifier). The Nullifier DB stores the information whether a note was already consumed.
68+
The nullifier is the note's index in the [Nullifier DB](notes.md/#note-nullifier). The Nullifier DB stores the information whether a note was already consumed.
6969

7070
The nullifier is computed as `hash(serial_num, script_hash, input_hash, vault_hash)`.
7171

@@ -83,14 +83,14 @@ To know a note’s nullifier, one needs to know all details of the note. That me
8383

8484
## Note lifecycle
8585

86-
For a note to exist it must be present in the [Notes DB](./state/#note-database) kept by the Miden node(s). New notes are being produced when executing a transaction. They can be produced locally by users in local transactions or by the operator in a network transaction.
86+
For a note to exist it must be present in the [Notes DB](state.md/#note-database) kept by the Miden node(s). New notes are being produced when executing a transaction. They can be produced locally by users in local transactions or by the operator in a network transaction.
8787

88-
The lifcycle of a note is as follows:
88+
The life-cycle of a note is as follows:
8989

90-
* A new note is produced when a transaction is executed - regardless of the transaction type
91-
* Operator will receive the note hash and if the note is public, it'll also receive the corresponding note's data
92-
* Operator verifies the correctness of the underlying transaction before adding the note hash to the Notes DB
93-
* The note can now be consumed in a seperate transaction - to consume the note, the note's data must be known
94-
* A note is consumed when the its nullifier in the [Nullifier DB](./state/#nullifier-database) is set to `1`
95-
* Operator will receive the note's nullifier together with a transaction proof
96-
* After successful verification, the Operator sets the corresponding entry in the Nullifier DB to `1`
90+
* A new note is produced when a transaction is executed - regardless of the transaction type.
91+
* Operator will receive the note hash and if the note is public, it'll also receive the corresponding note's data.
92+
* Operator verifies the correctness of the underlying transaction before adding the note hash to the Notes DB.
93+
* The note can now be consumed in a separate transaction - to consume the note, the note's data must be known.
94+
* A note is consumed when the its nullifier in the [Nullifier DB](state.md/#nullifier-database) is set to `1`.
95+
* Operator will receive the note's nullifier together with a transaction proof.
96+
* After successful verification, the Operator sets the corresponding entry in the Nullifier DB to `1`.

0 commit comments

Comments
 (0)