0xpolygonzero / plonky Goto Github PK
View Code? Open in Web Editor NEWRecursive SNARKs based on Plonk and Halo
Recursive SNARKs based on Plonk and Halo
For sufficiently large numbers, squaring a number can be made up to ~40% faster than simply multiplying it with itself (for example, see here). We should investigate whether we can obtain some performance benefit for numbers of the size used in Plonky.
Note that the existing Montgomery modmul implementation is CIOS (i.e. interleaves multiplication and reduction). To implement fast squaring we first need Montogomery REDC and we lose the (mild) performance benefits of CIOS layout.
We can combine the fast squaring method with modular reduction with the CIOS layout in a fairly straight forward manner. This is mentioned (but not explained) in Acar's thesis, Section 2.3. Another useful reference is this post by the Goff developers (that also includes a cute trick to skip some additions for some moduli).
I run the test_proof_trivial_recursive() test on the master branch, but get syntactic errors as follows:
cargo test --color=always --no-run --package plonky --test prove_and_verify_recursive test_proof_trivial_recursive -- --exact
Compiling plonky v0.1.0
warning: unused import: std::collections::HashSet
--> src/field/field.rs:3:5
|
3 | use std::collections::HashSet;
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: #[warn(unused_imports)]
on by default
error[E0277]: arrays only have std trait implementations for lengths 0..=32
--> src/bigint/bigint_arithmetic.rs:53:50
|
53 | debug_assert!(!borrow, "a < b: {:?} < {:?}", a, b);
| ^ the trait std::array::LengthAtMost32
is not implemented for [u64; N]
|
= note: required because of the requirements on the impl of std::fmt::Debug
for [u64; N]
= note: required by std::fmt::Debug::fmt
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: arrays only have std trait implementations for lengths 0..=32
--> src/bigint/bigint_arithmetic.rs:53:53
|
53 | debug_assert!(!borrow, "a < b: {:?} < {:?}", a, b);
| ^ the trait std::array::LengthAtMost32
is not implemented for [u64; N]
|
= note: required because of the requirements on the impl of std::fmt::Debug
for [u64; N]
= note: required by std::fmt::Debug::fmt
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound &mut [{integer}; N]: std::iter::IntoIterator
is not satisfied
--> src/bigint/bigint_arithmetic.rs:108:23
|
108 | for limb_i in &mut limbs {
| ^^^^^^^^^^ the trait std::iter::IntoIterator
is not implemented for &mut [{integer}; N]
|
= help: the following implementations were found:
<&'a [T; N] as std::iter::IntoIterator>
<&'a [T] as std::iter::IntoIterator>
<&'a mut [T; N] as std::iter::IntoIterator>
<&'a mut [T] as std::iter::IntoIterator>
= note: required by std::iter::IntoIterator::into_iter
error[E0369]: binary operation !=
cannot be applied to type [u64; N]
--> src/bigint/bigint_inverse.rs:18:13
|
18 | while u != one && v != one {
| - ^^ --- [u64; N]
| |
| [u64; N]
error[E0369]: binary operation !=
cannot be applied to type [u64; N]
--> src/bigint/bigint_inverse.rs:18:25
|
18 | while u != one && v != one {
| - ^^ --- [u64; N]
| |
| [u64; N]
error[E0369]: binary operation ==
cannot be applied to type [u64; N]
--> src/bigint/bigint_inverse.rs:50:10
|
50 | if u == one {
| - ^^ --- [u64; N]
| |
| [u64; N]
error: aborting due to 6 previous errors; 1 warning emitted
Some errors have detailed explanations: E0277, E0369.
For more information about an error, try rustc --explain E0277
.
error: could not compile plonky
.
There are a few existing open Montgomeral modmul implementations which might (i) form a good/better basis for our improvements in Plonky, or (ii) in any case, they should at least give some ideas for improvements that we might not have thought of. We are initially interested in the Rust implementation; assembly implementation will come later.
Some implementations to consider:
There is currently a fair amount of copy-pasta between the different base field implementations (e.g. here, here and here). This should be factored out, so as to more clearly and conveniently accommodate the coming implementations and specialisations.
NB: Need to be careful to maintain the performance advantages that some of those implementations have from inlining and specialisation.
In a comment on #68, it was noted that the value of the constant ORDER[2]
for the Tweedle* curves is zero, and so the compiler should simplify/eliminate arithmetic involving that value. This should be verified over at https://godbolt.org.
There are several ways to vectorise modular multiplication (see Section 4 of this article for example). In some cases we may be able to write high-level code from which the compiler will generate SSE or AVX instructions; in other cases we may have to write the assembly ourselves.
Before embarking on refactoring (#68), we need a more thorough test suite for finite field arithmetic. Many of the existing tests only test internal consistency, and that only wrt randomly generated inputs. A more thorough test suite will read in a fixed set of independently generated inputs and outputs (so the tests are repeatable) that have been more deliberately chosen (so we know we hit boundary cases).
The base field moduli used with elliptic curves are often chosen to be of the form 2^b + c for some small c; this is the case for the Tweedledee/Tweedledum curves, for example. We can exploit this form of modulus to speed up the reduction algorithm.
The two Tweedle curves have almost identical implementations. There should be a cleaner way to express that; I'm thinking something like a 'Montgomery256' trait that provides Montgomery representation and arithmetic for moduli up to 256 bits.
This issue follows on from #68.
Hi! I wanted to try plonky but I am unable to run the benchmarks properly. The "Generating inner proof" part takes forever to finish, and the part "generating the recursion circuit" always panics and fails with the following error (running on Ubuntu18.04 with 8GB RAM, Intel i7-9750H 2.6GHz):
Generating inner circuit
Finished in 156.286423678sGenerating inner witness
Finished in 0.366971488sGenerating inner proof
Finished in 2920.980774765sVerifying inner proof
Finished in 75.733380387sGenerating recursion circuit...
thread 'main' panicked at 'index out of bounds: the len is 0 but the index is 4', /home/workspace/plonky/src/plonk_recursion.rs:460:19
I saw you were mentioning on https://www.plonk.cafe/t/plonky-recursive-proofs-based-on-plonk-and-halo/63 that you were obtaining benchmarks of 10 sec for verifier circuit of size 2^14, how did you get those results? I saw also that the test test_proof_trivial_recursive()
in tests/prove_and_verify_recursive.rs was flawky and hence disabled, would that be linked to it? Thanks!
PR #100 introduced some duplication in the tests for curves and fields. These should be refactored.
It can be advantageous to leave a few bits of space in the representation of an element of a base field and to allow a certain number of overflows into that space during calculations. This can reduce branching, carry-chain dependencies, and, most importantly, the number of modular reductions in arithmetic operations.
In order to measure performance improvements, and protect against performance regressions (while refactoring, for example, see #68), we should measure the performance of the current field arithmetic implementations in a way that makes it easy to compare to future performance measurements. The (already in use) Criterion crate seems to cover this functionality, at least for micro-benchmarks such as field operations.
In Fast recursive arguments based on Plonk and Halo, “Explicit formulae” section,are
Implement types for the Pasta curves (reference).
These will likely supersede the Tweedle curves, but they can happily live side-by-side to begin with.
Carry chains in field arithmetic are a significant source of data dependency which can cause pipeline stalls and bubbles. In some cases instead of handling carries at their source we can accumulate and defer treatment until later. We should identify places where this is possible. Possibly most applicable in the context of #72.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.