-
Notifications
You must be signed in to change notification settings - Fork 22
feat: add pk_trfv_generation_circuit to zk-prover #1281
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7faf59b
feat: add pk_trfv_generation_circuit to zk-prover
ctrlc03 039ce6b
chore: add missing license
ctrlc03 c3d3a9d
chore: update vk and complete tests
ctrlc03 ea011a5
chore: refactor structure
ctrlc03 2ef451a
chore: lint
ctrlc03 a89bfa8
chore: rename
ctrlc03 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| // SPDX-License-Identifier: LGPL-3.0-only | ||
| // | ||
| // This file is provided WITHOUT ANY WARRANTY; | ||
| // without even the implied warranty of MERCHANTABILITY | ||
| // or FITNESS FOR A PARTICULAR PURPOSE | ||
|
|
||
| mod pk; |
|
ctrlc03 marked this conversation as resolved.
ctrlc03 marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| // SPDX-License-Identifier: LGPL-3.0-only | ||
| // | ||
| // This file is provided WITHOUT ANY WARRANTY; | ||
| // without even the implied warranty of MERCHANTABILITY | ||
| // or FITNESS FOR A PARTICULAR PURPOSE. | ||
|
|
||
| mod pk_generation; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| // SPDX-License-Identifier: LGPL-3.0-only | ||
| // | ||
| // This file is provided WITHOUT ANY WARRANTY; | ||
| // without even the implied warranty of MERCHANTABILITY | ||
| // or FITNESS FOR A PARTICULAR PURPOSE | ||
|
|
||
| use crate::circuits::utils::{crt_polynomial_to_array, polynomial_to_input_value}; | ||
| use crate::error::ZkError; | ||
| use crate::traits::Provable; | ||
| use e3_events::CircuitName; | ||
| use e3_fhe_params::BfvPreset; | ||
| use e3_zk_helpers::circuits::threshold::pk_generation::circuit::{ | ||
| PkGenerationCircuit, PkGenerationCircuitInput, | ||
| }; | ||
| use e3_zk_helpers::circuits::threshold::pk_generation::computation::Witness; | ||
| use e3_zk_helpers::Computation; | ||
| use noirc_abi::InputMap; | ||
| use std::collections::BTreeMap; | ||
|
|
||
| impl Provable for PkGenerationCircuit { | ||
| type Params = BfvPreset; | ||
| type Input = PkGenerationCircuitInput; | ||
|
|
||
| fn circuit(&self) -> CircuitName { | ||
| CircuitName::PkGeneration | ||
| } | ||
|
|
||
| fn build_witness( | ||
| &self, | ||
| preset: &Self::Params, | ||
| input: &Self::Input, | ||
| ) -> Result<InputMap, ZkError> { | ||
| let witness = Witness::compute(preset.clone(), &input) | ||
| .map_err(|e| ZkError::WitnessGenerationFailed(e.to_string()))?; | ||
|
|
||
| let mut inputs = BTreeMap::new(); | ||
| inputs.insert("a".into(), crt_polynomial_to_array(&witness.a)?); | ||
| inputs.insert("eek".into(), polynomial_to_input_value(&witness.eek)?); | ||
| inputs.insert("sk".into(), polynomial_to_input_value(&witness.sk)?); | ||
| inputs.insert("e_sm".into(), crt_polynomial_to_array(&witness.e_sm)?); | ||
| inputs.insert("r1is".into(), crt_polynomial_to_array(&witness.r1is)?); | ||
| inputs.insert("r2is".into(), crt_polynomial_to_array(&witness.r2is)?); | ||
| inputs.insert("pk0is".into(), crt_polynomial_to_array(&witness.pk0is)?); | ||
| inputs.insert("pk1is".into(), crt_polynomial_to_array(&witness.pk1is)?); | ||
|
|
||
| Ok(inputs) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| // SPDX-License-Identifier: LGPL-3.0-only | ||
| // | ||
| // This file is provided WITHOUT ANY WARRANTY; | ||
| // without even the implied warranty of MERCHANTABILITY | ||
| // or FITNESS FOR A PARTICULAR PURPOSE | ||
|
|
||
| use std::collections::BTreeMap; | ||
|
|
||
| use crate::error::ZkError; | ||
| use acir::FieldElement; | ||
| use e3_polynomial::{CrtPolynomial, Polynomial}; | ||
| use noirc_abi::input_parser::InputValue; | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| pub fn crt_polynomial_to_array(crt_poly: &CrtPolynomial) -> Result<InputValue, ZkError> { | ||
| let mut polynomials = Vec::with_capacity(crt_poly.limbs.len()); | ||
|
|
||
| for limb in &crt_poly.limbs { | ||
| let coeffs = limb.coefficients(); | ||
| let mut field_coeffs = Vec::with_capacity(coeffs.len()); | ||
|
|
||
| for b in coeffs { | ||
| let s = b.to_string(); | ||
| let field = FieldElement::try_from_str(&s).ok_or_else(|| { | ||
| ZkError::SerializationError(format!("invalid field element: {}", s)) | ||
| })?; | ||
| field_coeffs.push(InputValue::Field(field)); | ||
| } | ||
|
|
||
| let mut fields = BTreeMap::new(); | ||
| fields.insert("coefficients".to_string(), InputValue::Vec(field_coeffs)); | ||
| polynomials.push(InputValue::Struct(fields)); | ||
| } | ||
|
|
||
| Ok(InputValue::Vec(polynomials)) | ||
| } | ||
|
|
||
| pub fn polynomial_to_input_value(poly: &Polynomial) -> Result<InputValue, ZkError> { | ||
| let coeffs = poly.coefficients(); | ||
| let mut field_coeffs = Vec::with_capacity(coeffs.len()); | ||
|
|
||
| for b in coeffs { | ||
| let s = b.to_string(); | ||
| let field = FieldElement::try_from_str(&s) | ||
| .ok_or_else(|| ZkError::SerializationError(format!("invalid field element: {}", s)))?; | ||
| field_coeffs.push(InputValue::Field(field)); | ||
| } | ||
|
|
||
| let mut fields = BTreeMap::new(); | ||
| fields.insert("coefficients".to_string(), InputValue::Vec(field_coeffs)); | ||
| Ok(InputValue::Struct(fields)) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
ctrlc03 marked this conversation as resolved.
|
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.