Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Combine coefficient polynomials #168

Merged
merged 17 commits into from
Oct 12, 2021
Merged

Conversation

imeckler
Copy link
Contributor

@imeckler imeckler commented Oct 5, 2021

Right now, for poseidon and generic gates, we have in the index

  • 15 polynomials for poseidon round constants
  • 1 selector polynomial for poseidon
  • 5 polynomials for generic gate coefficients (3 for linear terms, 1 for multiplication term, 1 for constant term)

This PR changes this set-up to have

  • 15 polynomials for "coefficients", values that can be used by any gates. In poseidon rows these are the round constants, in generic rows, these are the coefficients as described above for the first 5, 0 for the rest).
  • 1 selector polynomial for poseidon
  • 1 selector polynomial for generic gates

So overall, this eliminates 4 polynomials, and correspondingly removes 4 commitments from verification keys. On the other hand, the change necessitates the addition of evaluations for the poseidon and generic selector polynomials, adding (1 + 1)*(2 evaluation points) = 4 evaluations to the proofs. I think this could probably reduced to making it so we only need to evaluate one additional polynomial with some more work if we want.

Base automatically changed from mimoo/15-wire-plonk-fixes-3 to master October 7, 2021 17:38
@mimoo mimoo self-requested a review October 7, 2021 19:08
Copy link
Contributor

@mimoo mimoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! So we decrease key/index size (and I guess verifier runtime), but increase proof size (of ~1KB) IIUC.

I think this could probably reduced to making it so we only need to evaluate one additional polynomial with some more work if we want.

What do you have in mind?

@@ -9,9 +9,11 @@ use crate::wires::{GateWires, COLUMNS, GENERICS};
use ark_ff::FftField;
use array_init::array_init;

pub const MUL_COEFF: usize = GENERICS;
pub const CONSTANT_COEFF: usize = GENERICS + 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is great. Also "index" more than "coeff" no?

@@ -28,7 +30,7 @@ impl<F: FftField> CircuitGate<F> {
pub fn create_generic_add(row: usize, wires: GateWires) -> Self {
let on = F::one();
let off = F::zero();
let qw: [F; COLUMNS] = array_init(|col| {
let qw: [F; GENERICS] = array_init(|col| {
if col < 2 {
on
Copy link
Contributor

@mimoo mimoo Oct 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw this function is missing the fact that you can scale the operand freely, which I didn't think about back when I wrote that.

impl<F: FftField> CircuitGate<F> {
// TODO(mimoo): why qw is length 15 if the polynomial side only uses 3?
pub fn create_generic(row: usize, wires: GateWires, qw: [F; COLUMNS], qm: F, qc: F) -> Self {
pub fn create_generic(row: usize, wires: GateWires, qw: [F; GENERICS], qm: F, qc: F) -> Self {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had meant to look into why it was set to the full columns, thanks for fixing that!


// return in lagrange and monomial form for optimization purpose
let eval_part = &multiplication + &wires;
let poly_part = &self.qc + public;
let poly_part = public.clone();
(eval_part, poly_part)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the poly part is now just the public polynomial, then let's not pass the public argument and return the poly_part in this function :o wdyt?

} else {
F::zero()
}
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one-liner:

gate.c.get(i).unwrap_or(F::zero())

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting, maybe it'd be good to document somewhere that if you need static coefficients for your gate, you should use the coefficient polynomials/commitments

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually the one liner doesn't work because you get a borrow from get. I guess you could make it work by mapping but seemed kind more awkward than this to me

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gate.c.get(i).copied().unwrap_or(F::zero()) ?

/// coefficient commitment array
pub coefficients_comm: [PolyComm<G>; COLUMNS],
/// coefficient commitment array
pub generic_comm: PolyComm<G>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@codecov-commenter
Copy link

Codecov Report

Merging #168 (c40c3c8) into master (34e0c85) will decrease coverage by 0.02%.
The diff coverage is 98.01%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #168      +/-   ##
==========================================
- Coverage   86.86%   86.84%   -0.03%     
==========================================
  Files          74       74              
  Lines       15669    15639      -30     
==========================================
- Hits        13611    13581      -30     
  Misses       2058     2058              
Impacted Files Coverage Δ
circuits/plonk-15-wires/src/gates/generic.rs 89.18% <91.66%> (-0.67%) ⬇️
circuits/plonk-15-wires/src/polynomials/generic.rs 90.16% <96.66%> (+0.54%) ⬆️
...ircuits/plonk-15-wires/src/nolookup/constraints.rs 95.90% <100.00%> (-0.49%) ⬇️
circuits/plonk-15-wires/src/nolookup/scalars.rs 100.00% <100.00%> (ø)
...ircuits/plonk-15-wires/src/polynomials/poseidon.rs 100.00% <100.00%> (ø)
dlog/plonk-15-wires/src/index.rs 92.30% <100.00%> (-0.55%) ⬇️
dlog/plonk-15-wires/src/prover.rs 98.78% <100.00%> (+0.03%) ⬆️
dlog/plonk-15-wires/src/verifier.rs 90.48% <100.00%> (-0.03%) ⬇️
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 34e0c85...c40c3c8. Read the comment docs.

@imeckler imeckler merged commit 70065b3 into master Oct 12, 2021
@imeckler imeckler deleted the combine-coefficient-polynomials branch October 12, 2021 00:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants