56 Commits

Author SHA1 Message Date
Daniel Lubarov
43cbb84cc9
Have verify_merkle_proof call permute_swapped (#257)
Rather than adding the gate "manually".
2021-09-21 12:29:37 -07:00
wborgeaud
5d8241760f
Merge pull request #255 from mir-protocol/better_compressed_merkle_paths
Simpler Merkle paths compression
2021-09-21 08:56:34 +02:00
wborgeaud
391759479e PR feedback 2021-09-21 08:37:23 +02:00
Jakub Nabaglo
1369dd7c76
Many small optimizations to scalar Poseidon (#253)
* Many small optimizations

* Lints

* Hamish comments

* Inlining
2021-09-20 10:52:12 -07:00
wborgeaud
1f42916bfc Comments 2021-09-20 17:58:25 +02:00
wborgeaud
36e4d3608d Working (de)compression for FRI proofs 2021-09-20 17:34:52 +02:00
Daniel Lubarov
471ace6d85
Remove loop unrolling in a few more places where it doesn't seem important (#254)
LLVM will do some unrolling/inlining, but I think we should only force it in places we know it's really justified.
2021-09-20 07:50:00 -07:00
wborgeaud
422e72954c Working path (de)compression 2021-09-20 14:37:28 +02:00
wborgeaud
0be8650bca PR feedback 2021-09-18 09:23:39 +02:00
wborgeaud
b8f6b3a778 Merge branch 'main' into poseidon_gate 2021-09-18 08:55:54 +02:00
Jakub Nabaglo
d3de2b5518 Fix alignment assumptions in AVX2 Poseidon 2021-09-17 10:04:05 -07:00
wborgeaud
14bbf5ae11 Fix AVX2 conflict 2021-09-17 17:50:43 +02:00
wborgeaud
f83c587cc5 Comments 2021-09-17 13:47:08 +02:00
wborgeaud
e418997d6f Cleanup 2021-09-17 13:29:59 +02:00
wborgeaud
5488be2acd Add HashGate constant type 2021-09-17 13:15:22 +02:00
wborgeaud
3534018fec Remove hardcoded GMiMC 2021-09-16 22:19:54 +02:00
wborgeaud
b63d83aacf Add Poseidon gadget 2021-09-16 21:18:08 +02:00
wborgeaud
5d7f4de2a6 Working recursively 2021-09-16 19:17:37 +02:00
wborgeaud
b11e54d6ed Semi-working 2021-09-16 17:51:07 +02:00
Daniel Lubarov
151d1f1d84
Constants for Goldilocks & binary to generate them (#247)
* Constants for Goldilocks etc

* Fix typo
2021-09-15 19:48:30 -07: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
b411a275f9
AVX2 vectorization of Poseidon S-box (#244)
* AVX2 vectorization of Poseidon S-box

* Minor doc

* Microoptimization
2021-09-14 19:26:31 -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
de1d5d0ad2
Minor: fix a few warnings (#239)
* Minor: fix a few warnings

* Lints
2021-09-13 15:42:59 -07:00
Jakub Nabaglo
9ef784a99d
Poseidon: vectorized MDS matrix multiplication (NEON) (#231)
* Port of AVX2 MDS impl

* Bugfixes

* Inline ASM to the rescue

* remove debug printsln + minor formatting

* Work around NEON intrinsic bug without inline ASM

* Minor error in doc

* Daniel comments

* More Daniel comments

Co-authored-by: Jakub Nabaglo <jakub@mirprotocol.org>
2021-09-13 12:36:06 -07:00
Jakub Nabaglo
6465e35e1f
Poseidon: vectorized MDS matrix multiplication (AVX2) (#229)
* Poseidon: vectorized MDS matrix multiplication

* Lints

* This is a bit cleaner

* More cleanup

* Width 12

* Replace the unaligned load trick with something nicer

* Simplify conversion between CrandallField and u64

* Make things more concise with const generics

* Minor documentation

* Minor: unused import

* Daniel comments + consistency with #230 + errors in docs

* Remove dependence on feature(stdsimd)

* Daniel comments
2021-09-13 11:46:36 -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
Jakub Nabaglo
c0e8edb899
Non-vector Poseidon speedups (#230) 2021-09-11 11:25:20 -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
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
Daniel Lubarov
ba4b03e487
Unroll a couple loops in Poseidon code (#215)
* Unroll a couple loops in Poseidon code (super hacky)

* Comments
2021-09-03 21:42:40 -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
wborgeaud
d01d206524 Remove named connects 2021-08-24 18:20:47 +02:00
wborgeaud
69a945547a route, assert_equal -> connect 2021-08-24 08:25:11 +02:00
wborgeaud
cd1bd9e77b
Merge pull request #195 from mir-protocol/partition_witness
Remove `CopyGenerator`s and add new `PartitionWitness`
2021-08-24 08:16:35 +02:00
wborgeaud
bc3eb856f2 Remove remaining reverse_bits 2021-08-23 11:57:35 +02: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
wborgeaud
507577b7ad Comments 2021-08-20 12:55:59 +02:00
wborgeaud
a90ea6ec79 PartialWitness back to HashMap 2021-08-20 11:56:57 +02:00
wborgeaud
a44bf9ffd8 Added witness trait 2021-08-20 09:50:07 +02:00
Daniel Lubarov
90c7a72ceb
Remove some unused warnings (#192)
- Made some methods public, if they seemed like they'd be useful crates that depend on plonky2, and seemed like good/stable APIs
- Deleted a few things I didn't think seemed very useful
- Left a few for now that I was on the fence about
2021-08-19 08:23:45 -07:00
wborgeaud
291e67bec5 Remove reverse_bits flag in Merkle trees 2021-08-18 14:32:24 +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
Daniel Lubarov
9c42fef997
Little refactor (#178) 2021-08-14 08:47:03 -07:00
wborgeaud
9c01e1d942 PR feedback 2021-08-11 08:33:58 +02:00
wborgeaud
9f004c9664 Clippy 2021-08-10 16:18:42 +02:00
wborgeaud
e73c1d7769 Cleaning / Renaming 2021-08-10 15:53:27 +02:00
wborgeaud
ec1147848a Minor 2021-08-10 15:05:21 +02:00
wborgeaud
684df1e057 Pass cap index 2021-08-10 15:03:29 +02:00
wborgeaud
57f2b5b763 working 2021-08-10 13:52:50 +02:00