mirror of
https://github.com/saymrwulf/pasta_curves-source.git
synced 2026-09-07 20:30:34 +00:00
commit
69d987644c
8 changed files with 77 additions and 1 deletions
6
.github/workflows/book.yml
vendored
6
.github/workflows/book.yml
vendored
|
|
@ -16,6 +16,12 @@ jobs:
|
||||||
with:
|
with:
|
||||||
mdbook-version: '0.4.4'
|
mdbook-version: '0.4.4'
|
||||||
|
|
||||||
|
- name: Install mdbook-katex
|
||||||
|
uses: actions-rs/cargo@v1
|
||||||
|
with:
|
||||||
|
command: install
|
||||||
|
args: mdbook-katex
|
||||||
|
|
||||||
- name: Build halo2 book
|
- name: Build halo2 book
|
||||||
run: mdbook build book/
|
run: mdbook build book/
|
||||||
|
|
||||||
|
|
|
||||||
6
.github/workflows/ci.yml
vendored
6
.github/workflows/ci.yml
vendored
|
|
@ -69,12 +69,16 @@ jobs:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
|
- name: cargo build
|
||||||
|
uses: actions-rs/cargo@v1
|
||||||
|
with:
|
||||||
|
command: build
|
||||||
- name: Setup mdBook
|
- name: Setup mdBook
|
||||||
uses: peaceiris/actions-mdbook@v1
|
uses: peaceiris/actions-mdbook@v1
|
||||||
with:
|
with:
|
||||||
mdbook-version: '0.4.4'
|
mdbook-version: '0.4.4'
|
||||||
- name: Test halo2 book
|
- name: Test halo2 book
|
||||||
run: mdbook test book/
|
run: mdbook test -L target/debug/deps book/
|
||||||
|
|
||||||
clippy:
|
clippy:
|
||||||
name: Clippy (stable)
|
name: Clippy (stable)
|
||||||
|
|
|
||||||
|
|
@ -4,3 +4,5 @@ language = "en"
|
||||||
multilingual = false
|
multilingual = false
|
||||||
src = "src"
|
src = "src"
|
||||||
title = "The halo2 Book"
|
title = "The halo2 Book"
|
||||||
|
|
||||||
|
[preprocessor.katex]
|
||||||
|
|
|
||||||
|
|
@ -3,5 +3,8 @@
|
||||||
[halo2](README.md)
|
[halo2](README.md)
|
||||||
- [Concepts](concepts.md)
|
- [Concepts](concepts.md)
|
||||||
- [User Documentation](user.md)
|
- [User Documentation](user.md)
|
||||||
|
- [A simple example](user/simple-example.md)
|
||||||
|
- [Lookup tables](user/lookup-tables.md)
|
||||||
- [Gadgets](user/gadgets.md)
|
- [Gadgets](user/gadgets.md)
|
||||||
|
- [Tips and tricks](user/tips-and-tricks.md)
|
||||||
- [Design](design.md)
|
- [Design](design.md)
|
||||||
|
|
|
||||||
|
|
@ -1 +1,5 @@
|
||||||
# User Documentation
|
# User Documentation
|
||||||
|
|
||||||
|
You're probably here because you want to write circuits? Excellent!
|
||||||
|
|
||||||
|
This section will guide you through the process of creating circuits with halo2.
|
||||||
|
|
|
||||||
11
book/src/user/lookup-tables.md
Normal file
11
book/src/user/lookup-tables.md
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
# Lookup tables
|
||||||
|
|
||||||
|
In normal programs, you can trade memory for CPU to improve performance, by pre-computing
|
||||||
|
and storing lookup tables for some part of the computation. We can do the same thing in
|
||||||
|
halo2 circuits!
|
||||||
|
|
||||||
|
A lookup table can be thought of as enforcing a *relation* between variables, where the relation is expressed as a table.
|
||||||
|
Assuming we have only one lookup argument in our constraint system, the total size of tables is constrained by the size of the circuit:
|
||||||
|
each table entry costs one row, and it also costs one row to do each lookup.
|
||||||
|
|
||||||
|
TODO
|
||||||
19
book/src/user/simple-example.md
Normal file
19
book/src/user/simple-example.md
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
# A simple example
|
||||||
|
|
||||||
|
Let's start with a simple circuit, to introduce you to the common APIs and how they are
|
||||||
|
used. The circuit will take a public input $c$, and will prove knowledge of two private
|
||||||
|
inputs $a$ and $b$ such that
|
||||||
|
|
||||||
|
$$a \cdot b = c.$$
|
||||||
|
|
||||||
|
```rust
|
||||||
|
# extern crate halo2;
|
||||||
|
use halo2::arithmetic::FieldExt;
|
||||||
|
|
||||||
|
struct MyCircuit<F: FieldExt> {
|
||||||
|
a: F,
|
||||||
|
b: F,
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
TODO
|
||||||
27
book/src/user/tips-and-tricks.md
Normal file
27
book/src/user/tips-and-tricks.md
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
# Tips and tricks
|
||||||
|
|
||||||
|
This section contains various ideas and snippets that you might find useful while writing
|
||||||
|
halo2 circuits.
|
||||||
|
|
||||||
|
## Small range constraints
|
||||||
|
|
||||||
|
A common constraint used in R1CS circuits is the boolean constraint: $b * (1 - b) = 0$.
|
||||||
|
This constraint can only be satisfied by $b = 0$ or $b = 1$.
|
||||||
|
|
||||||
|
In halo2 circuits, you can similarly constrain a cell to have one of a small set of
|
||||||
|
values. For example, to constrain $a$ to the range $[0..5]$, you would create a gate of
|
||||||
|
the form:
|
||||||
|
|
||||||
|
$$a \cdot (1 - a) \cdot (2 - a) \cdot (3 - a) \cdot (4 - a) = 0$$
|
||||||
|
|
||||||
|
while to constraint $c$ to be either 7 or 13, you would use:
|
||||||
|
|
||||||
|
$$(7 - c) \cdot (13 - c) = 0$$
|
||||||
|
|
||||||
|
> The underlying principle here is that we create a polynomial constraint with roots at
|
||||||
|
> each value in the set of possible values we want to allow. In R1CS circuits, the maximum
|
||||||
|
> supported polynomial degree is 2 (due to all constraints being of the form $a * b = c$).
|
||||||
|
> In halo2 circuits, you can use arbitrary-degree polynomials - with the proviso that
|
||||||
|
> higher-degree constraints are more expensive to use.
|
||||||
|
|
||||||
|
Note that the roots don't have to be constants; for example $(a - x) \cdot (a - y) \cdot (a - z) = 0$ will constrain $a$ to be equal to one of $\{ x, y, z \}$ where the latter can be arbitrary polynomials, as long as the whole expression stays within the maximum degree bound.
|
||||||
Loading…
Reference in a new issue