Skip to content

Commit 4e89655

Browse files
committed
docs: Add brief bus documentation
1 parent 510ca8c commit 4e89655

File tree

8 files changed

+97
-2
lines changed

8 files changed

+97
-2
lines changed

docs/src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- [Constraint descriptions](./description/constraints.md)
99
- [Variables](./description/variables.md)
1010
- [Evaluators](./description/evaluators.md)
11+
- [Buses](./description/buses.md)
1112
- [Convenience syntax](./description/convenience.md)
1213
- [AirScript Example](./description/example.md)
1314
- [Keywords](./description/keywords.md)

docs/src/description/buses.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Buses
2+
3+
A bus is a construct that aims to easily describe specific constraints, and can be for instance useful to communicate data between multiple proofs.
4+
5+
## Bus types
6+
7+
## Multiset `unit`
8+
9+
Multiset-based buses can represent constraints specifying given values have been added or removed from a column, in no specific order.
10+
11+
## LogUp `mult`
12+
13+
LogUp-based buses are more complex than multiset buses, and can encode the multiplicity of an element: an element can be added or removed multiple times.
14+
15+
## Defining buses
16+
17+
See the [declaring buses](./declarations.md#buses) for more details.
18+
19+
```
20+
buses {
21+
unit p,
22+
mult q,
23+
}
24+
```
25+
26+
## Bus boundary constraints
27+
28+
In the boundary constraints section, we can constrain the initial and final state of the bus. Currently, only constraining a bus to be empty (with the `null` keyword) is supported.
29+
30+
```
31+
boundary_constraints {
32+
enf p.first = null;
33+
enf p.last = null;
34+
}
35+
```
36+
37+
The above example states that the bus `p` should be empty at the beginning and end of the trace.
38+
39+
## Bus integrity constraints
40+
41+
In the integrity constraints section, we can add and remove elements (as tuples of felts) to and from a bus. In the following examples, `p` and `q` are respectivelly multiset and logup based buses.
42+
43+
```
44+
integrity_constraints {
45+
p.add(a) when s1;
46+
p.rem(a, b) when 1 - s2;
47+
}
48+
```
49+
50+
Here, `s1` and `1 - s2` are binary selectors: the element is added or removed when the corresponding selector's value is 1.
51+
52+
The global resulting constraint on the column of the bus is the following: `p ′ ⋅ ( ( α 0 + α 1 ⋅ a + α 2 ⋅ b ) ⋅ ( 1 − s2 ) + s2 ) = p ⋅ ( ( α 0 + α 1 ⋅ a ) ⋅ s1 + 1 − s1 ))`, where `α i` corresponds to the i-th random value provided by the verifier.
53+
54+
```
55+
integrity_constraints {
56+
q.rem(e, f, g) when s
57+
q.add(a, b, c) for d
58+
}
59+
```
60+
61+
Similarly to the previous example elements can be added or removed from `q` with binary selectors. However, as it is a LogUp-based bus, it is also possible to add and remove elements with a given scalar multiplicity with the `for` keyword (here, `d` does not have to be binary).
62+
63+
The global resulting constraint on the column of the bus is the following: `q ′ + s ( α 0 + α 1 ⋅ e + α 2 ⋅ f + α 3 ⋅ g ) = q + d ( α 0 + α 1 ⋅ a + α 2 ⋅ b + α 3 ⋅ c )`, where `α i` corresponds to the i-th random value provided by the verifier.

docs/src/description/declarations.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,23 @@ Periodic columns can be referenced by [integrity constraints](./constraints.md#i
9090

9191
When constraints are evaluated, these periodic values always refer to the value of the column in the current row. For example, when evaluating an integrity constraint such as `enf k0 * a = 0`, `k0` would be evaluated as `0` in rows `0`, `1`, `2` of the trace and as `1` in row `3`, and then the cycle would repeat. Attempting to refer to the "next" row of a periodic column, such as by `k0'`, is invalid and will cause a `ParseError`.
9292

93+
94+
## Buses (`buses`)
95+
96+
A `buses` section contains declarations for buses used in the description and evaluation of integrity constraints.
97+
98+
99+
The following is an example of a valid `buses` source section:
100+
101+
```
102+
buses {
103+
unit p,
104+
mult q,
105+
}
106+
```
107+
108+
In the above example, we declare two buses: `p` of type `unit`, and `q` of type `mult`. They respectively correspond to a multiset-based bus and a LogUp-based bus, that expand to different constraints. More information on bus types can be found in the [buses](./buses.md) section.
109+
93110
## Random values (`random_values`)
94111

95112
A `random_values` section contains declarations for random values provided by the verifier. Random values can be accessed by the named identifier for the whole array or by named bindings to single or grouped random values within the array.

docs/src/description/example.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ periodic_columns {
1919
k0: [1, 1, 1, 1, 1, 1, 1, 0],
2020
}
2121
22+
buses {
23+
mult: q,
24+
}
25+
2226
boundary_constraints {
2327
# define boundary constraints against the main trace at the first row of the trace.
2428
enf a.first = stack_inputs[0];
@@ -32,6 +36,9 @@ boundary_constraints {
3236
3337
# set the first row of the auxiliary column p to 1
3438
enf p.first = 1;
39+
40+
# set the bus q to be initially empty
41+
enf q.first = null;
3542
}
3643
3744
integrity_constraints {
@@ -49,5 +56,8 @@ integrity_constraints {
4956
5057
# the auxiliary column contains the product of values of c offset by a random value.
5158
enf p' = p * (c + $rand[0]);
59+
60+
# add p to the q bus when s = 1
61+
q.add(p) when s;
5262
}
5363
```

docs/src/description/keywords.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
AirScript defines the following keywords:
44

55
- `boundary_constraints`: used to declare the source section where the [boundary constraints are described](./constraints.md#boundary_constraints).
6-
- `first`: used to access the value of a trace column at the first row of the trace. _It may only be used when defining boundary constraints._
7-
- `last`: used to access the value of a trace column at the last row of the trace. _It may only be used when defining boundary constraints._
6+
- `first`: used to access the value of a trace column / bus at the first row of the trace. _It may only be used when defining boundary constraints._
7+
- `last`: used to access the value of a trace column / bus at the last row of the trace. _It may only be used when defining boundary constraints._
88
- `case`: used to declare arms of [conditional constraints](./convenience.md#conditional-constraints).
99
- `const`: used to declare [constants](./declarations.md#constant-constant).
1010
- `def`: used to [define the name](./organization.md#root-module) of a root AirScript module.

docs/src/description/main.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- [Constraint descriptions](./constraints.md)
77
- [Variables](./variables.md)
88
- [Evaluators](./evaluators.md)
9+
- [Buses](./buses.md)
910
- [Convenience syntax](./convenience.md)
1011
- [AirScript Example](./example.md)
1112
- [Keywords](./keywords.md)

docs/src/description/organization.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ All modules must start with a module name declaration followed by a set of sourc
1212
| [trace columns](./declarations.md#execution-trace-trace_columns) | required | not allowed |
1313
| [public inputs](./declarations.md#public-inputs-public_inputs) | required | not allowed |
1414
| [periodic columns](./declarations.md#periodic-columns-periodic_columns) | optional | optional |
15+
| [buses](./declarations.md#buses-buses) | optional | optional |
1516
| [random values](./declarations.md#random-values-random_values) | optional | not allowed |
1617
| [boundary constraints](./constraints.md#boundary-constraints-boundary_constraints) | required | not allowed |
1718
| [integrity constraints](./constraints.md#integrity-constraints-integrity_constraints) | required | not allowed |

docs/src/introduction.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ AirScript includes the following features:
1616

1717
- **Random Values**: Users can define random values provided by the verifier (e.g. `alphas: [x, y[14], z],` or `rand: [16],`)
1818

19+
- **Buses**: Users can declare buses (e.g. `unit p,`)
20+
1921
- **Boundary Constraints**: Users can enforce boundary constraints on main and auxiliary trace columns using public inputs, random values, constants and variables.
2022

2123
- **Integrity Constraints**: Users can enforce integrity constraints on main and auxiliary trace columns using trace columns, periodic columns, random values, constants and variables.

0 commit comments

Comments
 (0)