208 Commits

Author SHA1 Message Date
wborgeaud
b5d35b3582
Merge pull request #246 from mir-protocol/goldilocks_ext
Goldilocks extension fields
2021-09-15 18:32:15 +02:00
wborgeaud
c14673863a Add submodule for field extension tests 2021-09-15 18:22:26 +02:00
wborgeaud
5048a3f31d Minor 2021-09-15 10:05:41 +02:00
wborgeaud
c9d884f740 Change tests for quartic extension 2021-09-15 09:55:38 +02:00
wborgeaud
1ca197840f Add a test_field_extension macro 2021-09-15 09:52:49 +02:00
wborgeaud
d9978b5897 Remove unused 2021-09-15 09:38:25 +02:00
wborgeaud
80af66c87b Test quadratic extensions of Crandall and Goldilocks 2021-09-15 09:36:56 +02:00
wborgeaud
dc4062cde7 Add quadratic and quartic extensions to Goldilocks 2021-09-15 09:10:18 +02:00
Jakub Nabaglo
a7cd1ef40b
Vectorize Poseidon constant layer with NEON (#245)
* Start work on Crandall arithmetic in NEON

* Poseidon constant layer in NEON

* its alive

Co-authored-by: Jakub Nabaglo <jakub@mirprotocol.org>
2021-09-14 21:37:07 -07:00
Jakub Nabaglo
2ae9e34993
AVX2 vectorization of Poseidon constant layer (#243)
* AVX2 vectorization of Poseidon constant layer

* Silence unused import warning + minor style

* Daniel comment
2021-09-13 21:18:18 -07:00
Jakub Nabaglo
b0f244f1ee
Vectorize Goldilocks with AVX2 (#241)
* Start work on vectorized Goldilocks

* Vectorized Goldilocks

* Unused import warning
2021-09-13 17:42:25 -07:00
Jakub Nabaglo
de1d5d0ad2
Minor: fix a few warnings (#239)
* Minor: fix a few warnings

* Lints
2021-09-13 15:42:59 -07:00
Daniel Lubarov
91f7b4e300
Replace CrandallQuarticField with a more generic QuarticExtension (#232)
* Replace `CrandallQuarticField` with a more generic `QuarticExtension`

And likewise for `CrandallQuadraticField`.

There are a few parameters which we can't automatically derive (in const Rust), so I specified them in a `AutoExtendable` trait.

This would make it fairly easy to add extension fields for `GoldilocksField` and any future fields.

* Attempt to derive 2-adicity, see Hamish's feedback

* Simplify TWO_ADICITY based on chat with Hamish

* PR feedback

* Merge AutoExtendable into Extendable (#235)
2021-09-13 11:45:17 -07:00
Daniel Lubarov
c76eb9ddeb
Prepare for the switch to Poseidon (#228)
* Prepare for the switch to Poseidon

Everything will now select a permutation based on the `PERMUTATION_FAMILY` const.

The `Poseidon` variant won't work quite yet since the gate isn't in place; I left that as a `todo!()`

* fix
2021-09-13 10:22:25 -07:00
Daniel Lubarov
7ffeba3ae4 Delete my old MDS code, now obsolete 2021-09-12 18:29:07 -07:00
Jakub Nabaglo
a8d08aa153
Vectorized FFT (#223)
* Vectorized FFT

* Cleanup

* Use updated FieldPacking

* Use to_vec/from_slice (+ typo)

* Cleanup + Daniel's comments
2021-09-12 16:54:25 -07:00
Jakub Nabaglo
bdd86a306f
Crandall squaring in AVX2 (#233) 2021-09-11 17:47:17 -07:00
Daniel Lubarov
ba8b40f0e6
Goldilocks field (#227)
* Goldilocks field

Based on Hamish's old branch, but I updated it with a few missing things like generators.

Pulled the inversion code into a shared helper method to avoid redundancy.

Just the base field for now. We can add a quartic extension field later.

* typo

* PR feedback

* More overflowing -> wrapping

* fmt

* cleanup
2021-09-10 10:39:27 -07:00
Jakub Nabaglo
e50d79a347 Tweaks to CrandallField::product 2021-09-08 17:15:56 -07:00
Jakub Nabaglo
3674ceb571 Lints 2021-09-08 12:15:25 -07:00
Jakub Nabaglo
db3171bb81 Conversion to/from statically-sized arrays 2021-09-08 12:15:25 -07:00
Jakub Nabaglo
5d69d85d42 Daniel PR comments + delete throughput figures 2021-09-08 12:15:25 -07:00
Jakub Nabaglo
87f5201e6f Style (incl. Daniel PR comments) 2021-09-08 12:15:25 -07:00
Jakub Nabaglo
7ee7d8bf8a Crandall arithmetic in AVX2 2021-09-08 12:15:25 -07:00
Daniel Lubarov
3bc34c59d8
Refactor GMiMC code (#224)
* Refactor GMiMC code

Adds a sub-trait of `Field` called `GMiMCInterface`, which is similar to `PoseidonInterface`.

This lets us have different fields with different GMiMC constants in a type-safe way.

* Remove `Interface`

* Const generic for width
2021-09-07 18:28:28 -07:00
Daniel Lubarov
a2eaaceb34
Rework the field test code a bit (#225)
- Split it into two files, one for general `Field` tests and one for `PrimeField` tests.
- Replace most uses of `BigUint` in tests with `u64`. These uses were only applicable for `PrimeField`s, which are 64-bit fields anyway. This lets us delete the `BigUInt` conversion methods.
- Simplify `test_inputs`, which was originally written for large prime fields. Now that it's only used for 64-bit fields, I think interesting inputs are just the smallest and largest elements, and those close to 2^32 etc.
2021-09-07 14:17:15 -07:00
Daniel Lubarov
676c244de7 Unused field 2021-09-06 17:01:15 -07:00
Daniel Lubarov
a42bec0354 cargo fix 2021-09-05 22:36:10 -07:00
Daniel Lubarov
236a143abf
Move some Field members to a Field64 subtrait (#213)
* Move some Field members to a Field64 subtrait

I.e. move anything specific to 64-bit fields.

Also, relatedly,
- Tweak a bunch of prover code to require `Field64`, since 64-bit stuff is used in a couple places, like the FRI proof-of-work
- Remove `bits()`, which was unused and assumed a 64-bit field
- Rename a couple methods to reflect that they're u64 variants

There are no functional changes.

* Field64 -> PrimeField

* Remove `exp_u32`, `kth_root_u32`

* PrimeField: PrimeField

* Move `to_canonical_biguint` as well

* Add back from_noncanonical_u128
2021-09-05 10:27:11 -07:00
Jakub Nabaglo
032e2feeb4 Daniel comments 2021-09-03 17:19:48 -07:00
Jakub Nabaglo
ec0195c8eb PackedField trait 2021-09-03 17:19:48 -07:00
Hamish Ivey-Law
92bc65a6b5
Native Poseidon implementation(s) (#207)
* Simplify and refactor GMiMC benchmark.

* Refactor/combine GMiMC and Rescue hash benchmarks.

* Remove old Rescue bench; rename GMiMC bench.

* Add from_canonical_u128 for fields.

* Initial version of Poseidon.

* Partial implementation of fast Poseidon.

* Complete (but broken) implementation of fast partial rounds.

* Fix index calculation.

* Add basic tests.

* Fix constants; fix bugs in fast partial round calculation.

* Rename main functions.

* Add test vectors.

* Use x^7 for s-box monomial.

* Fix s-box application in fast version.

* Make WIDTH a parameter.

* Working version with both widths.

* Updated the constants so they use x^3; added test vectors.

* Expand bench_hash to cover both widths and report relative slowdown.

* Remove references to MaybeUninit.

* First draft of refactoring the two Poseidon widths.

* Tidy up use of conversion to/from raw data.

* Add some comments.

* Refactor tests.

* Apply cargo fmt changes.

* Have `Field`s implement `PoseidonInterface` (#209)

* Have `Field`s implement `PoseidonInterface`

Rather than having a sort of "dummy struct" implement `PoseidonInterface` with the field as a generic param. I think this seems more natural and type-safe.

The type safety does come at a price -- it would be harder to do dynamic things such as taking `WIDTH` as a command line option -- but I think that's alright.

* Fix missed conflicts.

* cargo fmt fixes.

* Fix to accommodate changes in latest nightly.

Co-authored-by: Hamish Ivey-Law <426294+unzvfu@users.noreply.github.com>
Co-authored-by: Hamish Ivey-Law <hamish@ivey-law.name>

* Sanity check number of rounds.

Co-authored-by: Daniel Lubarov <daniel@lubarov.com>
2021-09-01 21:45:52 +10:00
Jakub Nabaglo
1727d2c872
Batch multiplicative inverse optimizations (#210)
* Batch multiplicative inverse optimizations

* Minor style (Daniel PR comment)
2021-08-31 15:08:39 -07:00
Jakub Nabaglo
a71966f6f5
Bugfix: Crandall field addition occasionally returns incorrect results (#203)
* Fix bug that causes Crandall field addition to yield incorrect results in rare circumstances

* Minor proof correction

* Daniel PR comment
2021-08-26 12:24:18 -07:00
Daniel Lubarov
535c385643
Field: Default (#193)
* Field: Default

It's done for primitive types like `u64`, so seems conventional, and some code in mir-core expects it.

* HashOut::ZERO

* Default for HashOut

* fmt

* pub elements

* Debug

* rand_from_rng
2021-08-20 08:44:28 -07:00
Daniel Lubarov
c31c06d227
FFT/LDE benches (#188)
And expose FftStrategy so we can bench both
2021-08-18 08:36:40 -07:00
wborgeaud
561228103f More scalar muls 2021-08-17 10:26:31 +02:00
Daniel Lubarov
f3bfd66657
Add a BoolTarget (#179)
It's just a wrapper around `Target`, which signifies that the wrapped `Target` has already been range checked. Should make it easier to audit code that expects bools.
2021-08-14 08:53:39 -07:00
wborgeaud
4433fd8048 Merge branch 'main' into optimize_arithmetic_ops 2021-08-10 09:11:08 +02:00
Daniel Lubarov
b89f4d656d
Update various dependencies (#163) 2021-08-09 10:11:42 -07:00
Daniel Lubarov
3eacd53b30
PolynomialBatchCommitment tweaks (#164)
Very minor things:
- A few renames
- Instead of having two constructors call a third constructor, just have one constructor call the other.
- Invoke FFT with the option that specifies the inputs are mostly zero, as a (minor) optimization
- Remove unused field
2021-08-09 10:11:35 -07:00
wborgeaud
4b44578ffa More optimizations 2021-08-09 12:39:37 +02:00
wborgeaud
eeb33f99ca Optimize mul_ext_algebra 2021-08-09 11:30:03 +02:00
Daniel Lubarov
2d9891983f
Add a reduce_polys_base (#149)
* Add a reduce_polys_base

Reducing the polynomials in `open_plonk` was taking ~100ms on my machine. It was converting BF polynomials to the EF early on; by doing more work in the BF we can reduce it to ~20ms.

* PR feedback
2021-08-03 13:00:50 -07:00
Daniel Lubarov
5c96e7b366 Trivial fixes from "cargo fix" 2021-08-02 10:58:03 -07:00
Daniel Lubarov
50b07f2ceb
Special cases for extension field arithmetic (#138)
We previously checked for special cases, like arithmetic on constant Targets, in `arithmetic`. We can handle those cases without actually adding an `ArithmeticGate`.

Now that `arithmetic` just calls `arithmetic_extension`, it makes more sense to check for special cases in the latter method, so it applies to both base and extension field arithmetic.

Reduces gate count from 16149 to 15689.
2021-07-30 09:03:11 -07:00
Daniel Lubarov
018fb005f8
Move stuff around (#135)
No functional changes here. The biggest change was moving certain files into new directories like `plonk` and `iop` (for things like `Challenger` that could be used in STARKs or other IOPs). I also split a few files, renames, etc, but again nothing functional, so I don't think a careful review is necessary (just a sanity check).
2021-07-29 22:00:29 -07:00
Daniel Lubarov
e382decc9f Import fixes 2021-07-29 11:45:58 -07:00
wborgeaud
8f18089aac Implement eval_unfiltered_recursively for ReducingGate 2021-07-23 18:06:14 +02:00
Nicholas Ward
0af5c3bdb8 addressed nit 2021-07-22 14:49:24 -07:00