-
Notifications
You must be signed in to change notification settings - Fork 22
feat: add decrypted-shares-aggregation [skip-line-limit] #1273
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
10 commits
Select commit
Hold shift + click to select a range
c35e080
add share-encryption circuit gen
0xjei 5ad8c2c
port of c4
0xjei 0280291
generate_sample using the same input in user_data_enc
0xjei 925a6f2
simplify and uniform the samples
0xjei 3d91af4
port c7
0xjei 3c42d7e
format
0xjei 4c28403
minor coderabbit fixes
0xjei f9b1bc0
remove duplicated utils
0xjei 46c9b1d
add missing guard on witness computation
0xjei 530c944
conflicts
0xjei 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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
2 changes: 1 addition & 1 deletion
2
circuits/bin/threshold/decrypted_shares_aggregation_bn/Nargo.toml
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
2 changes: 1 addition & 1 deletion
2
circuits/bin/threshold/decrypted_shares_aggregation_mod/Nargo.toml
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
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
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
35 changes: 35 additions & 0 deletions
35
crates/zk-helpers/src/circuits/threshold/decrypted_shares_aggregation/circuit.rs
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,35 @@ | ||
| // 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::computation::DkgInputType; | ||
| use crate::registry::Circuit; | ||
| use crate::CiphernodesCommittee; | ||
| use e3_fhe_params::ParameterType; | ||
| use fhe_math::rq::Poly; | ||
|
|
||
| /// Circuit identifier for threshold decrypted-shares aggregation (Noir circuit 7). | ||
| #[derive(Debug)] | ||
| pub struct DecryptedSharesAggregationCircuit; | ||
|
|
||
| impl Circuit for DecryptedSharesAggregationCircuit { | ||
| const NAME: &'static str = "decrypted-shares-aggregation"; | ||
| const PREFIX: &'static str = "DECRYPTED_SHARES_AGGREGATION"; | ||
| const SUPPORTED_PARAMETER: ParameterType = ParameterType::THRESHOLD; | ||
| const DKG_INPUT_TYPE: Option<DkgInputType> = None; | ||
| } | ||
|
|
||
| /// Raw input for witness computation: decryption share polynomials from T+1 parties, | ||
| /// party IDs (1-based), and decoded message. Witness::compute runs Lagrange + CRT. | ||
| #[derive(Debug, Clone)] | ||
| pub struct DecryptedSharesAggregationCircuitInput { | ||
| pub committee: CiphernodesCommittee, | ||
| /// Decryption shares from T+1 parties (Poly in RNS form). | ||
| pub d_share_polys: Vec<Poly>, | ||
| /// Party IDs (1-based: 1, 2, ..., T+1) for the reconstructing parties. | ||
| pub reconstructing_parties: Vec<usize>, | ||
| /// Decoded message polynomial coefficients. | ||
| pub message_vec: Vec<u64>, | ||
| } |
128 changes: 128 additions & 0 deletions
128
crates/zk-helpers/src/circuits/threshold/decrypted_shares_aggregation/codegen.rs
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,128 @@ | ||
| // 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. | ||
|
|
||
| //! Code generation for the Decrypted Shares Aggregation circuit: Prover.toml and configs.nr. | ||
|
|
||
| use e3_fhe_params::BfvPreset; | ||
|
|
||
| use crate::circuits::computation::Computation; | ||
| use crate::threshold::decrypted_shares_aggregation::circuit::DecryptedSharesAggregationCircuit; | ||
| use crate::threshold::decrypted_shares_aggregation::computation::{Configs, Witness}; | ||
| use crate::threshold::decrypted_shares_aggregation::DecryptedSharesAggregationCircuitInput; | ||
| use crate::Circuit; | ||
| use crate::CircuitCodegen; | ||
| use crate::CircuitsErrors; | ||
| use crate::{Artifacts, CodegenConfigs, CodegenToml}; | ||
|
|
||
| /// Implementation of [`CircuitCodegen`] for [`DecryptedSharesAggregationCircuit`]. | ||
| impl CircuitCodegen for DecryptedSharesAggregationCircuit { | ||
| type Preset = BfvPreset; | ||
| type Input = DecryptedSharesAggregationCircuitInput; | ||
| type Error = CircuitsErrors; | ||
|
|
||
| fn codegen(&self, preset: Self::Preset, input: &Self::Input) -> Result<Artifacts, Self::Error> { | ||
| let witness = Witness::compute(preset, input)?; | ||
| let configs = Configs::compute(preset, &())?; | ||
|
|
||
| let toml = generate_toml(witness)?; | ||
| let configs_str = generate_configs(preset, &configs); | ||
|
|
||
| Ok(Artifacts { | ||
| toml, | ||
| configs: configs_str, | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| pub fn generate_toml(witness: Witness) -> Result<CodegenToml, CircuitsErrors> { | ||
| let json = witness.to_json().map_err(CircuitsErrors::SerdeJson)?; | ||
|
|
||
| Ok(toml::to_string(&json)?) | ||
| } | ||
|
|
||
| /// Generates the decrypted_shares_aggregation config fragment for threshold.nr. | ||
| /// Emits L, QIS, PLAINTEXT_MODULUS, Q_INVERSE_MOD_T so the circuit uses the same | ||
| /// crypto params as the witness (avoids "Cannot satisfy constraint" from config mismatch). | ||
| pub fn generate_configs(_preset: BfvPreset, configs: &Configs) -> CodegenConfigs { | ||
| let prefix = <DecryptedSharesAggregationCircuit as Circuit>::PREFIX; | ||
| let qis_str = configs | ||
| .moduli | ||
| .iter() | ||
| .map(|q| q.to_string()) | ||
| .collect::<Vec<_>>() | ||
| .join(", "); | ||
|
|
||
| format!( | ||
| r#"use crate::core::threshold::decrypted_shares_aggregation::Configs as DecryptedSharesAggregationConfigs; | ||
|
|
||
| /************************************ | ||
| ------------------------------------- | ||
| decrypted_shares_aggregation (CIRCUIT 7) | ||
| ------------------------------------- | ||
| ************************************/ | ||
|
|
||
| pub global L: u32 = {}; | ||
| pub global QIS: [Field; L] = [{}]; | ||
| pub global PLAINTEXT_MODULUS: Field = {}; | ||
| pub global Q_INVERSE_MOD_T: Field = {}; | ||
|
|
||
| pub global {}_BIT_NOISE: u32 = {}; | ||
|
|
||
| pub global {}_CONFIGS: DecryptedSharesAggregationConfigs<L> = | ||
| DecryptedSharesAggregationConfigs::new(QIS, PLAINTEXT_MODULUS, Q_INVERSE_MOD_T); | ||
| "#, | ||
| configs.l, | ||
| qis_str, | ||
| configs.plaintext_modulus, | ||
| configs.q_inverse_mod_t, | ||
| prefix, | ||
| configs.bits.noise_bit, | ||
| prefix, | ||
| ) | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
| use crate::CiphernodesCommitteeSize; | ||
|
|
||
| #[test] | ||
| fn test_configs_generation() { | ||
| let preset = BfvPreset::InsecureThreshold512; | ||
| let configs = Configs::compute(preset, &()).unwrap(); | ||
| let prefix: &str = <DecryptedSharesAggregationCircuit as Circuit>::PREFIX; | ||
|
|
||
| let codegen_configs = generate_configs(preset, &configs); | ||
|
|
||
| assert!(codegen_configs.contains("decrypted_shares_aggregation")); | ||
| assert!(codegen_configs.contains(&format!( | ||
| "{}_BIT_NOISE: u32 = {}", | ||
| prefix, configs.bits.noise_bit | ||
| ))); | ||
| assert!(codegen_configs.contains(&format!("{}_CONFIGS:", prefix))); | ||
| assert!(codegen_configs.contains( | ||
| "DecryptedSharesAggregationConfigs::new(QIS, PLAINTEXT_MODULUS, Q_INVERSE_MOD_T)" | ||
| )); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_codegen_with_sample() { | ||
| let preset = BfvPreset::InsecureThreshold512; | ||
| let committee = CiphernodesCommitteeSize::Small.values(); | ||
| let input = DecryptedSharesAggregationCircuitInput::generate_sample(preset, committee); | ||
| let circuit = DecryptedSharesAggregationCircuit; | ||
|
|
||
| let artifacts = circuit.codegen(preset, &input).unwrap(); | ||
|
|
||
| assert!(!artifacts.toml.is_empty()); | ||
| assert!(artifacts | ||
| .configs | ||
| .contains("DECRYPTED_SHARES_AGGREGATION_BIT_NOISE")); | ||
| assert!(artifacts | ||
| .configs | ||
| .contains("DECRYPTED_SHARES_AGGREGATION_CONFIGS")); | ||
| } | ||
| } |
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.