Skip to content

Commit f82719f

Browse files
Merge pull request 0xPolygon#83 from 0xPolygon/km/miden_airscript
Miden AirScript chunk added
2 parents 5c38c2a + d969887 commit f82719f

File tree

18 files changed

+1179
-22
lines changed

18 files changed

+1179
-22
lines changed

docs/index.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,23 @@ hide:
44
- toc
55
---
66

7+
<style>
8+
9+
.hero-content-flex {
10+
bottom: 5px;
11+
}
12+
13+
</style>
14+
715
<div class="main">
816
<header class="section">
917
<div class="container-global">
1018
<div class="section-wrapper">
1119
<div class="hero-content-flex">
1220
<div class="hero-left">
1321
<h1 class="hero-heading">The Polygon Knowledge Layer</h1>
14-
<p class="hero-subext">Welcome to the technical documentation and knowledge resources for Polygon protocols and scaling technologies. Here you can learn how to build and deploy dApps, launch ZK rollups and validiums as Layer 2s on Ethereum, spin up nodes, and learn all about the latest in ZK research.</p>
22+
<p class="hero-subext">Welcome to the technical documentation and knowledge resources for Polygon protocols and scaling technologies.</p>
23+
<p> Learn how to build and deploy dApps, launch ZK rollups and validiums as Layer 2s on Ethereum, spin up nodes, and find out about the latest in zero-knowledge research.</p>
1524
</div>
1625
<div class="hero-right"><img src="img/home/main-img.svg" loading="lazy" alt="" class="hero-image"></div>
1726
</div>
@@ -88,7 +97,7 @@ hide:
8897
</a>
8998
<a href="learn" class="flex-card-item w-inline-block">
9099
<div class="product-list-item-header">
91-
<div class="feature-card-heading">Unified Liquidity</div>
100+
<div class="feature-card-heading">Unified liquidity</div>
92101
<div class="arrow-embed w-embed"><svg xmlns="http://www.w3.org/2000/svg" display="block" width="100%" height="auto" viewbox="0 0 16 17" fill="none">
93102
<path d="M9.98805 5.70133L3.41071 12.2787L4.58922 13.4572L11.1666 6.87976V12.2013H12.8333V4.03467H4.66665V5.70133H9.98805Z" fill="currentColor"></path>
94103
</svg></div>
@@ -114,7 +123,7 @@ hide:
114123
<div class="section-wrapper">
115124
<div class="home-dev-resources">
116125
<div class="section-header-wrapper">
117-
<h2 class="heading-h2">Developer Resources</h2>
126+
<h2 class="heading-h2">Developer resources</h2>
118127
<p class="home-section-subtext">For developers who know what they want to build and are ready to go.</p>
119128
</div>
120129
<div class="flexbox">
@@ -185,7 +194,7 @@ hide:
185194
</a>
186195
<a href="pos/get-started/building-on-polygon/" class="home-feature-card w-inline-block"><img src="img/home/polygon-icon.svg" loading="lazy" alt="" class="feature-icon">
187196
<div class="feature-content-wrapper">
188-
<div class="feature-content-name">Polygon PoS: Build a new dApp</div>
197+
<div class="feature-content-name">Polygon PoS: Build a new web3 dApp</div>
189198
<div class="arrow-embed w-embed"><svg xmlns="http://www.w3.org/2000/svg" display="block" width="100%" height="auto" viewbox="0 0 16 17" fill="none">
190199
<path d="M9.98805 5.70133L3.41071 12.2787L4.58922 13.4572L11.1666 6.87976V12.2013H12.8333V4.03467H4.66665V5.70133H9.98805Z" fill="currentColor"></path>
191200
</svg></div>
@@ -195,7 +204,7 @@ hide:
195204
<div class="flexbox items-4">
196205
<a href="pos/how-to/smart-contracts/" class="home-feature-card w-inline-block"><img src="img/home/polygon-icon.svg" loading="lazy" alt="" class="feature-icon">
197206
<div class="feature-content-wrapper">
198-
<div class="feature-content-name">Polygon PoS: Deploy an existing smart contract</div>
207+
<div class="feature-content-name">Polygon PoS: Deploy an existing contract</div>
199208
<div class="arrow-embed w-embed"><svg xmlns="http://www.w3.org/2000/svg" display="block" width="100%" height="auto" viewbox="0 0 16 17" fill="none">
200209
<path d="M9.98805 5.70133L3.41071 12.2787L4.58922 13.4572L11.1666 6.87976V12.2013H12.8333V4.03467H4.66665V5.70133H9.98805Z" fill="currentColor"></path>
201210
</svg></div>

docs/miden/architecture/assets.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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.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.
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](../concepts/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/state.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Polygon Miden has two databases to capture the note states. The note database is
2626

2727
### Account database
2828

29-
The latest account states - and data for onchain accounts - are recorded in a [tiered sparse Merkle tree](../crypto-primitives/tsmt.md) which maps account IDs to account hashes and account data if needed.
29+
The latest account states - and data for onchain accounts - are recorded in a [tiered sparse Merkle tree](../concepts/crypto-primitives/tsmt.md) which maps account IDs to account hashes and account data if needed.
3030

3131
<center>
3232
![Account DB](../../img/miden/architecture/state/account_DB.png){ width="80%" }
@@ -69,7 +69,7 @@ However, the size of the note database does not grow indefinitely. Theoretically
6969

7070
### Nullifier database
7171

72-
Nullifiers are stored in a [Tiered Sparse Merkle Tree](../crypto-primitives/tsmt.md), which maps [Note Nullifiers](notes.md#note-nullifier) to `0` or `1`. Nullifiers provide information on whether a specific note has been consumed yet. The database allows proving that a given nullifier is not in the database.
72+
Nullifiers are stored in a [Tiered Sparse Merkle Tree](../concepts/crypto-primitives/tsmt.md), which maps [Note Nullifiers](notes.md#note-nullifier) to `0` or `1`. Nullifiers provide information on whether a specific note has been consumed yet. The database allows proving that a given nullifier is not in the database.
7373

7474
<center>
7575
![Nullifier DB](../../img/miden/architecture/state/nullifier_DB.png){ width="80%" }

docs/miden/crypto-primitives/tsmt.md renamed to docs/miden/concepts/crypto-primitives/tsmt.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ A major issue with SMTs is the fact that operations scale with the size of the k
77
A common solution to this issue is to keep only non-empty leaves in the tree, which in practice means that sub-trees with only one non-empty child are replaced with the sub-tree rooted at that non-empty child. Here's an example of this:
88

99
<center>
10-
![tsmt compaction example](../../img/miden/crypto-primitives/tsmt/tsmt_compaction_example.svg){ width="80%" }
10+
![tsmt compaction example](../../../img/miden/crypto-primitives/tsmt/tsmt_compaction_example.svg){ width="80%" }
1111
</center>
1212

1313
Compaction implies then that the tree depth is logarithmic in the size of the dictionary entries as opposed to the size of the key space. This, in turn, means that the number of hashing required for executing operations on the key-value map scales logarithmically in the size of the map.
@@ -19,19 +19,19 @@ A disadvantage of this implementation, as well as all known implementations of c
1919
Tiered sparse Merkle trees (TSMT) are a result of the idea that one can trade hashing for more efficient bit-wise operations. More precisely, in TSMT, compaction happens only at certain pre-specified tiers and this leads to simpler bit-wise manipulations. In the case of Miden VM, compaction happens at depths `16`, `32`, `48` and `64`. To illustrate this, consider the following example where the keys have length 4, i.e. the SMT has depth 4.
2020

2121
<center>
22-
![tsmt non compact](../../img/miden/crypto-primitives/tsmt/tsmt_non_compact.svg){ width="80%" }
22+
![tsmt non compact](../../../img/miden/crypto-primitives/tsmt/tsmt_non_compact.svg){ width="80%" }
2323
</center>
2424

2525
If we choose the tiers to be at depths 2 and 4 then the compact version of the above tree will look like
2626

2727
<center>
28-
![tsmt compact 2](../../img/miden/crypto-primitives/tsmt/tsmt_compact_2.svg){ width="80%" }
28+
![tsmt compact 2](../../../img/miden/crypto-primitives/tsmt/tsmt_compact_2.svg){ width="80%" }
2929
</center>
3030

3131
If, however, we choose compaction at all possible depths we get a compact SMT that is similar to the [Jellyfish SMT](https://developers.diem.com/papers/jellyfish-merkle-tree/2021-01-14.pdf)
3232

3333
<center>
34-
![tsmt compact 2](../../img/miden/crypto-primitives/tsmt/tsmt_compact_1.svg){ width="80%" }
34+
![tsmt compact 2](../../../img/miden/crypto-primitives/tsmt/tsmt_compact_1.svg){ width="80%" }
3535
</center>
3636

3737
We can see that a TSMT is a parametrized SMT, where the parameter is the number of tiers, that interpolates between a plain SMT with no compaction and a (fully) compact SMT with compaction allowed at evey depth.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
This appendix contains additional information about some concepts that are not covered in the main documentation.
2+
3+
## Main vs. auxiliary execution trace segments (`main` and `aux`)
4+
5+
With Randomized AIRs, the construction of the execution trace can be split into multiple rounds, with the verifier providing new randomness between rounds. In the first round, before any random values are available, the Prover builds the first segment of the execution trace, which we refer to as the `main` trace (using [Winterfell](https://github.com/0xPolygonMiden/air-script/tree/main/codegen/winterfell) terminology). Additional trace segments can be built after the prover has committed to the first execution trace segment. When building auxiliary trace segments, the prover has access to the extra randomness sent by the verifier (in the non-interactive version of the protocol, this randomness is derived from the previous trace segment commitments). We refer to these as auxiliary trace segments (using Winterfell terminology again), and we call the first one the `aux` segment in AirScript and throughout this documentation.
6+
7+
Miden VM only makes use of one auxiliary trace segment, and in Winterfell the number of auxiliary trace segments is currently limited to one. Therefore, AirScript currently only supports the main execution trace called `main` and a single auxiliary trace segment called `aux`.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
AirScript currently comes bundled with two backends:
2+
3+
- [Winterfell backend](https://github.com/0xPolygonMiden/air-script/tree/main/codegen/winterfell) which outputs `Air` trait implementation for the [Winterfell prover](https://github.com/facebook/winterfell) (Rust).
4+
- [Miden assembly backend](https://github.com/0xPolygonMiden/air-script/tree/main/codegen/masm) which outputs constraint evaluation code for the [Miden VM](https://github.com/0xPolygonMiden/miden-vm) recursive verifier.
5+
6+
These backends can be used programmatically as crates. They can also be used via AirScript CLI by specifying `--target` flag.
7+
8+
For example, the following will output Winterfell `Air` trait implementation for AIR constraints described in `example.air` file:
9+
10+
```
11+
./target/release/airc transpile examples/example.air --target winterfell
12+
```
13+
14+
While the following will output constraint evaluation code for the same constraints in Miden assembly.
15+
16+
```
17+
./target/release/airc transpile examples/example.air --target masm
18+
```
19+
20+
In both cases we assumed that the CLI has been compiled as described [here](introduction.md#cli).
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
An AirScript project can consist of one or more modules, each module located in a separate file with a `.air` extension. For projects consisting of multiple modules, one module must be declared as the root module, and all other modules must be declared as library modules.
2+
3+
Currently, all modules must be located in a single directory, but in the future this limitation will be removed.
4+
5+
All modules must start with a module name declaration followed by a set of source sections. These sections describe both the metadata and constraint evaluation logic for the AIR. Depending on the module type, some source sections may be required, be optional, or may not be allowed. The table below summarizes this information.
6+
7+
<center>
8+
9+
| Section | Root module | Library module |
10+
| ------------------------------------------------------------------------------------- | :---------: | :---------------: |
11+
| [constants](type-declarations.md#constants-const) | optional | optional |
12+
| [trace columns](type-declarations.md#execution-trace-trace_columns) | required | not allowed |
13+
| [public inputs](type-declarations.md#public-inputs-public_inputs) | required | not allowed |
14+
| [periodic columns](type-declarations.md#periodic-columns-periodic_columns) | optional | optional |
15+
| [random values](type-declarations.md#random-values-random_values) | optional | not allowed |
16+
| [boundary constraints](constraints.md#boundary-constraints-boundary_constraints) | required | not allowed |
17+
| [integrity constraints](constraints.md#integrity-constraints-integrity_constraints) | required | not allowed |
18+
| [evaluators](evaluators.md) | optional | optional |
19+
20+
</center>
21+
22+
!!! note
23+
Constants and evaluators are not really distinct sections but rather a set of declarations which can be done in-between any other sections.
24+
25+
### Root module
26+
27+
A root module defines an entrypoint into an AirScript project. It must start with a name declaration which consists of a `def` keyword followed by the name of the AIR project. For example:
28+
29+
```
30+
def ExampleAir
31+
```
32+
33+
where the name of the module must:
34+
35+
- Be a string consisting of alpha-numeric characters and underscores.
36+
- Start with a letter.
37+
- End with a newline.
38+
39+
Besides the name declaration, a root module must:
40+
41+
- Describe the shape of the execution trace (done via the *trace columns* section).
42+
- If the trace consists of more than one segment (e.g., main and auxiliary segments), describe random values available to the prover after each segment commitment (done via the *random values* section).
43+
- Describe the shape of the public inputs (done via the *public inputs* section).
44+
- Describe the boundary constraints placed against the execution trace (done via the *boundary constraints* section).
45+
- Describe the integrity constraints placed against the execution trace (done via the *integrity constraints* section).
46+
47+
To aid with boundary and integrity constraint descriptions, a root module may also contain definitions of constants, evaluators, and periodic columns.
48+
49+
### Library modules
50+
51+
Library modules can be used to split integrity constraint descriptions across multiple files. A library module must start with a name declaration which consists of a `mod` keyword followed by the name of the module. For example:
52+
53+
```
54+
mod example_module
55+
```
56+
57+
where the name of the module must:
58+
59+
- Be the same as the name of the file in which the library module is defined (e.g., the above module must be located in `example_module.air` file).
60+
- Be a string consisting of alpha-numeric characters and underscores.
61+
- Start with a letter.
62+
- End with a newline.
63+
64+
Besides the name declaration, library modules my contain definitions of constants, evaluators, and periodic columns. Constants and evaluators defined in a library module may be imported by a root or other library modules.
65+
66+
Library modules inherit random value declarations of the root module. That is, evaluators defined in a library module can reference random values declared in the root module.
67+
68+
## Importing evaluators
69+
70+
A module can import constants and evaluators from library modules via a `use` statement. For example:
71+
72+
```
73+
use my_module::my_evaluator
74+
use my_module::my_constant
75+
```
76+
77+
where:
78+
79+
- `my_module` is a library module located in the same directory as the importing module.
80+
- `my_evaluator` and `my_constant` is an evaluator and a constant defined in `my_module`.
81+
82+
Once an evaluator or a constant is imported, it can be used in the same way as evaluators and constants defined in the importing module.
83+
84+
To import multiple evaluators and constants, multiple `use` statements must be used:
85+
86+
```
87+
use my_module::foo
88+
use my_module::bar
89+
use my_other_module::baz
90+
```
91+
92+
!!! note
93+
`use` statements can appear anywhere in the module file.

0 commit comments

Comments
 (0)