Commit Graph

2040 Commits

Author SHA1 Message Date
chriseth
e2eadffa2a Create is_first inside the lookup. (#1796)
Since we can now create constant columns inside `constr` functions, we
don't need to pass `is_first` any more.
2024-09-13 08:31:02 +00:00
onurinanc
e668cdfc64 add generic fp2 for all the field elements (bb, gl, bn254, m31) (#1788) 2024-09-12 16:01:37 +00:00
chriseth
48d7d90d9b Return errors from pil analyzer. (#1758) 2024-09-12 10:04:42 +00:00
Gastón Zanitti
945d613f15 Remove lookups from PilStatement (#1782)
Co-authored-by: chriseth <chris@ethereum.org>
2024-09-12 10:02:46 +00:00
Georg Wiese
44c04c2e6c Add M31 support for Plonky3 backend (#1785)
Analogously to our Plonky3 BabyBear support, I added support for M31 by
using the parameters they use in [their Keccak
example](7c5deb0eab/keccak-air/examples/prove_m31_poseidon2.rs).

To test:
```bash
cargo run pil test_data/pil/fibonacci.pil -o output -f --field m31 --prove-with plonky3
```
2024-09-12 09:55:56 +00:00
chriseth
b2a06c2b03 More prover functions for std. (#1762) 2024-09-11 14:20:09 +00:00
Steve Wang
6c1c31a4da BabyBear shift machine (#1784)
All tests passed. :)

Operations:
- shl<0> A1, A2, B -> C1, C2
- shr<1> A1, A2, B -> C1, C2
- `A1` `A2` are 16 bit limbs of 32 bit `A` in little-endian order.
Likewise for `C1` and `C2`

Implementation:
- We adopted a similar implementation to our prior shift machine, which
decomposes `A` to 4 bytes and looks up each byte to a lookup table of
`[A_byte, B (shift amount), block row, operation id]`, so the size of
the lookup table is `[256, 32, 4, 2] = 65536`. Each row looks up to the
resulting byte after the bit shifting, and the results are added
together to obtain `C`.
- In our design, instead of looking up to 32-bit `C` column, we are
looking up to two 16-bit `C1` and `C2` columns. Overall, there are more
witness columns due to decomposing to 16-bit limbs the in the main shift
machine and one more fixed column in the lookup table, but the same
number of lookups performed.

Future optimization:
- There's ample ground for "reshaping" the main machine to have more
columns but fewer rows, and do more lookups in each row so that we are
not just processing one byte in each row. In the most aggressive case,
we can even process everything in the same row.
- For example, processing two bytes in one row (instead of one byte)
should have half the number of rows but less than twice the number of
columns, and therefore fewer cells in total. This should be good for
provers with time linear to the number of cells.

---------

Co-authored-by: onurinanc <e191322@metu.edu.tr>
2024-09-11 13:28:23 +00:00
chriseth
5b52c1f486 More arith hints (#1760) 2024-09-11 11:49:39 +00:00
Lucas Clemente Vella
114429a86c General macro for supporting only a subset of fields in the Backend. (#1727)
Co-authored-by: topanisto <ankaa@mit.edu>
Co-authored-by: schaeff <thibaut@schaeff.fr>
Co-authored-by: Thibaut Schaeffer <schaeffer.thibaut@gmail.com>
2024-09-11 11:27:42 +00:00
chriseth
efd93482e3 Prover functions (#1717) 2024-09-11 10:51:56 +00:00
Lucas Clemente Vella
83e2c841e6 Trying buildjet CI runner (#1777) 2024-09-11 08:53:12 +00:00
Georg Wiese
41a61b1638 Add Mersene31Field (#1781)
Adds Plonky3's implementation of the Mersenne-31 field.

To test:
```
cargo run pil test_data/pil/fibonacci.pil -o output -f --field m31
```

The implementation is basically the same wrapper as for BabyBear, so I
moved the code to a macro and used it for both fields.
2024-09-10 16:24:12 +00:00
Gastón Zanitti
4f190b9bf9 Lookups as Binary ops (#1770)
Co-authored-by: chriseth <chris@ethereum.org>
2024-09-10 15:15:58 +00:00
chriseth
948cf1f837 Quote op (#1771) 2024-09-10 13:57:29 +00:00
Gastón Zanitti
c6a649775c More quote ops (#1776) 2024-09-10 11:17:30 +00:00
chriseth
72cacd2c78 Use cache v4 (#1774) 2024-09-10 11:06:30 +00:00
chriseth
e061ad0685 Use checkout v4 (#1773) 2024-09-10 11:05:51 +00:00
chriseth
a98a625d6f Move evaluator tests. (#1769) 2024-09-10 10:42:04 +00:00
chriseth
2b5d2e1ca1 Use artifact v4 actions (#1772) 2024-09-10 09:55:04 +00:00
Gastón Zanitti
73f49a4553 Traits unification (#1625)
Co-authored-by: chriseth <chris@ethereum.org>
2024-09-09 13:37:42 +00:00
Georg Wiese
4340d462ed Update docs to mention RUSTFLAGS (#1766)
This makes sure that we use AVX instructions when available. Seems to
speed up Plonky3 proofs (slightly for Goldilocks and 30-50% for
BabyBear).
2024-09-06 16:37:42 +00:00
topanisto
277edbf5dd BabyBear with only Plonky3 changes (#1693)
Adding BabyBear params to Plonky3 crate.

---------

Co-authored-by: Thibaut Schaeffer <schaeffer.thibaut@gmail.com>
Co-authored-by: Lucas Clemente Vella <lvella@powdrlabs.com>
Co-authored-by: schaeff <thibaut@schaeff.fr>
Co-authored-by: Leo Alt <leo@powdrlabs.com>
2024-09-06 13:33:40 +00:00
chriseth
6688249331 Support captured vars (#1645)
Co-authored-by: Thibaut Schaeffer <schaeffer.thibaut@gmail.com>
2024-09-06 12:55:15 +00:00
Georg Wiese
831edf3412 Print tracing profiling log (for Plonky3) (#1753)
With this change, we also print profiling logs for crates that are
instrumented using the `tracing` crate (if we're at least in the `DEBUG`
log level).

For example, for:
```bash
cargo run -r --bin powdr-rs compile riscv/tests/riscv_data/keccak -o output
RUST_LOG=debug cargo run -r --features plonky3,halo2 pil output/keccak.asm -o output -f --field gl --prove-with plonky3-composite
```

This prints:
```
== Proving machine: main (size 131072), stage 0
INFO     prove_with_key [ 1.84s | 0.23% / 100.00% ]
INFO     ┝━ infer log of constraint degree [ 141µs | 0.01% ]
INFO     ┝━ commit to trace data [ 458ms | 19.13% / 24.94% ]
INFO     │  ┕━ coset_lde_batch [ 107ms | 5.81% ] dims: 74x131072
INFO     ┝━ compute quotient polynomial [ 1.16s | 62.90% ]
INFO     ┝━ commit to quotient poly chunks [ 58.7ms | 2.14% / 3.19% ]
INFO     │  ┝━ coset_lde_batch [ 10.6ms | 0.58% ] dims: 2x131072
INFO     │  ┕━ coset_lde_batch [ 8.86ms | 0.48% ] dims: 2x131072
INFO     ┝━ compute_inverse_denominators [ 26.3ms | 1.43% ]
INFO     ┝━ reduce matrix quotient [ 10.9ms | 0.00% / 0.59% ] dims: 4x262144
INFO     │  ┝━ compute opened values with Lagrange interpolation [ 8.46ms | 0.46% ]
INFO     │  ┕━ reduce rows [ 2.42ms | 0.13% ]
INFO     ┝━ reduce matrix quotient [ 10.9ms | 0.00% / 0.59% ] dims: 4x262144
INFO     │  ┝━ compute opened values with Lagrange interpolation [ 8.91ms | 0.48% ]
INFO     │  ┕━ reduce rows [ 2.01ms | 0.11% ]
INFO     ┝━ reduce matrix quotient [ 20.4ms | 0.00% / 1.11% ] dims: 74x262144
INFO     │  ┝━ compute opened values with Lagrange interpolation [ 14.0ms | 0.76% ]
INFO     │  ┕━ reduce rows [ 6.35ms | 0.35% ]
INFO     ┝━ reduce matrix quotient [ 17.6ms | 0.00% / 0.96% ] dims: 74x262144
INFO     │  ┝━ compute opened values with Lagrange interpolation [ 11.2ms | 0.61% ]
INFO     │  ┕━ reduce rows [ 6.44ms | 0.35% ]
INFO     ┝━ reduce matrix quotient [ 7.55ms | 0.00% / 0.41% ] dims: 2x262144
INFO     │  ┝━ compute opened values with Lagrange interpolation [ 6.63ms | 0.36% ]
INFO     │  ┕━ reduce rows [ 913µs | 0.05% ]
INFO     ┝━ reduce matrix quotient [ 8.74ms | 0.00% / 0.48% ] dims: 2x262144
INFO     │  ┝━ compute opened values with Lagrange interpolation [ 7.92ms | 0.43% ]
INFO     │  ┕━ reduce rows [ 817µs | 0.04% ]
INFO     ┕━ FRI prover [ 57.8ms | 0.00% / 3.15% ]
INFO        ┝━ commit phase [ 56.0ms | 3.05% ]
INFO        ┝━ grind for proof-of-work witness [ 654µs | 0.04% ]
INFO        ┕━ query phase [ 1.09ms | 0.06% ]
INFO     verify_with_key [ 42.6ms | 99.63% / 100.00% ]
INFO     ┕━ infer log of constraint degree [ 158µs | 0.37% ]
==> Proof stage computed in 1.934923926s
```
2024-09-05 13:45:55 +00:00
Georg Wiese
80170a6e43 Plonky3 circuit builder: Cache computations on Analyzed PIL (#1754)
On the Keccak test (and with the `RUSTFLAGS='-Ctarget-cpu=native'`
flag), this brings down the proof time from 7.2 to 4.4s. The share for
computing the quotient polynomial drops from > 50% for some machines to
< 10% for all machines.
2024-09-05 12:46:23 +00:00
Leandro Pacheco
7fe5fb4d02 run pr-tests on self hosted runner (#1734) 2024-09-04 14:46:30 +00:00
Georg Wiese
82dbac04c2 Correct source for Plonky3 parameters (#1752)
We're using a Poseidon transcript, so it seems like this comment is
wrong.
2024-09-04 13:24:20 +00:00
chriseth
42d998c1cf Introduce machine parts. (#1743) 2024-09-04 13:08:34 +00:00
onurinanc
14225aa1d1 Implement Fp4 for BabyBear Field in PIL (#1707)
Solves the issue in #1691

You can run the test using `--field bb`
2024-09-03 15:15:44 +00:00
Thibaut Schaeffer
55afe60662 Make csv export work with multiple fixed column sizes (#1744) 2024-09-03 12:55:30 +00:00
Thibaut Schaeffer
7f259b43c7 Support degree ranges (#1667)
We currently hardcode the range of degrees that variable degree machines
are preprocessed for. Expose that in machines instead.

This changes pil namespaces to accept a min and max degree:
```
namespace main(123..456);
namespace main(5); // allowed for backward compatibility, translates to `5..5`
```

It adds two new builtins:
```
std::prover::min_degree
std::prover::max_degree
```

And sets the behavior of the `std::prover::degree` builtin to only
succeed if `min_degree` and `max_degree` are equal.
2024-09-03 12:37:44 +00:00
chriseth
ecf5535be3 Mark test as slow. (#1742) 2024-09-02 10:59:19 +00:00
Gastón Zanitti
ea2f06df16 LambdaExpression formatting (#1733)
This PR fixes issue #1728.
1) Removes the blank space that was printed even if the body of the
blocks was empty.
2) Adds the Precedence trait to LambdaExpressions to correctly handle
the use of parentheses.
2024-09-02 09:27:05 +00:00
Steve Wang
4bd1f1dfb6 Keccak Rust Wrappers (#1337)
Input for syscall is one memory pointer to the state array of 25 gl fe.
Output is calculated in place.

All functions outside of keccakf are executed in Rust. Might need to
delete everything except keccakf from keccakf.asm (including the
padding, updating, and byte <-> u64 conversions).

Not tested. Should I wait till all infrastructure needed are merged?
Technically can also do the following for the machine and I think I can
test it already?

```
pol commit input_state[25];
pol commit output_state[25];
operation keccakf_permutation<0> input_state[0], input_state[1], ..., input_state[24] -> output_state[0], output_state[1], ..., output_state[24]
array::zip(input_state, output_state, |input_state, output_state| (keccakf(input_state) - output_state = 0);
```
2024-09-02 07:50:24 +00:00
Lucas Clemente Vella
59902639de Saving one hit to the BTreeMap. (#1741) 2024-08-31 21:54:11 +00:00
Leandro Pacheco
19503e1cbb cancel old workflows for the same branch (#1740)
when a new commit to branch triggers a build and tests, cancel any
currently running (now obsolete) workflows for the same branch
2024-08-31 11:51:10 +00:00
Leo
18ccb2fe81 remove unsafe in const bb traits (#1738) 2024-08-30 15:06:02 +00:00
chriseth
3a1e3bb398 Remove poly_id property. (#1723) 2024-08-30 14:52:20 +00:00
Gastón Zanitti
43155ab586 Add Hash trait for Type (#1732)
Small PR that adds the `Hash` trait to `Type` and some of its internal
types.
Needed to be able to store `Vec<type>` in order to solve trait
implementations based on its `type_args`.
2024-08-30 13:26:16 +00:00
chriseth
14d710c56c Refactor double sorted witness. (#1735) 2024-08-30 12:43:16 +00:00
Leo
c9ebdd9682 Baby bear initial machine tests (#1682) 2024-08-30 12:43:07 +00:00
Lucas Clemente Vella
8b66a66a11 Unifying implementation of fake random number generator. (#1731)
There are two interfaces we must provide: the one from `getrandom` crate
and the one used internally by `std`.
2024-08-29 20:40:21 +00:00
Leandro Pacheco
83d9c7ad87 rust_continuations_dry_run return type (#1730)
this way we can get more information back (total trace length for now)
2024-08-29 09:31:23 +00:00
chriseth
69ae0b69e7 Extract build_machine. (#1729) 2024-08-28 17:47:50 +00:00
Gastón Zanitti
4fbac58bd2 Parameterized expressions (#1627)
This PR 'parameterise' Expressions to be able to choose when they can be
converted into a StructExpression and when they cannot. This
modification allows us to overcome ambiguities with Structs and to adopt
the standard Structs syntax:
```
struct Point{ x: int, y: int }
let p: Point = Point{ x: 1, y: 2 };
```

This PR replace #1591 to be able to include this modifications before
merging structs.

---------

Co-authored-by: chriseth <chris@ethereum.org>
2024-08-28 16:48:35 +00:00
topanisto
6cd2ba1617 Switching dependencies to main branch of Plonky3 fork (#1670)
Merging https://github.com/powdr-labs/Plonky3/tree/uni-stark-with-fixed
and changing dependencies accordingly.

Co-authored-by: schaeff <thibaut@schaeff.fr>
2024-08-26 10:50:24 +00:00
Leandro Pacheco
fb74fc1034 point baby-bear to our p3 fork (#1715)
point `p3-baby-bear` to our `p3` fork (like the other `p3` dependencies
in the project)
2024-08-23 18:27:51 +00:00
Thibaut Schaeffer
b65ff65df2 Simplify test files after #1694 (#1720)
Now that #1694 is merged we don't need convoluted module trees.
2024-08-23 17:28:19 +00:00
chriseth
82358ef5f3 Mark slow tests as slow. (#1712) 2024-08-23 15:24:40 +00:00
Gastón Zanitti
0dc3ae762f Depreciation of . by :: in paths (#1694) 2024-08-23 07:39:50 +00:00