Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions circuits/bin/dkg/e_sm_share_decryption/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE.

use lib::configs::default::dkg::{L_THRESHOLD, N, SHARE_DECRYPTION_BIT_MSG_E_SM};
use lib::configs::default::dkg::{L_THRESHOLD, N, SHARE_DECRYPTION_BIT_MSG};
use lib::configs::default::H;
use lib::core::dkg::share_decryption::ShareDecryption;
use lib::math::polynomial::Polynomial;
Expand All @@ -13,7 +13,7 @@ fn main(
expected_commitments: pub [[Field; L_THRESHOLD]; H],
decrypted_shares: [[Polynomial<N>; L_THRESHOLD]; H],
) -> pub Field {
let share_decryption: ShareDecryption<N, L_THRESHOLD, H, SHARE_DECRYPTION_BIT_MSG_E_SM> =
let share_decryption: ShareDecryption<N, L_THRESHOLD, H, SHARE_DECRYPTION_BIT_MSG> =
ShareDecryption::new(expected_commitments, decrypted_shares);

share_decryption.execute()
Expand Down
4 changes: 2 additions & 2 deletions circuits/bin/dkg/sk_share_decryption/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE.

use lib::configs::default::dkg::{L_THRESHOLD, N, SHARE_DECRYPTION_BIT_MSG_SK};
use lib::configs::default::dkg::{L_THRESHOLD, N, SHARE_DECRYPTION_BIT_MSG};
use lib::configs::default::H;
use lib::core::dkg::share_decryption::ShareDecryption;
use lib::math::polynomial::Polynomial;
Expand All @@ -13,7 +13,7 @@ fn main(
expected_commitments: pub [[Field; L_THRESHOLD]; H],
decrypted_shares: [[Polynomial<N>; L_THRESHOLD]; H],
) -> pub Field {
let share_decryption: ShareDecryption<N, L_THRESHOLD, H, SHARE_DECRYPTION_BIT_MSG_SK> =
let share_decryption: ShareDecryption<N, L_THRESHOLD, H, SHARE_DECRYPTION_BIT_MSG> =
ShareDecryption::new(expected_commitments, decrypted_shares);

share_decryption.execute()
Expand Down
15 changes: 3 additions & 12 deletions circuits/lib/src/configs/insecure/dkg.nr
Original file line number Diff line number Diff line change
Expand Up @@ -136,18 +136,9 @@ pub global SHARE_ENCRYPTION_CONFIGS: ShareEncryptionConfigs<L> = ShareEncryption

/************************************
-------------------------------------
share_decryption_sk (CIRCUIT 4a)
share_decryption_sk (CIRCUIT 4a - BFV DECRYPTION SK)
share_decryption_e_sm (CIRCUIT 4b - BFV DECRYPTION E_SM)
-------------------------------------
************************************/

// share_decryption_sk - bit parameters
pub global SHARE_DECRYPTION_BIT_MSG_SK: u32 = 37;

/************************************
-------------------------------------
share_decryption_e_sm (CIRCUIT 4b)
-------------------------------------
************************************/

// share_decryption_e_sm - bit parameters
pub global SHARE_DECRYPTION_BIT_MSG_E_SM: u32 = 37;
pub global SHARE_DECRYPTION_BIT_MSG: u32 = 36;
15 changes: 3 additions & 12 deletions circuits/lib/src/configs/secure/dkg.nr
Original file line number Diff line number Diff line change
Expand Up @@ -132,18 +132,9 @@ pub global SHARE_ENCRYPTION_CONFIGS: ShareEncryptionConfigs<L> = ShareEncryption

/************************************
-------------------------------------
share_decryption_sk (CIRCUIT 4a)
share_decryption_sk (CIRCUIT 4a - BFV DECRYPTION SK)
share_decryption_e_sm (CIRCUIT 4b - BFV DECRYPTION E_SM)
-------------------------------------
************************************/

// share_decryption_sk - bit parameters
pub global SHARE_DECRYPTION_BIT_MSG_SK: u32 = 56;

/************************************
-------------------------------------
share_decryption_e_sm (CIRCUIT 4b)
-------------------------------------
************************************/

// share_decryption_e_sm - bit parameters
pub global SHARE_DECRYPTION_BIT_MSG_E_SM: u32 = 56;
pub global SHARE_DECRYPTION_BIT_MSG: u32 = 55;
90 changes: 33 additions & 57 deletions crates/zk-helpers/src/bin/zk_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,15 @@ use e3_zk_helpers::circuits::dkg::share_computation::circuit::{
};
use e3_zk_helpers::codegen::{write_artifacts, CircuitCodegen};
use e3_zk_helpers::computation::DkgInputType;
use e3_zk_helpers::dkg::share_encryption::{
ShareEncryptionCircuit, ShareEncryptionCircuitInput, ShareEncryptionSample,
};
use e3_zk_helpers::dkg::share_decryption::{ShareDecryptionCircuit, ShareDecryptionCircuitInput};
use e3_zk_helpers::dkg::share_encryption::{ShareEncryptionCircuit, ShareEncryptionCircuitInput};
use e3_zk_helpers::registry::{Circuit, CircuitRegistry};
use e3_zk_helpers::threshold::pk_aggregation::PkAggregationCircuit;
use e3_zk_helpers::threshold::pk_aggregation::PkAggregationCircuitInput;
use e3_zk_helpers::threshold::pk_generation::{PkGenerationCircuit, PkGenerationCircuitInput};
use e3_zk_helpers::threshold::user_data_encryption::{
UserDataEncryptionCircuit, UserDataEncryptionCircuitInput, UserDataEncryptionSample,
UserDataEncryptionCircuit, UserDataEncryptionCircuitInput,
};
use e3_zk_helpers::{PkSample, ShareComputationSample};
use std::io::Write;
use std::path::PathBuf;
use std::sync::atomic::{AtomicBool, Ordering};
Expand Down Expand Up @@ -159,8 +157,9 @@ fn main() -> Result<()> {
registry.register(Arc::new(PkCircuit));
registry.register(Arc::new(ShareComputationCircuit));
registry.register(Arc::new(UserDataEncryptionCircuit));
registry.register(Arc::new(ShareEncryptionCircuit));
registry.register(Arc::new(PkGenerationCircuit));
registry.register(Arc::new(ShareEncryptionCircuit));
registry.register(Arc::new(ShareDecryptionCircuit));
registry.register(Arc::new(PkAggregationCircuit));

// Handle list circuits flag.
Expand Down Expand Up @@ -211,7 +210,8 @@ fn main() -> Result<()> {
let write_prover_toml = args.toml;
// Only share-computation has a witness-type choice (secret-key vs smudging-noise). pk always uses secret key.
let has_witness_type = circuit_meta.name() == ShareComputationCircuit::NAME
|| circuit_meta.name() == ShareEncryptionCircuit::NAME;
|| circuit_meta.name() == ShareEncryptionCircuit::NAME
|| circuit_meta.name() == ShareDecryptionCircuit::NAME;

let dkg_input_type = if has_witness_type {
// Share-computation: require --witness when generating Prover.toml; default secret-key for configs-only.
Expand Down Expand Up @@ -249,91 +249,67 @@ fn main() -> Result<()> {
let circuit_name = circuit_meta.name();
let artifacts = match circuit_name {
name if name == <PkCircuit as Circuit>::NAME => {
let sample = PkSample::generate(preset, CiphernodesCommitteeSize::Small);
let sample = PkCircuitInput::generate_sample(preset);

let circuit = PkCircuit;
circuit.codegen(
preset,
&PkCircuitInput {
public_key: sample.dkg_public_key,
},
)?
circuit.codegen(preset, &sample)?
}
name if name == <ShareComputationCircuit as Circuit>::NAME => {
let sd = preset
.search_defaults()
.ok_or_else(|| anyhow!("missing search_defaults for preset"))?;
let sample = ShareComputationSample::generate(
let sample = ShareComputationCircuitInput::generate_sample(
preset,
CiphernodesCommitteeSize::Small,
dkg_input_type,
sd.z,
sd.lambda,
);

let circuit = ShareComputationCircuit;
circuit.codegen(
preset,
&ShareComputationCircuitInput {
dkg_input_type,
secret: sample.secret.clone(),
secret_sss: sample.secret_sss.clone(),
parity_matrix: sample.parity_matrix.clone(),
n_parties: sample.committee.n as u32,
threshold: sample.committee.threshold as u32,
},
)?
circuit.codegen(preset, &sample)?
}
name if name == <ShareEncryptionCircuit as Circuit>::NAME => {
let sd = preset
.search_defaults()
.ok_or_else(|| anyhow!("missing search_defaults for preset"))?;
let sample = ShareEncryptionSample::generate(
let sd = preset.search_defaults().ok_or_else(|| {
anyhow!("preset does not define search defaults for {}", name)
})?;
let sample = ShareEncryptionCircuitInput::generate_sample(
preset,
CiphernodesCommitteeSize::Small,
dkg_input_type,
sd.z,
sd.lambda,
);
let circuit = ShareEncryptionCircuit;

circuit.codegen(
preset,
&ShareEncryptionCircuitInput {
plaintext: sample.plaintext,
ciphertext: sample.ciphertext,
public_key: sample.public_key,
secret_key: sample.secret_key,
u_rns: sample.u_rns,
e0_rns: sample.e0_rns,
e1_rns: sample.e1_rns,
},
)?
let circuit = ShareEncryptionCircuit;
circuit.codegen(preset, &sample)?
}
name if name == <UserDataEncryptionCircuit as Circuit>::NAME => {
let sample = UserDataEncryptionSample::generate(preset);
let circuit = UserDataEncryptionCircuit;
let sample = UserDataEncryptionCircuitInput::generate_sample(preset);

circuit.codegen(
preset,
&UserDataEncryptionCircuitInput {
public_key: sample.public_key,
plaintext: sample.plaintext,
},
)?
let circuit = UserDataEncryptionCircuit;
circuit.codegen(preset, &sample)?
}
name if name == <PkGenerationCircuit as Circuit>::NAME => {
let sample = PkGenerationCircuitInput::generate_sample(
preset,
CiphernodesCommitteeSize::Small.values(),
)?;

let circuit = PkGenerationCircuit;
circuit.codegen(preset, &sample)?
}
name if name == <ShareDecryptionCircuit as Circuit>::NAME => {
let sample = ShareDecryptionCircuitInput::generate_sample(
preset,
CiphernodesCommitteeSize::Small,
dkg_input_type,
);

let circuit = ShareDecryptionCircuit;
circuit.codegen(preset, &sample)?
}
name if name == <PkAggregationCircuit as Circuit>::NAME => {
let sample = PkAggregationCircuitInput::generate_sample(
preset,
CiphernodesCommitteeSize::Small.values(),
)?;

let circuit = PkAggregationCircuit;
circuit.codegen(preset, &sample)?
}
Expand Down
2 changes: 1 addition & 1 deletion crates/zk-helpers/src/circuits/computation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//! [`Toml`] and [`Configs`] are the string types used for Prover.toml and configs.nr.

/// Variant for input types for DKG.
#[derive(Clone, Copy, PartialEq, Eq)]
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum DkgInputType {
/// The input type that generates shares of a secret key using secret sharing.
SecretKey,
Expand Down
1 change: 1 addition & 0 deletions crates/zk-helpers/src/circuits/dkg/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@

pub mod pk;
pub mod share_computation;
pub mod share_decryption;
pub mod share_encryption;
15 changes: 3 additions & 12 deletions crates/zk-helpers/src/circuits/dkg/pk/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,8 @@ pub global {}_BIT_PK: u32 = {};
#[cfg(test)]
mod tests {
use super::*;
use crate::ciphernodes_committee::CiphernodesCommitteeSize;
use crate::codegen::write_artifacts;
use crate::prepare_pk_sample_for_test;
use crate::dkg::pk::PkCircuitInput;
use crate::utils::compute_pk_bit;

use e3_fhe_params::{build_pair_for_preset, BfvPreset};
Expand All @@ -82,18 +81,10 @@ mod tests {
#[test]
fn test_toml_generation_and_structure() {
let (_, dkg_params) = build_pair_for_preset(BfvPreset::InsecureThreshold512).unwrap();
let sample = prepare_pk_sample_for_test(
BfvPreset::InsecureThreshold512,
CiphernodesCommitteeSize::Small,
);
let sample = PkCircuitInput::generate_sample(BfvPreset::InsecureThreshold512);

let artifacts = PkCircuit
.codegen(
BfvPreset::InsecureThreshold512,
&PkCircuitInput {
public_key: sample.dkg_public_key,
},
)
.codegen(BfvPreset::InsecureThreshold512, &sample)
.unwrap();

let parsed: toml::Value = artifacts.toml.parse().unwrap();
Expand Down
10 changes: 2 additions & 8 deletions crates/zk-helpers/src/circuits/dkg/pk/computation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,8 @@ impl Computation for Witness {
build_pair_for_preset(preset).map_err(|e| CircuitsErrors::Sample(e.to_string()))?;
let moduli = dkg_params.moduli();

let mut pk0is = CrtPolynomial::from_fhe_polynomial(&input.public_key.c.c[0]);
let mut pk1is = CrtPolynomial::from_fhe_polynomial(&input.public_key.c.c[1]);

pk0is.reverse();
pk1is.reverse();

pk0is.center(&moduli)?;
pk1is.center(&moduli)?;
let mut pk0is = crate::crt::fhe_poly_to_crt_centered(&input.public_key.c.c[0], moduli)?;
let mut pk1is = crate::crt::fhe_poly_to_crt_centered(&input.public_key.c.c[1], moduli)?;

let zkp_modulus = &get_zkp_modulus();

Expand Down
Loading
Loading