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

Optional zero-knowledge by const generic #76

Conversation

han0110
Copy link

@han0110 han0110 commented Jun 2, 2022

This PR aims to extend halo2 to allow developers to enable/disable zero-knowledge with const generic const ZK: bool.

Protocol adjustment for non-ZK

Notations are following the ones used in halo2 book.

Blinding factors

The final max(3, max(num_advice_queries)) + 2 rows of every advice column, including permuted columns in lookup argument, and grand-product columns in lookup and permutation argument, are loaded with random blinding factors, which aims for zero knowledge.

When we turn off zero-knowledge, we don't need to reserve these final rows, then all rows are usable.

Lookup argument

Currently the constraints of lookup argument are:

  • $\ell_0(X) \cdot (1 - Z(X))$
  • $q_{last}(X) \cdot (Z(X)^2 - Z(X))$
  • $(1 - (q_{last}(X) + q_{blind}(X))) \cdot (Z(\omega X)\cdot(A^\prime(X) + \beta)\cdot(S^\prime(X) + \gamma) - Z(X)\cdot(A(X) + \beta)\cdot(S(X) + \gamma))$
  • $\ell_0(X) \cdot (A^\prime(X) - S^\prime(X))$
  • $(1 - (q_{last}(X) + q_{blind}(X))) \cdot (A^\prime(X) - S^\prime(X)) \cdot (A^\prime(X) - A^\prime(\omega^{-1}X))$

When we turn off zero-knowledge, the constraints could be simplified to the orange parts only:

  • $\color{orange}{\ell_0(X) \cdot (1 - Z(X))}$
  • $\color{darkgray}{q_{last}(X) \cdot (Z(X)^2 - Z(X))}$
  • $\color{darkgray}{(1 - (q_{last}(X) + q_{blind}(X))) \cdot(}\color{orange}{Z(\omega X)\cdot(A^\prime(X) + \beta)\cdot(S^\prime(X) + \gamma) - Z(X)\cdot(A(X) + \beta)\cdot(S(X) + \gamma)}\color{darkgray}{)}$
  • $\color{darkgray}{\ell_0(X) \cdot (A^\prime(X) - S^\prime(X))}$
  • $\color{darkgray}{(1 - (q_{last}(X) + q_{blind}(X))) \cdot}\color{orange}{(A^\prime(X) - S^\prime(X)) \cdot (A^\prime(X) - A^\prime(\omega^{-1}X))}$

Permutation argument

Currently the constraints of permutation argument are:

  • $\ell_0(X) \cdot (1 - Z_{P,0}(X))$
  • $q_{last}(X) \cdot (Z_{P,b}(X)^2 - Z_{P,b}(X))$
  • $\text{For}\ 0 < a < b$
    • $\ell_0(X) \cdot (Z_{P,a}(X) - Z_{P,a-1}(\omega^\mu X))$
  • $\text{For}\ 0 \le a < b$
    • $(1 - (q_{last}(X) + q_{blind}(X))) \cdot \Big(Z_{P,a}(\omega X) \cdot \prod\limits_{i=am}^{(a+1)m-1}(v_i(X) + \beta \cdot s_i(X) + \gamma) - Z_{P,a}(X) \cdot \prod\limits_{i=am}^{(a+1)m-1}(v_i(X) + \beta \cdot \delta^i \cdot X + \gamma)\Big)$

When we turn off zero-knowledge, the constraints could be simplified to the orange parts only:

  • $\text{If}\ m \le d-1, \text{then}\ b = 1$
    • $\color{orange}{\ell_0(X) \cdot (1 - Z_{P,0}(X))}$
    • $\color{darkgray}{q_{last}(X) \cdot (Z_{P,b}(X)^2 - Z_{P,b}(X))}$
    • $\color{darkgray}{\text{For}\ 0 < a < b}$
      • $\color{darkgray}{\ell_0(X) \cdot (Z_{P,a}(X) - Z_{P,a-1}(\omega^\mu X))}$
    • $\color{orange}{\text{For}\ 0 \le a < b}$
      • $\color{darkgray}{(1 - (q_{last}(X) + q_{blind}(X))) \cdot \Big(}\color{orange}{Z_{P,a}(\omega X) \cdot \prod\limits_{i=am}^{(a+1)m-1}(v_i(X) + \beta \cdot s_i(X) + \gamma) - Z_{P,a}(X) \cdot \prod\limits_{i=am}^{(a+1)m-1}(v_i(X) + \beta \cdot \delta^i \cdot X + \gamma)}\color{darkgray}{\Big)}$
  • $\text{Otherwise}$
    • $\color{orange}{\ell_0(X) \cdot (1 - Z_{P,0}(X))}$
    • $\color{darkgray}{q_{last}(X) \cdot (Z_{P,b}(X)^2 - Z_{P,b}(X))}$
    • $\color{darkgray}{\text{For}\ 0 < a < b}$
      • $\color{darkgray}{\ell_0(X) \cdot (Z_{P,a}(X) - Z_{P,a-1}(\omega^\mu X))}$
    • $\color{orange}{\text{For}\ 0 \le a < b}$
      • $\color{darkgray}{(1 - (q_{last}(X) + q_{blind}(X))) \cdot \Big(}\color{red}{(}\color{orange}{Z_{P,a}(\omega X)}\color{red}{ + q_{last}(X) \cdot (Z_{P,a+1}(\omega X) - Z_{P,a}(\omega X)))}\color{orange}{ \cdot \prod\limits_{i=am}^{(a+1)m-1}(v_i(X) + \beta \cdot s_i(X) + \gamma) - Z_{P,a}(X) \cdot \prod\limits_{i=am}^{(a+1)m-1}(v_i(X) + \beta \cdot \delta^i \cdot X + \gamma)}\color{darkgray}{\Big)}$

Where the red part is adjustment to make all rows copyable.

Vanishing argument

Currently we add a random polynomial in the vanishing argument to reveal nothing about $h(X)$. When we turn off zero-knowledge, it's on longer needed.

@kilic kilic force-pushed the abstraction branch 2 times, most recently from a69d136 to 949b54f Compare June 2, 2022 13:36
@CPerezz
Copy link
Member

CPerezz commented Jun 2, 2022

Would be also nice to simulate an upstream rebase to see how git faces this changes.

Just to prevent insane workloads when rebasing in the future.

@han0110 han0110 force-pushed the feature/optional-zk-by-const-generic-with-default branch from f89003e to 81491bb Compare June 3, 2022 01:55
Copy link
Member

@CPerezz CPerezz left a comment

Choose a reason for hiding this comment

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

Looks great atm!

Not a big fan of doing a const-associated ZK property as mentioned in the previous issues as it makes the code much harder when a feature would had been much simpler. Or maybe even a trait.

Anyway, it seems it has been decided to go towards this solution which looks fine.

Just left a couple of comments and will approve once the sha256.rs benches and the cost-model.rs errors and warnings are fixed :)

halo2_gadgets/benches/poseidon.rs Outdated Show resolved Hide resolved
halo2_proofs/src/plonk/circuit.rs Outdated Show resolved Hide resolved
halo2_proofs/src/plonk/vanishing/prover.rs Show resolved Hide resolved
@kilic kilic force-pushed the abstraction branch 3 times, most recently from 8cbf9b6 to e112ee4 Compare June 15, 2022 16:13
@kilic kilic mentioned this pull request Jun 16, 2022
@kilic kilic self-requested a review June 17, 2022 14:43
@kilic
Copy link

kilic commented Jun 19, 2022

@han0110 Great great work. Helped me to walk through many polynomial equations. Some points:

  1. Here we have a unique permutation folding trick and I think it should be documented more beyond a commented equation.

  2. Using the exactly same if ZK stuff I made another version that moves ZK bound from structs to required function signatures. Here. It was an experiment and not sure atm which approach would be better. But seems like it saved many structs from thisZK bound.

@CPerezz
Copy link
Member

CPerezz commented Jun 21, 2022

@han0110 are we planning to merge this?

Would be nice that the next halo2 release comes with this together with #81 #79 and #77

@han0110 han0110 force-pushed the feature/optional-zk-by-const-generic-with-default branch from ec94ed5 to 967bbe6 Compare June 23, 2022 16:25
@han0110 han0110 force-pushed the feature/optional-zk-by-const-generic-with-default branch from 967bbe6 to 55839ce Compare July 11, 2022 11:28
@han0110 han0110 changed the base branch from abstraction to feature/abstraction-squashed July 11, 2022 11:28
@han0110 han0110 changed the title Optional zero-knowledge by const generic with default Optional zero-knowledge by const generic Jul 11, 2022
@han0110 han0110 force-pushed the feature/optional-zk-by-const-generic-with-default branch from 55839ce to 44ee401 Compare July 11, 2022 11:49
@han0110 han0110 force-pushed the feature/optional-zk-by-const-generic-with-default branch from 44ee401 to 57225ee Compare July 18, 2022 17:19
@han0110 han0110 force-pushed the feature/abstraction-squashed branch from 70c11c1 to ac9839e Compare August 15, 2022 08:47
@ed255 ed255 mentioned this pull request Nov 2, 2022
@han0110 han0110 force-pushed the feature/optional-zk-by-const-generic-with-default branch from 57225ee to 51c1184 Compare November 16, 2022 02:57
@han0110 han0110 changed the base branch from feature/abstraction-squashed to main November 16, 2022 03:11
@CPerezz CPerezz self-requested a review November 18, 2022 08:13
@han0110 han0110 marked this pull request as ready for review November 22, 2022 12:18
@CPerezz CPerezz closed this Jan 10, 2023
@davidnevadoc davidnevadoc mentioned this pull request Oct 25, 2024
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.

4 participants