You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/miden/architecture/accounts.md
+26-18Lines changed: 26 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,29 +10,33 @@ The diagram below illustrates basic components of an account. In Miden every acc
10
10
11
11
In the above picture, you can see:
12
12
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.
18
18
19
19
### 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.
21
20
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
+
23
25
Storage for user-defined data. `AccountStorage` is composed of two components.
24
26
25
27
The first component is a simple sparse Merkle tree of depth `8` which is index addressable. This provides the user with `256``Word` slots.
26
28
27
29
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`.
28
30
29
31
### Nonce
32
+
30
33
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.
31
34
32
35
### Vault
36
+
33
37
Asset container for an account.
34
38
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
36
40
Merkle tree as follows:
37
41
38
42
* 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:
44
48
An account vault can be reduced to a single hash which is the root of the sparse Merkle tree.
45
49
46
50
### Code
51
+
47
52
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:
48
53
49
54
* 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.
50
55
* 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.
51
56
* Account functions can take parameters and can create new notes.
52
57
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*
54
60
55
61
## 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.
57
62
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.
59
64
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:
66
66
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.
67
73
68
74
## Account types
75
+
69
76
There are four types of accounts in Miden:
70
77
71
78
|| 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:
75
82
|**Most significant bits**|`00`|`01`|`10`|`11`|
76
83
77
84
## 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`.
79
87
80
88
* 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.
81
89
* 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])`.
Copy file name to clipboardExpand all lines: docs/miden/architecture/assets.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,7 +17,7 @@ Native assets are data structures that follow the Miden asset model (encoding, i
17
17
18
18
### Issuance
19
19
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.
21
21
22
22
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.
23
23
@@ -39,7 +39,7 @@ Examples of non-fungible assets are all NFTs, e.g., a DevCon ticket. The ticket'
39
39
40
40
### Storage
41
41
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.
Copy file name to clipboardExpand all lines: docs/miden/architecture/execution.md
+2-1Lines changed: 2 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ Polygon Miden is an Ethereum rollup. It batches transactions - or more precisely
8
8
9
9
Every transaction will result in a zkProof that attests to its correctness.
10
10
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.
12
12
13
13
## Transaction batching
14
14
@@ -37,6 +37,7 @@ A block produced by the Miden Node looks somewhat like this:
37
37
* 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.
38
38
39
39
To verify that a block describes a valid state transition, we do the following:
40
+
40
41
1. Compute hashes of public account and note states.
41
42
2. Make sure these hashes match records in the *state updates* section.
42
43
3. Verify the included ZKP against the following public inputs:
Copy file name to clipboardExpand all lines: docs/miden/architecture/notes.md
+12-12Lines changed: 12 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,7 +21,7 @@ Asset container for a note. A note vault can contain up to `255` assets stored i
21
21
22
22
### Script
23
23
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.
25
25
26
26
!!! note
27
27
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
44
44
45
45
## Note storage modes
46
46
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.
48
48
49
49
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.
50
50
@@ -65,7 +65,7 @@ the VM.
65
65
66
66
## Note nullifier
67
67
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.
69
69
70
70
The nullifier is computed as `hash(serial_num, script_hash, input_hash, vault_hash)`.
71
71
@@ -83,14 +83,14 @@ To know a note’s nullifier, one needs to know all details of the note. That me
83
83
84
84
## Note lifecycle
85
85
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.
87
87
88
-
The lifcycle of a note is as follows:
88
+
The life-cycle of a note is as follows:
89
89
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