diff --git a/crates/bfv-client/src/client.rs b/crates/bfv-client/src/client.rs index e605694a0d..15927c93ed 100644 --- a/crates/bfv-client/src/client.rs +++ b/crates/bfv-client/src/client.rs @@ -6,7 +6,7 @@ use anyhow::{anyhow, Result}; use e3_fhe_params::{build_bfv_params_arc, DEFAULT_BFV_PRESET}; -use e3_zk_helpers::circuits::threshold::user_data_encryption::circuit::UserDataEncryptionCircuitInput; +use e3_zk_helpers::circuits::threshold::user_data_encryption::circuit::UserDataEncryptionCircuitData; use e3_zk_helpers::circuits::threshold::user_data_encryption::Inputs as UserDataEncryptionInputs; use e3_zk_helpers::circuits::Computation; use fhe::bfv::{Ciphertext, Encoding, Plaintext, PublicKey, SecretKey}; @@ -103,7 +103,7 @@ where let inputs = UserDataEncryptionInputs::compute( DEFAULT_BFV_PRESET, - &UserDataEncryptionCircuitInput { + &UserDataEncryptionCircuitData { public_key: pk, plaintext: plaintext, }, diff --git a/crates/multithread/src/multithread.rs b/crates/multithread/src/multithread.rs index 97ef97a2e7..4cbc792f78 100644 --- a/crates/multithread/src/multithread.rs +++ b/crates/multithread/src/multithread.rs @@ -31,7 +31,7 @@ use e3_trbfv::gen_esi_sss::gen_esi_sss; use e3_trbfv::gen_pk_share_and_sk_sss::gen_pk_share_and_sk_sss; use e3_trbfv::{TrBFVError, TrBFVRequest, TrBFVResponse}; use e3_utils::SharedRng; -use e3_zk_helpers::circuits::dkg::pk::circuit::{PkCircuit, PkCircuitInput}; +use e3_zk_helpers::circuits::dkg::pk::circuit::{PkCircuit, PkCircuitData}; use e3_zk_prover::{Provable, ZkBackend, ZkProver}; use fhe::bfv::PublicKey; use fhe_traits::DeserializeParametrized; @@ -357,7 +357,7 @@ fn handle_pk_bfv_proof( })?; let circuit = PkCircuit; - let circuit_input = PkCircuitInput { public_key: pk_bfv }; + let circuit_data = PkCircuitData { public_key: pk_bfv }; let e3_id_str = request.e3_id.to_string(); let preset_counterpart = req .params_preset @@ -366,7 +366,7 @@ fn handle_pk_bfv_proof( // But here we have to pass the InsecureThreshold512 preset because the underlaying witness generator // builds both params, but will only use the DKG one let proof = circuit - .prove(prover, &preset_counterpart, &circuit_input, &e3_id_str) + .prove(prover, &preset_counterpart, &circuit_data, &e3_id_str) .map_err(|e| { ComputeRequestError::new( ComputeRequestErrorKind::Zk(ZkEventError::ProofGenerationFailed(e.to_string())), diff --git a/crates/zk-helpers/README.md b/crates/zk-helpers/README.md index f499b4de7a..2573e37610 100644 --- a/crates/zk-helpers/README.md +++ b/crates/zk-helpers/README.md @@ -1,8 +1,8 @@ # zk-helpers ZK circuit artifact generation for the Noir prover. Produces `configs.nr` and optionally -`Prover.toml` for the Enclave circuits. The Prover.toml contains circuit inputs for Nargo, -which executes them to produce witnesses for proof generation. +`Prover.toml` for the Enclave circuits. The Prover.toml contains circuit inputs for Nargo, which +executes them to produce witnesses for proof generation. ## zk-cli diff --git a/crates/zk-helpers/src/bin/zk_cli.rs b/crates/zk-helpers/src/bin/zk_cli.rs index 3b2d9c5eb7..06ffe63139 100644 --- a/crates/zk-helpers/src/bin/zk_cli.rs +++ b/crates/zk-helpers/src/bin/zk_cli.rs @@ -14,30 +14,30 @@ use anyhow::{anyhow, Context, Result}; use clap::{arg, command, Parser}; use e3_fhe_params::{BfvPreset, ParameterType}; use e3_zk_helpers::ciphernodes_committee::CiphernodesCommitteeSize; -use e3_zk_helpers::circuits::dkg::pk::circuit::{PkCircuit, PkCircuitInput}; +use e3_zk_helpers::circuits::dkg::pk::circuit::{PkCircuit, PkCircuitData}; use e3_zk_helpers::circuits::dkg::share_computation::circuit::{ - ShareComputationCircuit, ShareComputationCircuitInput, + ShareComputationCircuit, ShareComputationCircuitData, }; use e3_zk_helpers::codegen::{write_artifacts, write_toml, CircuitCodegen}; use e3_zk_helpers::computation::DkgInputType; use e3_zk_helpers::dkg::share_decryption::{ ShareDecryptionCircuit as DkgShareDecryptionCircuit, - ShareDecryptionCircuitInput as DkgShareDecryptionCircuitInput, + ShareDecryptionCircuitData as DkgShareDecryptionCircuitData, }; -use e3_zk_helpers::dkg::share_encryption::{ShareEncryptionCircuit, ShareEncryptionCircuitInput}; +use e3_zk_helpers::dkg::share_encryption::{ShareEncryptionCircuit, ShareEncryptionCircuitData}; use e3_zk_helpers::registry::{Circuit, CircuitRegistry}; use e3_zk_helpers::threshold::decrypted_shares_aggregation::{ - DecryptedSharesAggregationCircuit, DecryptedSharesAggregationCircuitInput, + DecryptedSharesAggregationCircuit, DecryptedSharesAggregationCircuitData, }; 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::pk_aggregation::PkAggregationCircuitData; +use e3_zk_helpers::threshold::pk_generation::{PkGenerationCircuit, PkGenerationCircuitData}; use e3_zk_helpers::threshold::share_decryption::{ ShareDecryptionCircuit as ThresholdShareDecryptionCircuit, - ShareDecryptionCircuitInput as ThresholdShareDecryptionCircuitInput, + ShareDecryptionCircuitData as ThresholdShareDecryptionCircuitData, }; use e3_zk_helpers::threshold::user_data_encryption::{ - UserDataEncryptionCircuit, UserDataEncryptionCircuitInput, + UserDataEncryptionCircuit, UserDataEncryptionCircuitData, }; use std::io::Write; use std::path::PathBuf; @@ -270,13 +270,13 @@ fn main() -> Result<()> { let committee = CiphernodesCommitteeSize::Small.values(); let artifacts = match circuit_name { name if name == ::NAME => { - let sample = PkCircuitInput::generate_sample(preset)?; + let sample = PkCircuitData::generate_sample(preset)?; let circuit = PkCircuit; circuit.codegen(preset, &sample)? } name if name == ::NAME => { - let sample = ShareComputationCircuitInput::generate_sample( + let sample = ShareComputationCircuitData::generate_sample( preset, committee, dkg_input_type, @@ -287,7 +287,7 @@ fn main() -> Result<()> { } name if name == ::NAME => { let sd = preset.search_defaults().unwrap(); - let sample = ShareEncryptionCircuitInput::generate_sample( + let sample = ShareEncryptionCircuitData::generate_sample( preset, committee, dkg_input_type, @@ -299,19 +299,19 @@ fn main() -> Result<()> { circuit.codegen(preset, &sample)? } name if name == ::NAME => { - let sample = UserDataEncryptionCircuitInput::generate_sample(preset)?; + let sample = UserDataEncryptionCircuitData::generate_sample(preset)?; let circuit = UserDataEncryptionCircuit; circuit.codegen(preset, &sample)? } name if name == ::NAME => { - let sample = PkGenerationCircuitInput::generate_sample(preset, committee)?; + let sample = PkGenerationCircuitData::generate_sample(preset, committee)?; let circuit = PkGenerationCircuit; circuit.codegen(preset, &sample)? } name if name == ::NAME => { - let sample = DkgShareDecryptionCircuitInput::generate_sample( + let sample = DkgShareDecryptionCircuitData::generate_sample( preset, committee, dkg_input_type, @@ -321,20 +321,20 @@ fn main() -> Result<()> { circuit.codegen(preset, &sample)? } name if name == ::NAME => { - let sample = PkAggregationCircuitInput::generate_sample(preset, committee)?; + let sample = PkAggregationCircuitData::generate_sample(preset, committee)?; let circuit = PkAggregationCircuit; circuit.codegen(preset, &sample)? } name if name == ::NAME => { let sample = - ThresholdShareDecryptionCircuitInput::generate_sample(preset, committee)?; + ThresholdShareDecryptionCircuitData::generate_sample(preset, committee)?; let circuit = ThresholdShareDecryptionCircuit; circuit.codegen(preset, &sample)? } name if name == ::NAME => { - let sample = DecryptedSharesAggregationCircuitInput::generate_sample( + let sample = DecryptedSharesAggregationCircuitData::generate_sample( preset, CiphernodesCommitteeSize::Small.values(), )?; diff --git a/crates/zk-helpers/src/circuits/codegen.rs b/crates/zk-helpers/src/circuits/codegen.rs index 6a1d802792..3cf06525d2 100644 --- a/crates/zk-helpers/src/circuits/codegen.rs +++ b/crates/zk-helpers/src/circuits/codegen.rs @@ -26,17 +26,17 @@ pub struct Artifacts { pub configs: CodegenConfigs, } -/// Trait for circuits that can generate Prover.toml and configs.nr from circuit-specific input. +/// Trait for circuits that can generate Prover.toml and configs.nr from circuit-specific data. pub trait CircuitCodegen: crate::registry::Circuit { /// Circuit-specific BFV threshold parameters preset. type Preset; - /// Circuit-specific codegen input (e.g. preset + public key). - type Input; + /// Circuit-specific codegen data (e.g. preset + public key). + type Data; /// Error type for codegen failures. type Error; /// Produces [`Artifacts`] for this circuit from the given input. - fn codegen(&self, preset: Self::Preset, input: &Self::Input) -> Result; + fn codegen(&self, preset: Self::Preset, data: &Self::Data) -> Result; } /// Writes the Prover TOML string to `path/Prover.toml`, or `./Prover.toml` if `path` is `None`. diff --git a/crates/zk-helpers/src/circuits/computation.rs b/crates/zk-helpers/src/circuits/computation.rs index 88d1127e64..101470ef03 100644 --- a/crates/zk-helpers/src/circuits/computation.rs +++ b/crates/zk-helpers/src/circuits/computation.rs @@ -22,11 +22,11 @@ pub enum DkgInputType { /// Generic computation from parameters and input to a result. pub trait Computation: Sized { type Preset; - type Input; + type Data; type Error; /// Computes the result from parameters and input. - fn compute(preset: Self::Preset, input: &Self::Input) -> Result; + fn compute(preset: Self::Preset, data: &Self::Data) -> Result; /// Converts the result to a JSON [`serde_json::Value`] for serialization. /// Default: `serde_json::to_value(self)` when `Self: serde::Serialize`. @@ -41,10 +41,10 @@ pub trait Computation: Sized { /// Circuit-specific computation: parameters and input produce bounds, bits, circuit inputs, etc. pub trait CircuitComputation: crate::registry::Circuit { type Preset; - type Input; + type Data; type Output; type Error; /// Computes circuit-specific data (bounds, bits, inputs) from parameters and input. - fn compute(preset: Self::Preset, input: &Self::Input) -> Result; + fn compute(preset: Self::Preset, data: &Self::Data) -> Result; } diff --git a/crates/zk-helpers/src/circuits/dkg/pk/circuit.rs b/crates/zk-helpers/src/circuits/dkg/pk/circuit.rs index 28e8c708e4..4ba3d5ee7f 100644 --- a/crates/zk-helpers/src/circuits/dkg/pk/circuit.rs +++ b/crates/zk-helpers/src/circuits/dkg/pk/circuit.rs @@ -19,6 +19,6 @@ impl Circuit for PkCircuit { const DKG_INPUT_TYPE: Option = Some(DkgInputType::SecretKey); } -pub struct PkCircuitInput { +pub struct PkCircuitData { pub public_key: PublicKey, } diff --git a/crates/zk-helpers/src/circuits/dkg/pk/codegen.rs b/crates/zk-helpers/src/circuits/dkg/pk/codegen.rs index bff02c880d..32a8980c53 100644 --- a/crates/zk-helpers/src/circuits/dkg/pk/codegen.rs +++ b/crates/zk-helpers/src/circuits/dkg/pk/codegen.rs @@ -7,7 +7,7 @@ //! Code generation for the public-key BFV circuit: Prover.toml and configs.nr. use crate::circuits::dkg::pk::circuit::PkCircuit; -use crate::circuits::dkg::pk::circuit::PkCircuitInput; +use crate::circuits::dkg::pk::circuit::PkCircuitData; use crate::circuits::dkg::pk::computation::{Bits, Inputs, PkComputationOutput}; use crate::Artifacts; use crate::Circuit; @@ -23,11 +23,11 @@ use e3_fhe_params::BfvPreset; /// Implementation of [`CircuitCodegen`] for [`PkCircuit`]. impl CircuitCodegen for PkCircuit { type Preset = BfvPreset; - type Input = PkCircuitInput; + type Data = PkCircuitData; type Error = CircuitsErrors; - fn codegen(&self, preset: Self::Preset, input: &Self::Input) -> Result { - let PkComputationOutput { inputs, bits, .. } = PkCircuit::compute(preset, input)?; + fn codegen(&self, preset: Self::Preset, data: &Self::Data) -> Result { + let PkComputationOutput { inputs, bits, .. } = PkCircuit::compute(preset, data)?; let toml = generate_toml(inputs)?; let configs = generate_configs(preset, &bits); @@ -69,7 +69,7 @@ pub global {}_BIT_PK: u32 = {}; mod tests { use super::*; use crate::codegen::write_artifacts; - use crate::dkg::pk::PkCircuitInput; + use crate::dkg::pk::PkCircuitData; use crate::utils::compute_modulus_bit; use e3_fhe_params::{build_pair_for_preset, BfvPreset}; @@ -78,7 +78,7 @@ mod tests { #[test] fn test_toml_generation_and_structure() { let (_, dkg_params) = build_pair_for_preset(BfvPreset::InsecureThreshold512).unwrap(); - let sample = PkCircuitInput::generate_sample(BfvPreset::InsecureThreshold512).unwrap(); + let sample = PkCircuitData::generate_sample(BfvPreset::InsecureThreshold512).unwrap(); let artifacts = PkCircuit .codegen(BfvPreset::InsecureThreshold512, &sample) diff --git a/crates/zk-helpers/src/circuits/dkg/pk/computation.rs b/crates/zk-helpers/src/circuits/dkg/pk/computation.rs index 31b7a90827..eb1dc392c7 100644 --- a/crates/zk-helpers/src/circuits/dkg/pk/computation.rs +++ b/crates/zk-helpers/src/circuits/dkg/pk/computation.rs @@ -10,7 +10,7 @@ //! and (for input) a public key. They implement [`Computation`] and are used by codegen. use crate::circuits::dkg::pk::circuit::PkCircuit; -use crate::circuits::dkg::pk::circuit::PkCircuitInput; +use crate::circuits::dkg::pk::circuit::PkCircuitData; use crate::compute_max_modulus; use crate::crt_polynomial_to_toml_json; use crate::get_zkp_modulus; @@ -34,14 +34,14 @@ pub struct PkComputationOutput { /// Implementation of [`CircuitComputation`] for [`PkCircuit`]. impl CircuitComputation for PkCircuit { type Preset = BfvPreset; - type Input = PkCircuitInput; + type Data = PkCircuitData; type Output = PkComputationOutput; type Error = CircuitsErrors; - fn compute(preset: Self::Preset, input: &Self::Input) -> Result { + fn compute(preset: Self::Preset, data: &Self::Data) -> Result { let bounds = Bounds::compute(preset, &())?; let bits = Bits::compute(preset, &())?; - let inputs = Inputs::compute(preset, input)?; + let inputs = Inputs::compute(preset, data)?; Ok(PkComputationOutput { bounds, @@ -83,10 +83,10 @@ pub struct Inputs { impl Computation for Configs { type Preset = BfvPreset; - type Input = (); + type Data = (); type Error = CircuitsErrors; - fn compute(preset: Self::Preset, _: &Self::Input) -> Result { + fn compute(preset: Self::Preset, _: &Self::Data) -> Result { let (_, dkg_params) = build_pair_for_preset(preset).map_err(|e| CircuitsErrors::Sample(e.to_string()))?; @@ -107,10 +107,10 @@ impl Computation for Configs { impl Computation for Bits { type Preset = BfvPreset; - type Input = (); + type Data = (); type Error = CircuitsErrors; - fn compute(preset: Self::Preset, _: &Self::Input) -> Result { + fn compute(preset: Self::Preset, _: &Self::Data) -> Result { let (_, dkg_params) = build_pair_for_preset(preset).map_err(|e| CircuitsErrors::Sample(e.to_string()))?; @@ -122,10 +122,10 @@ impl Computation for Bits { impl Computation for Bounds { type Preset = BfvPreset; - type Input = (); + type Data = (); type Error = CircuitsErrors; - fn compute(preset: Self::Preset, _: &Self::Input) -> Result { + fn compute(preset: Self::Preset, _: &Self::Data) -> Result { let (_, dkg_params) = build_pair_for_preset(preset).map_err(|e| CircuitsErrors::Sample(e.to_string()))?; @@ -139,16 +139,16 @@ impl Computation for Bounds { impl Computation for Inputs { type Preset = BfvPreset; - type Input = PkCircuitInput; + type Data = PkCircuitData; type Error = CircuitsErrors; - fn compute(preset: Self::Preset, input: &Self::Input) -> Result { + fn compute(preset: Self::Preset, data: &Self::Data) -> Result { let (_, dkg_params) = build_pair_for_preset(preset).map_err(|e| CircuitsErrors::Sample(e.to_string()))?; let moduli = dkg_params.moduli(); - let mut pk0is = crate::math::fhe_poly_to_crt_centered(&input.public_key.c.c[0], moduli)?; - let mut pk1is = crate::math::fhe_poly_to_crt_centered(&input.public_key.c.c[1], moduli)?; + let mut pk0is = crate::math::fhe_poly_to_crt_centered(&data.public_key.c.c[0], moduli)?; + let mut pk1is = crate::math::fhe_poly_to_crt_centered(&data.public_key.c.c[1], moduli)?; let zkp_modulus = &get_zkp_modulus(); diff --git a/crates/zk-helpers/src/circuits/dkg/pk/mod.rs b/crates/zk-helpers/src/circuits/dkg/pk/mod.rs index faa06d83f0..ecf8526613 100644 --- a/crates/zk-helpers/src/circuits/dkg/pk/mod.rs +++ b/crates/zk-helpers/src/circuits/dkg/pk/mod.rs @@ -9,6 +9,6 @@ pub mod codegen; pub mod computation; pub mod sample; -pub use circuit::{PkCircuit, PkCircuitInput}; +pub use circuit::{PkCircuit, PkCircuitData}; pub use codegen::{generate_configs, generate_toml}; pub use computation::{Bits, Bounds, Configs, Inputs, PkComputationOutput}; diff --git a/crates/zk-helpers/src/circuits/dkg/pk/sample.rs b/crates/zk-helpers/src/circuits/dkg/pk/sample.rs index 045fc83343..6addad3453 100644 --- a/crates/zk-helpers/src/circuits/dkg/pk/sample.rs +++ b/crates/zk-helpers/src/circuits/dkg/pk/sample.rs @@ -6,14 +6,14 @@ //! Sample data generation for the pk circuit: committee and DKG public key only. -use crate::dkg::pk::PkCircuitInput; +use crate::dkg::pk::PkCircuitData; use crate::CircuitsErrors; use e3_fhe_params::build_pair_for_preset; use e3_fhe_params::BfvPreset; use fhe::bfv::{PublicKey, SecretKey}; use rand::thread_rng; -impl PkCircuitInput { +impl PkCircuitData { /// Generates sample data for the pk circuit. pub fn generate_sample(preset: BfvPreset) -> Result { let (_, dkg_params) = build_pair_for_preset(preset).map_err(|e| { @@ -32,12 +32,12 @@ impl PkCircuitInput { #[cfg(test)] mod tests { - use crate::dkg::pk::PkCircuitInput; + use crate::dkg::pk::PkCircuitData; use e3_fhe_params::BfvPreset; #[test] fn test_generate_pk_sample() { - let sample = PkCircuitInput::generate_sample(BfvPreset::InsecureThreshold512).unwrap(); + let sample = PkCircuitData::generate_sample(BfvPreset::InsecureThreshold512).unwrap(); assert_eq!(sample.public_key.c.c.len(), 2); } diff --git a/crates/zk-helpers/src/circuits/dkg/share_computation/circuit.rs b/crates/zk-helpers/src/circuits/dkg/share_computation/circuit.rs index b196de58f4..001c022461 100644 --- a/crates/zk-helpers/src/circuits/dkg/share_computation/circuit.rs +++ b/crates/zk-helpers/src/circuits/dkg/share_computation/circuit.rs @@ -23,8 +23,8 @@ impl Circuit for ShareComputationCircuit { const DKG_INPUT_TYPE: Option = None; } -pub struct ShareComputationCircuitInput { - /// Which secret type this input is for (determines which branch to use in input). +pub struct ShareComputationCircuitData { + /// Which secret type this data is for (determines which branch to use in data). pub dkg_input_type: DkgInputType, pub secret: CrtPolynomial, pub secret_sss: Vec>, diff --git a/crates/zk-helpers/src/circuits/dkg/share_computation/codegen.rs b/crates/zk-helpers/src/circuits/dkg/share_computation/codegen.rs index 5c8479ef8c..b12630b365 100644 --- a/crates/zk-helpers/src/circuits/dkg/share_computation/codegen.rs +++ b/crates/zk-helpers/src/circuits/dkg/share_computation/codegen.rs @@ -10,7 +10,7 @@ use crate::circuits::computation::CircuitComputation; use crate::circuits::computation::Computation; use crate::circuits::dkg::share_computation::{ utils::parity_matrix_constant_string, Bits, Inputs, ShareComputationCircuit, - ShareComputationCircuitInput, ShareComputationOutput, + ShareComputationCircuitData, ShareComputationOutput, }; use crate::circuits::{Artifacts, CircuitCodegen, CircuitsErrors, CodegenToml}; use crate::codegen::CodegenConfigs; @@ -25,19 +25,19 @@ use serde_json; /// Implementation of [`CircuitCodegen`] for [`ShareComputationCircuit`]. impl CircuitCodegen for ShareComputationCircuit { type Preset = BfvPreset; - type Input = ShareComputationCircuitInput; + type Data = ShareComputationCircuitData; type Error = CircuitsErrors; - fn codegen(&self, preset: Self::Preset, input: &Self::Input) -> Result { + fn codegen(&self, preset: Self::Preset, data: &Self::Data) -> Result { let ShareComputationOutput { inputs, bits, .. } = - ShareComputationCircuit::compute(preset, input)?; + ShareComputationCircuit::compute(preset, data)?; - let toml = generate_toml(&inputs, input.dkg_input_type.clone())?; + let toml = generate_toml(&inputs, data.dkg_input_type.clone())?; let configs = generate_configs( preset, &bits, - input.n_parties as usize, - input.threshold as usize, + data.n_parties as usize, + data.threshold as usize, )?; Ok(Artifacts { toml, configs }) @@ -152,7 +152,7 @@ mod tests { #[test] fn test_toml_generation_and_structure() { let committee = CiphernodesCommitteeSize::Small.values(); - let sample = ShareComputationCircuitInput::generate_sample( + let sample = ShareComputationCircuitData::generate_sample( BfvPreset::InsecureThreshold512, committee, DkgInputType::SecretKey, diff --git a/crates/zk-helpers/src/circuits/dkg/share_computation/computation.rs b/crates/zk-helpers/src/circuits/dkg/share_computation/computation.rs index 4f71202f8e..a9eda1e8d7 100644 --- a/crates/zk-helpers/src/circuits/dkg/share_computation/computation.rs +++ b/crates/zk-helpers/src/circuits/dkg/share_computation/computation.rs @@ -15,7 +15,7 @@ use crate::circuits::commitments::{ }; use crate::computation::DkgInputType; use crate::dkg::share_computation::ShareComputationCircuit; -use crate::dkg::share_computation::ShareComputationCircuitInput; +use crate::dkg::share_computation::ShareComputationCircuitData; use crate::CircuitsErrors; use crate::{bigint_3d_to_json_values, get_zkp_modulus}; use crate::{calculate_bit_width, crt_polynomial_to_toml_json}; @@ -39,14 +39,14 @@ pub struct ShareComputationOutput { /// Implementation of [`CircuitComputation`] for [`ShareComputationCircuit`]. impl CircuitComputation for ShareComputationCircuit { type Preset = BfvPreset; - type Input = ShareComputationCircuitInput; + type Data = ShareComputationCircuitData; type Output = ShareComputationOutput; type Error = CircuitsErrors; - fn compute(preset: Self::Preset, input: &Self::Input) -> Result { - let bounds = Bounds::compute(preset, input)?; + fn compute(preset: Self::Preset, data: &Self::Data) -> Result { + let bounds = Bounds::compute(preset, data)?; let bits = Bits::compute(preset, &bounds)?; - let inputs = Inputs::compute(preset, input)?; + let inputs = Inputs::compute(preset, data)?; Ok(ShareComputationOutput { bounds, @@ -97,16 +97,16 @@ pub struct Inputs { impl Computation for Configs { type Preset = BfvPreset; - type Input = ShareComputationCircuitInput; + type Data = ShareComputationCircuitData; type Error = CircuitsErrors; - fn compute(preset: Self::Preset, input: &Self::Input) -> Result { + fn compute(preset: Self::Preset, data: &Self::Data) -> Result { let (threshold_params, _) = build_pair_for_preset(preset).map_err(|e| CircuitsErrors::Sample(e.to_string()))?; let moduli = threshold_params.moduli().to_vec(); let l = moduli.len(); - let bounds = Bounds::compute(preset, input)?; + let bounds = Bounds::compute(preset, data)?; let bits = Bits::compute(preset, &bounds)?; Ok(Configs { @@ -121,10 +121,10 @@ impl Computation for Configs { impl Computation for Bits { type Preset = BfvPreset; - type Input = Bounds; + type Data = Bounds; type Error = crate::utils::ZkHelpersUtilsError; - fn compute(preset: Self::Preset, input: &Self::Input) -> Result { + fn compute(preset: Self::Preset, data: &Self::Data) -> Result { let (threshold_params, _) = build_pair_for_preset(preset) .map_err(|e| crate::utils::ZkHelpersUtilsError::ParseBound(e.to_string()))?; @@ -136,8 +136,8 @@ impl Computation for Bits { } Ok(Bits { - bit_sk_secret: calculate_bit_width(BigInt::from(input.sk_bound.clone())), - bit_e_sm_secret: calculate_bit_width(BigInt::from(input.e_sm_bound.clone())), + bit_sk_secret: calculate_bit_width(BigInt::from(data.sk_bound.clone())), + bit_e_sm_secret: calculate_bit_width(BigInt::from(data.e_sm_bound.clone())), bit_share, }) } @@ -145,10 +145,10 @@ impl Computation for Bits { impl Computation for Bounds { type Preset = BfvPreset; - type Input = ShareComputationCircuitInput; + type Data = ShareComputationCircuitData; type Error = CircuitsErrors; - fn compute(preset: Self::Preset, input: &Self::Input) -> Result { + fn compute(preset: Self::Preset, data: &Self::Data) -> Result { let (threshold_params, _) = build_pair_for_preset(preset).map_err(|e| CircuitsErrors::Sample(e.to_string()))?; let defaults = preset @@ -159,7 +159,7 @@ impl Computation for Bounds { let e_sm_config = SmudgingBoundCalculatorConfig::new( threshold_params, - input.n_parties as usize, + data.n_parties as usize, num_ciphertexts as usize, lambda as usize, ); @@ -177,21 +177,21 @@ impl Computation for Bounds { impl Computation for Inputs { type Preset = BfvPreset; - type Input = ShareComputationCircuitInput; + type Data = ShareComputationCircuitData; type Error = CircuitsErrors; - fn compute(preset: Self::Preset, input: &Self::Input) -> Result { + fn compute(preset: Self::Preset, data: &Self::Data) -> Result { let (threshold_params, _) = build_pair_for_preset(preset).map_err(|e| CircuitsErrors::Sample(e.to_string()))?; let moduli = threshold_params.moduli(); let degree = threshold_params.degree(); let num_moduli = moduli.len(); - let n_parties = input.n_parties as usize; + let n_parties = data.n_parties as usize; - let mut secret_crt = input.secret.clone(); - let sss = &input.secret_sss; + let mut secret_crt = data.secret.clone(); + let sss = &data.secret_sss; - if input.dkg_input_type == DkgInputType::SmudgingNoise { + if data.dkg_input_type == DkgInputType::SmudgingNoise { // Normalize secret_crt to [0, q_j) per limb so it matches what we put in y and what the circuit expects (e_sm_secret[j][i] == y[i][j][0]). secret_crt .reduce(moduli) @@ -215,9 +215,9 @@ impl Computation for Inputs { y.push(y_coeff); } - let bounds = Bounds::compute(preset, input)?; + let bounds = Bounds::compute(preset, data)?; let bits = Bits::compute(preset, &bounds)?; - let expected_secret_commitment = match input.dkg_input_type { + let expected_secret_commitment = match data.dkg_input_type { DkgInputType::SecretKey => { compute_share_computation_sk_commitment(secret_crt.limb(0), bits.bit_sk_secret) } @@ -266,13 +266,13 @@ mod tests { use crate::ciphernodes_committee::CiphernodesCommitteeSize; use crate::computation::DkgInputType; - use crate::dkg::share_computation::ShareComputationCircuitInput; + use crate::dkg::share_computation::ShareComputationCircuitData; use e3_fhe_params::BfvPreset; #[test] fn test_bound_and_bits_computation_consistency() { let committee = CiphernodesCommitteeSize::Small.values(); - let sample = ShareComputationCircuitInput::generate_sample( + let sample = ShareComputationCircuitData::generate_sample( BfvPreset::InsecureThreshold512, committee, DkgInputType::SecretKey, @@ -288,7 +288,7 @@ mod tests { #[test] fn test_input_smudging_noise_secret_consistency() { let committee = CiphernodesCommitteeSize::Small.values(); - let sample = ShareComputationCircuitInput::generate_sample( + let sample = ShareComputationCircuitData::generate_sample( BfvPreset::InsecureThreshold512, committee, DkgInputType::SmudgingNoise, @@ -313,7 +313,7 @@ mod tests { #[test] fn test_constants_json_roundtrip() { let committee = CiphernodesCommitteeSize::Small.values(); - let sample = ShareComputationCircuitInput::generate_sample( + let sample = ShareComputationCircuitData::generate_sample( BfvPreset::InsecureThreshold512, committee, DkgInputType::SecretKey, diff --git a/crates/zk-helpers/src/circuits/dkg/share_computation/mod.rs b/crates/zk-helpers/src/circuits/dkg/share_computation/mod.rs index 8578d3bdf1..d379ad5768 100644 --- a/crates/zk-helpers/src/circuits/dkg/share_computation/mod.rs +++ b/crates/zk-helpers/src/circuits/dkg/share_computation/mod.rs @@ -10,6 +10,6 @@ pub mod computation; pub mod sample; pub mod utils; -pub use circuit::{ShareComputationCircuit, ShareComputationCircuitInput}; +pub use circuit::{ShareComputationCircuit, ShareComputationCircuitData}; pub use computation::{Bits, Bounds, Configs, Inputs, ShareComputationOutput}; pub use sample::SecretShares; diff --git a/crates/zk-helpers/src/circuits/dkg/share_computation/sample.rs b/crates/zk-helpers/src/circuits/dkg/share_computation/sample.rs index 3ccd3ca61f..37cede3770 100644 --- a/crates/zk-helpers/src/circuits/dkg/share_computation/sample.rs +++ b/crates/zk-helpers/src/circuits/dkg/share_computation/sample.rs @@ -9,7 +9,7 @@ use crate::circuits::dkg::share_computation::utils::compute_parity_matrix; use crate::computation::DkgInputType; -use crate::dkg::share_computation::ShareComputationCircuitInput; +use crate::dkg::share_computation::ShareComputationCircuitData; use crate::CiphernodesCommittee; use crate::CircuitsErrors; use e3_fhe_params::build_pair_for_preset; @@ -22,7 +22,7 @@ use rand::thread_rng; pub type SecretShares = Vec>; -impl ShareComputationCircuitInput { +impl ShareComputationCircuitData { /// Generates sample data for the share-computation circuit. pub fn generate_sample( preset: BfvPreset, @@ -130,13 +130,13 @@ impl ShareComputationCircuitInput { mod tests { use crate::ciphernodes_committee::CiphernodesCommitteeSize; use crate::computation::DkgInputType; - use crate::dkg::share_computation::ShareComputationCircuitInput; + use crate::dkg::share_computation::ShareComputationCircuitData; use e3_fhe_params::BfvPreset; #[test] fn test_generate_secret_key_sample() { let committee = CiphernodesCommitteeSize::Small.values(); - let sample = ShareComputationCircuitInput::generate_sample( + let sample = ShareComputationCircuitData::generate_sample( BfvPreset::InsecureThreshold512, committee.clone(), DkgInputType::SecretKey, @@ -152,7 +152,7 @@ mod tests { #[test] fn test_generate_smudging_noise_sample() { let committee = CiphernodesCommitteeSize::Small.values(); - let sample = ShareComputationCircuitInput::generate_sample( + let sample = ShareComputationCircuitData::generate_sample( BfvPreset::InsecureThreshold512, committee.clone(), DkgInputType::SmudgingNoise, diff --git a/crates/zk-helpers/src/circuits/dkg/share_decryption/circuit.rs b/crates/zk-helpers/src/circuits/dkg/share_decryption/circuit.rs index e6c63b9a6a..e47ba1fba3 100644 --- a/crates/zk-helpers/src/circuits/dkg/share_decryption/circuit.rs +++ b/crates/zk-helpers/src/circuits/dkg/share_decryption/circuit.rs @@ -24,8 +24,8 @@ impl Circuit for ShareDecryptionCircuit { const DKG_INPUT_TYPE: Option = None; } -/// Input to the share-decryption circuit: secret key and honest parties' ciphertexts. -pub struct ShareDecryptionCircuitInput { +/// Data for the share-decryption circuit: secret key and honest parties' ciphertexts. +pub struct ShareDecryptionCircuitData { /// DKG secret key used to decrypt (private input). pub secret_key: SecretKey, /// Ciphertexts from H honest parties: [party_idx][mod_idx] (one ciphertext per party per TRBFV modulus). diff --git a/crates/zk-helpers/src/circuits/dkg/share_decryption/codegen.rs b/crates/zk-helpers/src/circuits/dkg/share_decryption/codegen.rs index b1af47b23b..408855cebf 100644 --- a/crates/zk-helpers/src/circuits/dkg/share_decryption/codegen.rs +++ b/crates/zk-helpers/src/circuits/dkg/share_decryption/codegen.rs @@ -10,7 +10,7 @@ use crate::circuits::computation::CircuitComputation; use crate::circuits::dkg::share_decryption::Configs; use crate::circuits::dkg::share_decryption::Inputs; use crate::circuits::dkg::share_decryption::ShareDecryptionCircuit; -use crate::circuits::dkg::share_decryption::ShareDecryptionCircuitInput; +use crate::circuits::dkg::share_decryption::ShareDecryptionCircuitData; use crate::circuits::dkg::share_decryption::ShareDecryptionOutput; use crate::circuits::{Artifacts, CircuitCodegen, CircuitsErrors, CodegenToml}; use crate::codegen::CodegenConfigs; @@ -21,14 +21,14 @@ use e3_fhe_params::BfvPreset; /// Implementation of [`CircuitCodegen`] for [`ShareDecryptionCircuit`]. impl CircuitCodegen for ShareDecryptionCircuit { type Preset = BfvPreset; - type Input = ShareDecryptionCircuitInput; + type Data = ShareDecryptionCircuitData; type Error = CircuitsErrors; - fn codegen(&self, preset: Self::Preset, input: &Self::Input) -> Result { - let ShareDecryptionOutput { inputs, .. } = ShareDecryptionCircuit::compute(preset, input)?; + fn codegen(&self, preset: Self::Preset, data: &Self::Data) -> Result { + let ShareDecryptionOutput { inputs, .. } = ShareDecryptionCircuit::compute(preset, data)?; let toml = generate_toml(&inputs)?; - let configs = Configs::compute(preset, input)?; + let configs = Configs::compute(preset, data)?; let configs_str = generate_configs(preset, &configs); Ok(Artifacts { @@ -74,7 +74,7 @@ mod tests { use super::*; use crate::ciphernodes_committee::CiphernodesCommitteeSize; - use crate::circuits::dkg::share_decryption::{Configs, ShareDecryptionCircuitInput}; + use crate::circuits::dkg::share_decryption::{Configs, ShareDecryptionCircuitData}; use crate::computation::{Computation, DkgInputType}; use crate::Circuit; use e3_fhe_params::BfvPreset; @@ -82,7 +82,7 @@ mod tests { #[test] fn test_toml_generation_and_structure() { let committee = CiphernodesCommitteeSize::Small.values(); - let sample = ShareDecryptionCircuitInput::generate_sample( + let sample = ShareDecryptionCircuitData::generate_sample( BfvPreset::InsecureThreshold512, committee, DkgInputType::SecretKey, @@ -101,7 +101,7 @@ mod tests { #[test] fn test_configs_generation_contains_expected() { let committee = CiphernodesCommitteeSize::Small.values(); - let sample = ShareDecryptionCircuitInput::generate_sample( + let sample = ShareDecryptionCircuitData::generate_sample( BfvPreset::InsecureThreshold512, committee, DkgInputType::SecretKey, diff --git a/crates/zk-helpers/src/circuits/dkg/share_decryption/computation.rs b/crates/zk-helpers/src/circuits/dkg/share_decryption/computation.rs index 65341234f0..3d504b983a 100644 --- a/crates/zk-helpers/src/circuits/dkg/share_decryption/computation.rs +++ b/crates/zk-helpers/src/circuits/dkg/share_decryption/computation.rs @@ -12,7 +12,7 @@ use crate::circuits::commitments::compute_share_encryption_commitment_from_message; use crate::dkg::share_decryption::ShareDecryptionCircuit; -use crate::dkg::share_decryption::ShareDecryptionCircuitInput; +use crate::dkg::share_decryption::ShareDecryptionCircuitData; use crate::CircuitsErrors; use crate::{bigint_2d_to_json_values, calculate_bit_width, poly_coefficients_to_toml_json}; use crate::{CircuitComputation, Computation}; @@ -38,14 +38,14 @@ pub struct ShareDecryptionOutput { /// Implementation of [`CircuitComputation`] for [`ShareDecryptionCircuit`]. impl CircuitComputation for ShareDecryptionCircuit { type Preset = BfvPreset; - type Input = ShareDecryptionCircuitInput; + type Data = ShareDecryptionCircuitData; type Output = ShareDecryptionOutput; type Error = CircuitsErrors; - fn compute(preset: Self::Preset, input: &Self::Input) -> Result { - let bounds = Bounds::compute(preset, input)?; + fn compute(preset: Self::Preset, data: &Self::Data) -> Result { + let bounds = Bounds::compute(preset, data)?; let bits = Bits::compute(preset, &bounds)?; - let inputs = Inputs::compute(preset, input)?; + let inputs = Inputs::compute(preset, data)?; Ok(ShareDecryptionOutput { bounds, @@ -93,18 +93,18 @@ pub struct Inputs { impl Computation for Configs { type Preset = BfvPreset; - type Input = ShareDecryptionCircuitInput; + type Data = ShareDecryptionCircuitData; type Error = CircuitsErrors; - fn compute(preset: Self::Preset, input: &Self::Input) -> Result { + fn compute(preset: Self::Preset, data: &Self::Data) -> Result { let (_, dkg_params) = build_pair_for_preset(preset) .map_err(|e| crate::utils::ZkHelpersUtilsError::ParseBound(e.to_string()))?; let n = dkg_params.degree() as usize; let l = dkg_params.moduli().len(); - let h = input.honest_ciphertexts.len(); + let h = data.honest_ciphertexts.len(); - let bounds = Bounds::compute(preset, &input)?; + let bounds = Bounds::compute(preset, &data)?; let bits = Bits::compute(preset, &bounds)?; Ok(Configs { @@ -119,10 +119,10 @@ impl Computation for Configs { impl Computation for Bits { type Preset = BfvPreset; - type Input = Bounds; + type Data = Bounds; type Error = crate::utils::ZkHelpersUtilsError; - fn compute(preset: Self::Preset, _: &Self::Input) -> Result { + fn compute(preset: Self::Preset, _: &Self::Data) -> Result { let (_, dkg_params) = build_pair_for_preset(preset) .map_err(|e| crate::utils::ZkHelpersUtilsError::ParseBound(e.to_string()))?; @@ -134,20 +134,20 @@ impl Computation for Bits { impl Computation for Bounds { type Preset = BfvPreset; - type Input = ShareDecryptionCircuitInput; + type Data = ShareDecryptionCircuitData; type Error = CircuitsErrors; - fn compute(_: Self::Preset, _: &Self::Input) -> Result { + fn compute(_: Self::Preset, _: &Self::Data) -> Result { Ok(Bounds {}) } } impl Computation for Inputs { type Preset = BfvPreset; - type Input = ShareDecryptionCircuitInput; + type Data = ShareDecryptionCircuitData; type Error = CircuitsErrors; - fn compute(preset: Self::Preset, input: &Self::Input) -> Result { + fn compute(preset: Self::Preset, data: &Self::Data) -> Result { let (threshold_params, dkg_params) = build_pair_for_preset(preset).map_err(|e| CircuitsErrors::Sample(e.to_string()))?; let threshold_l = threshold_params.moduli().len(); @@ -158,7 +158,7 @@ impl Computation for Inputs { let msg_bit = calculate_bit_width(BigInt::from(dkg_params.plaintext())); // Decrypt each ciphertext and compute its commitment - for party_cts in input.honest_ciphertexts.iter() { + for party_cts in data.honest_ciphertexts.iter() { if party_cts.len() < threshold_l { return Err(CircuitsErrors::Other(format!( "honest_ciphertexts party has {} ciphertexts but threshold_l is {}; \ @@ -171,7 +171,7 @@ impl Computation for Inputs { let mut party_shares = Vec::with_capacity(threshold_l); for mod_idx in 0..threshold_l { // Decrypt the ciphertext to get the plaintext share - let decrypted_pt = input.secret_key.try_decrypt(&party_cts[mod_idx]).unwrap(); + let decrypted_pt = data.secret_key.try_decrypt(&party_cts[mod_idx]).unwrap(); let share_coeffs = decrypted_pt.value.deref().to_vec(); party_commitments.push(compute_share_encryption_commitment_from_message( &Polynomial::from_u64_vector(share_coeffs.clone()), @@ -230,7 +230,7 @@ mod tests { #[test] fn test_bound_and_bits_computation_consistency() { let committee = CiphernodesCommitteeSize::Small.values(); - let sample = ShareDecryptionCircuitInput::generate_sample( + let sample = ShareDecryptionCircuitData::generate_sample( BfvPreset::InsecureThreshold512, committee, DkgInputType::SecretKey, @@ -247,7 +247,7 @@ mod tests { #[test] fn test_constants_json_roundtrip() { let committee = CiphernodesCommitteeSize::Small.values(); - let sample = ShareDecryptionCircuitInput::generate_sample( + let sample = ShareDecryptionCircuitData::generate_sample( BfvPreset::InsecureThreshold512, committee, DkgInputType::SecretKey, @@ -268,7 +268,7 @@ mod tests { #[test] fn test_input_decryption_consistency() { let committee = CiphernodesCommitteeSize::Small.values(); - let sample = ShareDecryptionCircuitInput::generate_sample( + let sample = ShareDecryptionCircuitData::generate_sample( BfvPreset::InsecureThreshold512, committee, DkgInputType::SecretKey, diff --git a/crates/zk-helpers/src/circuits/dkg/share_decryption/mod.rs b/crates/zk-helpers/src/circuits/dkg/share_decryption/mod.rs index c29f92bb13..79b9baa6e5 100644 --- a/crates/zk-helpers/src/circuits/dkg/share_decryption/mod.rs +++ b/crates/zk-helpers/src/circuits/dkg/share_decryption/mod.rs @@ -10,5 +10,5 @@ pub mod circuit; pub mod codegen; pub mod computation; pub mod sample; -pub use circuit::{ShareDecryptionCircuit, ShareDecryptionCircuitInput}; +pub use circuit::{ShareDecryptionCircuit, ShareDecryptionCircuitData}; pub use computation::{Bits, Bounds, Configs, Inputs, ShareDecryptionOutput}; diff --git a/crates/zk-helpers/src/circuits/dkg/share_decryption/sample.rs b/crates/zk-helpers/src/circuits/dkg/share_decryption/sample.rs index 2514e978bd..9b5ef24337 100644 --- a/crates/zk-helpers/src/circuits/dkg/share_decryption/sample.rs +++ b/crates/zk-helpers/src/circuits/dkg/share_decryption/sample.rs @@ -6,7 +6,7 @@ //! Sample data generation for the share-decryption circuit: honest ciphertexts, sum ciphertexts, secret key, and message. -use crate::circuits::dkg::share_decryption::circuit::ShareDecryptionCircuitInput; +use crate::circuits::dkg::share_decryption::circuit::ShareDecryptionCircuitData; use crate::computation::DkgInputType; use crate::CiphernodesCommittee; use crate::CircuitsErrors; @@ -21,7 +21,7 @@ use fhe_traits::FheEncoder; use fhe_traits::FheEncrypter; use rand::thread_rng; -impl ShareDecryptionCircuitInput { +impl ShareDecryptionCircuitData { /// Generates sample data for the share-decryption circuit (decrypts a sum of honest ciphertexts under DKG secret key). pub fn generate_sample( preset: BfvPreset, @@ -127,7 +127,7 @@ impl ShareDecryptionCircuitInput { honest_ciphertexts.push(party_cts); } - Ok(ShareDecryptionCircuitInput { + Ok(ShareDecryptionCircuitData { honest_ciphertexts, secret_key: dkg_secret_key, }) @@ -144,7 +144,7 @@ mod tests { #[test] fn test_generate_secret_key_sample() { let committee = CiphernodesCommitteeSize::Small.values(); - let sample = ShareDecryptionCircuitInput::generate_sample( + let sample = ShareDecryptionCircuitData::generate_sample( BfvPreset::InsecureThreshold512, committee.clone(), DkgInputType::SecretKey, @@ -161,7 +161,7 @@ mod tests { #[test] fn test_generate_smudging_noise_sample() { let committee = CiphernodesCommitteeSize::Small.values(); - let sample = ShareDecryptionCircuitInput::generate_sample( + let sample = ShareDecryptionCircuitData::generate_sample( BfvPreset::InsecureThreshold512, committee.clone(), DkgInputType::SmudgingNoise, diff --git a/crates/zk-helpers/src/circuits/dkg/share_encryption/circuit.rs b/crates/zk-helpers/src/circuits/dkg/share_encryption/circuit.rs index 40bd0bbb69..864255f60d 100644 --- a/crates/zk-helpers/src/circuits/dkg/share_encryption/circuit.rs +++ b/crates/zk-helpers/src/circuits/dkg/share_encryption/circuit.rs @@ -28,7 +28,7 @@ impl Circuit for ShareEncryptionCircuit { } /// Input to the share-encryption circuit: plaintext, ciphertext, keys, and encryption randomness. -pub struct ShareEncryptionCircuitInput { +pub struct ShareEncryptionCircuitData { /// Plaintext (encoded share row). pub plaintext: Plaintext, /// Ciphertext (encryption under public_key). diff --git a/crates/zk-helpers/src/circuits/dkg/share_encryption/codegen.rs b/crates/zk-helpers/src/circuits/dkg/share_encryption/codegen.rs index fc71f9f7e5..5837d1fdf1 100644 --- a/crates/zk-helpers/src/circuits/dkg/share_encryption/codegen.rs +++ b/crates/zk-helpers/src/circuits/dkg/share_encryption/codegen.rs @@ -10,7 +10,7 @@ use crate::circuits::computation::CircuitComputation; use crate::circuits::dkg::share_encryption::Configs; use crate::circuits::dkg::share_encryption::Inputs; use crate::circuits::dkg::share_encryption::ShareEncryptionCircuit; -use crate::circuits::dkg::share_encryption::ShareEncryptionCircuitInput; +use crate::circuits::dkg::share_encryption::ShareEncryptionCircuitData; use crate::circuits::dkg::share_encryption::ShareEncryptionOutput; use crate::circuits::{Artifacts, CircuitCodegen, CircuitsErrors, CodegenToml}; use crate::codegen::CodegenConfigs; @@ -22,14 +22,14 @@ use e3_fhe_params::BfvPreset; /// Implementation of [`CircuitCodegen`] for [`ShareEncryptionCircuit`]. impl CircuitCodegen for ShareEncryptionCircuit { type Preset = BfvPreset; - type Input = ShareEncryptionCircuitInput; + type Data = ShareEncryptionCircuitData; type Error = CircuitsErrors; - fn codegen(&self, preset: Self::Preset, input: &Self::Input) -> Result { - let ShareEncryptionOutput { inputs, .. } = ShareEncryptionCircuit::compute(preset, input)?; + fn codegen(&self, preset: Self::Preset, data: &Self::Data) -> Result { + let ShareEncryptionOutput { inputs, .. } = ShareEncryptionCircuit::compute(preset, data)?; let toml = generate_toml(&inputs)?; - let configs = Configs::compute(preset, input)?; + let configs = Configs::compute(preset, data)?; let configs_str = generate_configs(preset, &configs); Ok(Artifacts { @@ -185,7 +185,7 @@ pub global {}_CONFIGS: ShareEncryptionConfigs = ShareEncryptionConfigs::new( mod tests { use super::*; - use crate::circuits::dkg::share_encryption::{Bounds, ShareEncryptionCircuitInput}; + use crate::circuits::dkg::share_encryption::{Bounds, ShareEncryptionCircuitData}; use crate::computation::Computation; use crate::computation::DkgInputType; use crate::{CiphernodesCommitteeSize, Circuit}; @@ -195,7 +195,7 @@ mod tests { fn test_toml_generation_and_structure() { let committee = CiphernodesCommitteeSize::Small.values(); let sd = BfvPreset::InsecureThreshold512.search_defaults().unwrap(); - let sample = ShareEncryptionCircuitInput::generate_sample( + let sample = ShareEncryptionCircuitData::generate_sample( BfvPreset::InsecureThreshold512, committee.clone(), DkgInputType::SecretKey, @@ -218,7 +218,7 @@ mod tests { fn test_configs_generation_contains_expected() { let committee = CiphernodesCommitteeSize::Small.values(); let sd = BfvPreset::InsecureThreshold512.search_defaults().unwrap(); - let sample = ShareEncryptionCircuitInput::generate_sample( + let sample = ShareEncryptionCircuitData::generate_sample( BfvPreset::InsecureThreshold512, committee.clone(), DkgInputType::SecretKey, diff --git a/crates/zk-helpers/src/circuits/dkg/share_encryption/computation.rs b/crates/zk-helpers/src/circuits/dkg/share_encryption/computation.rs index 53b5b5ea1b..fb3265baa3 100644 --- a/crates/zk-helpers/src/circuits/dkg/share_encryption/computation.rs +++ b/crates/zk-helpers/src/circuits/dkg/share_encryption/computation.rs @@ -16,7 +16,7 @@ use crate::circuits::commitments::{ use std::ops::Deref; use crate::dkg::share_encryption::ShareEncryptionCircuit; -use crate::dkg::share_encryption::ShareEncryptionCircuitInput; +use crate::dkg::share_encryption::ShareEncryptionCircuitData; use crate::get_zkp_modulus; use crate::math::{compute_k0is, compute_q_mod_t, compute_q_product}; use crate::math::{cyclotomic_polynomial, decompose_residue}; @@ -55,14 +55,14 @@ pub struct ShareEncryptionOutput { /// Implementation of [`CircuitComputation`] for [`ShareEncryptionCircuit`]. impl CircuitComputation for ShareEncryptionCircuit { type Preset = BfvPreset; - type Input = ShareEncryptionCircuitInput; + type Data = ShareEncryptionCircuitData; type Output = ShareEncryptionOutput; type Error = CircuitsErrors; - fn compute(preset: Self::Preset, input: &Self::Input) -> Result { - let bounds = Bounds::compute(preset, input)?; + fn compute(preset: Self::Preset, data: &Self::Data) -> Result { + let bounds = Bounds::compute(preset, data)?; let bits = Bits::compute(preset, &bounds)?; - let inputs = Inputs::compute(preset, input)?; + let inputs = Inputs::compute(preset, data)?; Ok(ShareEncryptionOutput { bounds, @@ -144,10 +144,10 @@ pub struct Inputs { impl Computation for Configs { type Preset = BfvPreset; - type Input = ShareEncryptionCircuitInput; + type Data = ShareEncryptionCircuitData; type Error = CircuitsErrors; - fn compute(preset: Self::Preset, input: &Self::Input) -> Result { + fn compute(preset: Self::Preset, data: &Self::Data) -> Result { let (_, dkg_params) = build_pair_for_preset(preset).map_err(|e| CircuitsErrors::Sample(e.to_string()))?; @@ -163,7 +163,7 @@ impl Computation for Configs { let k0is = compute_k0is(&moduli, plaintext)?; - let bounds = Bounds::compute(preset, input)?; + let bounds = Bounds::compute(preset, data)?; let bits = Bits::compute(preset, &bounds)?; Ok(Configs { @@ -179,26 +179,25 @@ impl Computation for Configs { impl Computation for Bits { type Preset = BfvPreset; - type Input = Bounds; + type Data = Bounds; type Error = crate::utils::ZkHelpersUtilsError; - fn compute(_: Self::Preset, input: &Self::Input) -> Result { - let max_pk_bound = input.pk_bounds.iter().max().unwrap(); - let max_r2_bound = input.r2_bounds.iter().max().unwrap(); - let max_p1_bound = input.p1_bounds.iter().max().unwrap(); - let max_p2_bound = input.p2_bounds.iter().max().unwrap(); + fn compute(_: Self::Preset, data: &Self::Data) -> Result { + let max_pk_bound = data.pk_bounds.iter().max().unwrap(); + let max_r2_bound = data.r2_bounds.iter().max().unwrap(); + let max_p1_bound = data.p1_bounds.iter().max().unwrap(); + let max_p2_bound = data.p2_bounds.iter().max().unwrap(); let pk_bit = calculate_bit_width(BigInt::from(max_pk_bound.clone())); let ct_bit = calculate_bit_width(BigInt::from(max_pk_bound.clone())); - let u_bit = calculate_bit_width(BigInt::from(input.u_bound.clone())); - let e0_bit = calculate_bit_width(BigInt::from(input.e0_bound.clone())); - let e1_bit = calculate_bit_width(BigInt::from(input.e1_bound.clone())); - let msg_bit = calculate_bit_width(BigInt::from(input.msg_bound.clone())); + let u_bit = calculate_bit_width(BigInt::from(data.u_bound.clone())); + let e0_bit = calculate_bit_width(BigInt::from(data.e0_bound.clone())); + let e1_bit = calculate_bit_width(BigInt::from(data.e1_bound.clone())); + let msg_bit = calculate_bit_width(BigInt::from(data.msg_bound.clone())); let r1_bit = calculate_bit_width(BigInt::from( - input - .r1_low_bounds + data.r1_low_bounds .iter() - .chain(input.r1_up_bounds.iter()) + .chain(data.r1_up_bounds.iter()) .max() .unwrap() .clone(), @@ -224,10 +223,10 @@ impl Computation for Bits { impl Computation for Bounds { type Preset = BfvPreset; - type Input = ShareEncryptionCircuitInput; + type Data = ShareEncryptionCircuitData; type Error = CircuitsErrors; - fn compute(preset: Self::Preset, _: &Self::Input) -> Result { + fn compute(preset: Self::Preset, _: &Self::Data) -> Result { let (_, dkg_params) = build_pair_for_preset(preset).map_err(|e| CircuitsErrors::Sample(e.to_string()))?; @@ -346,22 +345,22 @@ impl Computation for Bounds { impl Computation for Inputs { type Preset = BfvPreset; - type Input = ShareEncryptionCircuitInput; + type Data = ShareEncryptionCircuitData; type Error = CircuitsErrors; - fn compute(preset: Self::Preset, input: &Self::Input) -> Result { + fn compute(preset: Self::Preset, data: &Self::Data) -> Result { let (_, dkg_params) = build_pair_for_preset(preset).map_err(|e| CircuitsErrors::Sample(e.to_string()))?; - let ctx = dkg_params.ctx_at_level(input.plaintext.level())?; + let ctx = dkg_params.ctx_at_level(data.plaintext.level())?; let pk_bit = compute_modulus_bit(&dkg_params); let msg_bit = compute_msg_bit(&dkg_params); - let pk = input.public_key.clone(); - let pt = input.plaintext.clone(); + let pk = data.public_key.clone(); + let pt = data.plaintext.clone(); // Reconstruct e0 in mod Q so that e0_poly row i matches e0_rns row i (same ctx). - let mut e0_power = input.e0_rns.clone(); + let mut e0_power = data.e0_rns.clone(); e0_power.change_representation(Representation::PowerBasis); let e0_mod_q: Vec = Vec::::from(&e0_power); let e0_bigints: Vec = e0_mod_q.iter().map(|c| c.to_bigint().unwrap()).collect(); @@ -388,10 +387,10 @@ impl Computation for Inputs { let mut k1 = Polynomial::from_u64_vector(k1_u64); k1.center(&BigInt::from(t.modulus())); - let mut u_rns_copy = input.u_rns.clone(); - let mut e0_rns_copy = input.e0_rns.clone(); + let mut u_rns_copy = data.u_rns.clone(); + let mut e0_rns_copy = data.e0_rns.clone(); let mut e0_poly_copy = e0.clone(); - let mut e1_rns_copy = input.e1_rns.clone(); + let mut e1_rns_copy = data.e1_rns.clone(); u_rns_copy.change_representation(Representation::PowerBasis); e0_rns_copy.change_representation(Representation::PowerBasis); @@ -432,8 +431,8 @@ impl Computation for Inputs { }; // Extract and convert ciphertext and public key polynomials - let mut ct0 = input.ciphertext.c[0].clone(); // ct0 - let mut ct1 = input.ciphertext.c[1].clone(); // ct1 + let mut ct0 = data.ciphertext.c[0].clone(); // ct0 + let mut ct1 = data.ciphertext.c[1].clone(); // ct1 ct0.change_representation(Representation::PowerBasis); ct1.change_representation(Representation::PowerBasis); @@ -756,7 +755,7 @@ mod tests { fn test_bound_and_bits_computation_consistency() { let sd = BfvPreset::InsecureThreshold512.search_defaults().unwrap(); let committee = CiphernodesCommitteeSize::Small.values(); - let sample = ShareEncryptionCircuitInput::generate_sample( + let sample = ShareEncryptionCircuitData::generate_sample( BfvPreset::InsecureThreshold512, committee, DkgInputType::SecretKey, @@ -779,7 +778,7 @@ mod tests { fn test_constants_json_roundtrip() { let sd = BfvPreset::InsecureThreshold512.search_defaults().unwrap(); let committee = CiphernodesCommitteeSize::Small.values(); - let sample = ShareEncryptionCircuitInput::generate_sample( + let sample = ShareEncryptionCircuitData::generate_sample( BfvPreset::InsecureThreshold512, committee, DkgInputType::SecretKey, @@ -804,7 +803,7 @@ mod tests { fn test_input_message_consistency() { let sd = BfvPreset::InsecureThreshold512.search_defaults().unwrap(); let committee = CiphernodesCommitteeSize::Small.values(); - let sample = ShareEncryptionCircuitInput::generate_sample( + let sample = ShareEncryptionCircuitData::generate_sample( BfvPreset::InsecureThreshold512, committee, DkgInputType::SecretKey, diff --git a/crates/zk-helpers/src/circuits/dkg/share_encryption/mod.rs b/crates/zk-helpers/src/circuits/dkg/share_encryption/mod.rs index 578cfc4d8a..bf107eac66 100644 --- a/crates/zk-helpers/src/circuits/dkg/share_encryption/mod.rs +++ b/crates/zk-helpers/src/circuits/dkg/share_encryption/mod.rs @@ -10,5 +10,5 @@ pub mod circuit; pub mod codegen; pub mod computation; pub mod sample; -pub use circuit::{ShareEncryptionCircuit, ShareEncryptionCircuitInput}; +pub use circuit::{ShareEncryptionCircuit, ShareEncryptionCircuitData}; pub use computation::{Bits, Bounds, Configs, Inputs, ShareEncryptionOutput}; diff --git a/crates/zk-helpers/src/circuits/dkg/share_encryption/sample.rs b/crates/zk-helpers/src/circuits/dkg/share_encryption/sample.rs index 6bc307074a..f1a63142ae 100644 --- a/crates/zk-helpers/src/circuits/dkg/share_encryption/sample.rs +++ b/crates/zk-helpers/src/circuits/dkg/share_encryption/sample.rs @@ -7,7 +7,7 @@ //! Sample data generation for the share-encryption circuit: DKG public key, plaintext, //! ciphertext, and encryption randomness (u_rns, e0_rns, e1_rns) for testing and codegen. -use crate::circuits::dkg::share_encryption::circuit::ShareEncryptionCircuitInput; +use crate::circuits::dkg::share_encryption::circuit::ShareEncryptionCircuitData; use crate::computation::DkgInputType; use crate::CiphernodesCommittee; use crate::CircuitsErrors; @@ -20,7 +20,7 @@ use fhe::trbfv::{ShareManager, TRBFV}; use fhe_traits::FheEncoder; use rand::thread_rng; -impl ShareEncryptionCircuitInput { +impl ShareEncryptionCircuitData { /// Generates sample data for the share-encryption circuit (encrypts a share row under DKG pk). pub fn generate_sample( preset: BfvPreset, @@ -99,7 +99,7 @@ impl ShareEncryptionCircuitInput { .try_encrypt_extended(&pt, &mut rng) .map_err(|e| CircuitsErrors::Sample(format!("Failed to encrypt extended: {:?}", e)))?; - Ok(ShareEncryptionCircuitInput { + Ok(ShareEncryptionCircuitData { plaintext: pt, ciphertext: _ct, public_key: dkg_public_key, @@ -121,7 +121,7 @@ mod tests { fn test_generate_secret_key_sample() { let committee = CiphernodesCommitteeSize::Small.values(); let sd = BfvPreset::InsecureThreshold512.search_defaults().unwrap(); - let sample = ShareEncryptionCircuitInput::generate_sample( + let sample = ShareEncryptionCircuitData::generate_sample( BfvPreset::InsecureThreshold512, committee.clone(), DkgInputType::SecretKey, @@ -154,7 +154,7 @@ mod tests { fn test_generate_smudging_noise_sample() { let committee = CiphernodesCommitteeSize::Small.values(); let sd = BfvPreset::InsecureThreshold512.search_defaults().unwrap(); - let sample = ShareEncryptionCircuitInput::generate_sample( + let sample = ShareEncryptionCircuitData::generate_sample( BfvPreset::InsecureThreshold512, committee, DkgInputType::SmudgingNoise, diff --git a/crates/zk-helpers/src/circuits/threshold/decrypted_shares_aggregation/circuit.rs b/crates/zk-helpers/src/circuits/threshold/decrypted_shares_aggregation/circuit.rs index 89c7284f84..53b7e2a2d0 100644 --- a/crates/zk-helpers/src/circuits/threshold/decrypted_shares_aggregation/circuit.rs +++ b/crates/zk-helpers/src/circuits/threshold/decrypted_shares_aggregation/circuit.rs @@ -24,7 +24,7 @@ impl Circuit for DecryptedSharesAggregationCircuit { /// Raw input for circuit input computation: decryption share polynomials from T+1 parties, /// party IDs (1-based), and decoded message. Inputs::compute runs Lagrange + CRT. #[derive(Debug, Clone)] -pub struct DecryptedSharesAggregationCircuitInput { +pub struct DecryptedSharesAggregationCircuitData { pub committee: CiphernodesCommittee, /// Decryption shares from T+1 parties (Poly in RNS form). pub d_share_polys: Vec, diff --git a/crates/zk-helpers/src/circuits/threshold/decrypted_shares_aggregation/codegen.rs b/crates/zk-helpers/src/circuits/threshold/decrypted_shares_aggregation/codegen.rs index 947dffaa0a..6386fec5c2 100644 --- a/crates/zk-helpers/src/circuits/threshold/decrypted_shares_aggregation/codegen.rs +++ b/crates/zk-helpers/src/circuits/threshold/decrypted_shares_aggregation/codegen.rs @@ -11,7 +11,7 @@ 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, Inputs}; -use crate::threshold::decrypted_shares_aggregation::DecryptedSharesAggregationCircuitInput; +use crate::threshold::decrypted_shares_aggregation::DecryptedSharesAggregationCircuitData; use crate::Circuit; use crate::CircuitCodegen; use crate::CircuitsErrors; @@ -20,11 +20,11 @@ use crate::{Artifacts, CodegenConfigs, CodegenToml}; /// Implementation of [`CircuitCodegen`] for [`DecryptedSharesAggregationCircuit`]. impl CircuitCodegen for DecryptedSharesAggregationCircuit { type Preset = BfvPreset; - type Input = DecryptedSharesAggregationCircuitInput; + type Data = DecryptedSharesAggregationCircuitData; type Error = CircuitsErrors; - fn codegen(&self, preset: Self::Preset, input: &Self::Input) -> Result { - let inputs = Inputs::compute(preset, input)?; + fn codegen(&self, preset: Self::Preset, data: &Self::Data) -> Result { + let inputs = Inputs::compute(preset, data)?; let configs = Configs::compute(preset, &())?; let toml = generate_toml(inputs)?; @@ -113,7 +113,7 @@ mod tests { let preset = BfvPreset::InsecureThreshold512; let committee = CiphernodesCommitteeSize::Small.values(); let input = - DecryptedSharesAggregationCircuitInput::generate_sample(preset, committee).unwrap(); + DecryptedSharesAggregationCircuitData::generate_sample(preset, committee).unwrap(); let circuit = DecryptedSharesAggregationCircuit; let artifacts = circuit.codegen(preset, &input).unwrap(); diff --git a/crates/zk-helpers/src/circuits/threshold/decrypted_shares_aggregation/computation.rs b/crates/zk-helpers/src/circuits/threshold/decrypted_shares_aggregation/computation.rs index 677481536c..26cba2ea26 100644 --- a/crates/zk-helpers/src/circuits/threshold/decrypted_shares_aggregation/computation.rs +++ b/crates/zk-helpers/src/circuits/threshold/decrypted_shares_aggregation/computation.rs @@ -13,7 +13,7 @@ use crate::calculate_bit_width; use crate::get_zkp_modulus; use crate::threshold::decrypted_shares_aggregation::circuit::DecryptedSharesAggregationCircuit; -use crate::threshold::decrypted_shares_aggregation::circuit::DecryptedSharesAggregationCircuitInput; +use crate::threshold::decrypted_shares_aggregation::circuit::DecryptedSharesAggregationCircuitData; use crate::threshold::decrypted_shares_aggregation::utils; use crate::CircuitsErrors; use crate::{CircuitComputation, Computation}; @@ -35,14 +35,14 @@ pub struct DecryptedSharesAggregationComputationOutput { impl CircuitComputation for DecryptedSharesAggregationCircuit { type Preset = BfvPreset; - type Input = DecryptedSharesAggregationCircuitInput; + type Data = DecryptedSharesAggregationCircuitData; type Output = DecryptedSharesAggregationComputationOutput; type Error = CircuitsErrors; - fn compute(preset: Self::Preset, input: &Self::Input) -> Result { + fn compute(preset: Self::Preset, data: &Self::Data) -> Result { let bounds = Bounds::compute(preset, &())?; let bits = Bits::compute(preset, &bounds)?; - let inputs = Inputs::compute(preset, input)?; + let inputs = Inputs::compute(preset, data)?; Ok(DecryptedSharesAggregationComputationOutput { bounds, @@ -97,10 +97,10 @@ pub struct Inputs { impl Computation for Bounds { type Preset = BfvPreset; - type Input = (); + type Data = (); type Error = CircuitsErrors; - fn compute(preset: Self::Preset, _: &Self::Input) -> Result { + fn compute(preset: Self::Preset, _: &Self::Data) -> Result { let (threshold_params, _) = build_pair_for_preset(preset).map_err(|e| CircuitsErrors::Other(e.to_string()))?; let moduli = threshold_params.moduli(); @@ -114,21 +114,21 @@ impl Computation for Bounds { impl Computation for Bits { type Preset = BfvPreset; - type Input = Bounds; + type Data = Bounds; type Error = CircuitsErrors; - fn compute(_: Self::Preset, bounds: &Self::Input) -> Result { - let noise_bit = calculate_bit_width(BigInt::from(bounds.delta_half.clone())); + fn compute(_: Self::Preset, data: &Self::Data) -> Result { + let noise_bit = calculate_bit_width(BigInt::from(data.delta_half.clone())); Ok(Bits { noise_bit }) } } impl Computation for Configs { type Preset = BfvPreset; - type Input = (); + type Data = (); type Error = CircuitsErrors; - fn compute(preset: Self::Preset, _: &Self::Input) -> Result { + fn compute(preset: Self::Preset, _: &Self::Data) -> Result { let (threshold_params, _) = build_pair_for_preset(preset).map_err(|e| CircuitsErrors::Other(e.to_string()))?; let moduli = threshold_params.moduli().to_vec(); @@ -154,10 +154,10 @@ impl Computation for Configs { impl Computation for Inputs { type Preset = BfvPreset; - type Input = DecryptedSharesAggregationCircuitInput; + type Data = DecryptedSharesAggregationCircuitData; type Error = CircuitsErrors; - fn compute(preset: Self::Preset, input: &Self::Input) -> Result { + fn compute(preset: Self::Preset, data: &Self::Data) -> Result { let configs = Configs::compute(preset, &())?; let (threshold_params, _) = build_pair_for_preset(preset).map_err(|e| CircuitsErrors::Other(e.to_string()))?; @@ -166,11 +166,11 @@ impl Computation for Inputs { .map_err(|e| CircuitsErrors::Other(format!("ctx_at_level: {:?}", e)))?; let num_moduli = ctx.moduli().len(); let degree = ctx.degree; - let threshold = input.committee.threshold; + let threshold = data.committee.threshold; let max_msg_non_zero_coeffs = configs.max_msg_non_zero_coeffs; // Copy to PowerBasis for coefficient extraction - let d_share_polys: Vec<_> = input + let d_share_polys: Vec<_> = data .d_share_polys .iter() .map(|p| { @@ -214,18 +214,18 @@ impl Computation for Inputs { } // 2. Party IDs (1-based) - let party_ids: Vec = input + let party_ids: Vec = data .reconstructing_parties .iter() .map(|&x| BigInt::from(x)) .collect(); // 3. Message (pad to degree for computation, then truncate to MAX_MSG_NON_ZERO_COEFFS for input) - let mut message: Vec = input.message_vec.iter().map(|&x| BigInt::from(x)).collect(); + let mut message: Vec = data.message_vec.iter().map(|&x| BigInt::from(x)).collect(); message.resize(degree, BigInt::zero()); // 4. u^{(l)} via Lagrange per modulus - let reconstructing_parties = &input.reconstructing_parties; + let reconstructing_parties = &data.reconstructing_parties; let mut u_per_modulus: Vec> = Vec::new(); for m in 0..num_moduli { let modulus = ctx.moduli()[m]; @@ -299,6 +299,7 @@ impl Computation for Inputs { u_global, crt_quotients, }; + Ok(inputs.standard_form()) } } @@ -381,7 +382,7 @@ impl Inputs { #[cfg(test)] mod tests { use super::*; - use crate::threshold::decrypted_shares_aggregation::DecryptedSharesAggregationCircuitInput; + use crate::threshold::decrypted_shares_aggregation::DecryptedSharesAggregationCircuitData; use crate::CiphernodesCommitteeSize; #[test] @@ -410,7 +411,7 @@ mod tests { let preset = BfvPreset::InsecureThreshold512; let committee = CiphernodesCommitteeSize::Small.values(); let input = - DecryptedSharesAggregationCircuitInput::generate_sample(preset, committee.clone()) + DecryptedSharesAggregationCircuitData::generate_sample(preset, committee.clone()) .unwrap(); let out = DecryptedSharesAggregationCircuit::compute(preset, &input).unwrap(); diff --git a/crates/zk-helpers/src/circuits/threshold/decrypted_shares_aggregation/sample.rs b/crates/zk-helpers/src/circuits/threshold/decrypted_shares_aggregation/sample.rs index 82c563fc89..e44b273978 100644 --- a/crates/zk-helpers/src/circuits/threshold/decrypted_shares_aggregation/sample.rs +++ b/crates/zk-helpers/src/circuits/threshold/decrypted_shares_aggregation/sample.rs @@ -14,7 +14,7 @@ use crate::circuits::computation::Computation; use crate::threshold::decrypted_shares_aggregation::computation::Configs; use crate::CircuitsErrors; use crate::{ - threshold::decrypted_shares_aggregation::DecryptedSharesAggregationCircuitInput, + threshold::decrypted_shares_aggregation::DecryptedSharesAggregationCircuitData, CiphernodesCommittee, }; use e3_fhe_params::{build_pair_for_preset, BfvPreset}; @@ -38,7 +38,7 @@ struct Party { es_poly_sum: Poly, } -impl DecryptedSharesAggregationCircuitInput { +impl DecryptedSharesAggregationCircuitData { /// Generates sample data for the decrypted shares aggregation circuit: /// TRBFV setup, parties with sk/pk shares and smudging error shares, share collection /// and aggregation, encryption of a message, T+1 decryption shares, and threshold decrypt. @@ -255,7 +255,7 @@ impl DecryptedSharesAggregationCircuitInput { let message_vec = Vec::::try_decode(&plaintext, Encoding::poly()) .map_err(|e| CircuitsErrors::Sample(format!("Failed to decode plaintext: {:?}", e)))?; - Ok(DecryptedSharesAggregationCircuitInput { + Ok(DecryptedSharesAggregationCircuitData { committee, d_share_polys, reconstructing_parties, @@ -268,7 +268,7 @@ impl DecryptedSharesAggregationCircuitInput { mod tests { use crate::{ computation::Computation, - threshold::decrypted_shares_aggregation::{DecryptedSharesAggregationCircuitInput, Inputs}, + threshold::decrypted_shares_aggregation::{DecryptedSharesAggregationCircuitData, Inputs}, CiphernodesCommitteeSize, }; use e3_fhe_params::BfvPreset; @@ -281,7 +281,7 @@ mod tests { let committee = CiphernodesCommitteeSize::Small.values(); let sample = - DecryptedSharesAggregationCircuitInput::generate_sample(preset, committee).unwrap(); + DecryptedSharesAggregationCircuitData::generate_sample(preset, committee).unwrap(); let inputs = Inputs::compute(preset, &sample).unwrap(); assert_eq!( @@ -305,7 +305,7 @@ mod tests { let preset = BfvPreset::InsecureThreshold512; let committee = CiphernodesCommitteeSize::Small.values(); let sample = - DecryptedSharesAggregationCircuitInput::generate_sample(preset, committee).unwrap(); + DecryptedSharesAggregationCircuitData::generate_sample(preset, committee).unwrap(); let inputs = Inputs::compute(preset, &sample).unwrap(); let configs = Configs::compute(preset, &()).unwrap(); let n = configs.max_msg_non_zero_coeffs; diff --git a/crates/zk-helpers/src/circuits/threshold/pk_aggregation/circuit.rs b/crates/zk-helpers/src/circuits/threshold/pk_aggregation/circuit.rs index 0b5e5f6799..14ab69c2d3 100644 --- a/crates/zk-helpers/src/circuits/threshold/pk_aggregation/circuit.rs +++ b/crates/zk-helpers/src/circuits/threshold/pk_aggregation/circuit.rs @@ -22,7 +22,7 @@ impl Circuit for PkAggregationCircuit { } #[derive(Debug, Clone)] -pub struct PkAggregationCircuitInput { +pub struct PkAggregationCircuitData { pub committee: CiphernodesCommittee, pub public_key: PublicKey, pub pk0_shares: Vec, diff --git a/crates/zk-helpers/src/circuits/threshold/pk_aggregation/codegen.rs b/crates/zk-helpers/src/circuits/threshold/pk_aggregation/codegen.rs index b29e99c6c3..faccf11d46 100644 --- a/crates/zk-helpers/src/circuits/threshold/pk_aggregation/codegen.rs +++ b/crates/zk-helpers/src/circuits/threshold/pk_aggregation/codegen.rs @@ -11,7 +11,7 @@ use e3_fhe_params::BfvPreset; use crate::circuits::computation::Computation; use crate::threshold::pk_aggregation::circuit::PkAggregationCircuit; use crate::threshold::pk_aggregation::computation::{Configs, Inputs}; -use crate::threshold::pk_aggregation::PkAggregationCircuitInput; +use crate::threshold::pk_aggregation::PkAggregationCircuitData; use crate::utils::join_display; use crate::CircuitCodegen; use crate::CircuitsErrors; @@ -21,11 +21,11 @@ use crate::{Circuit, CodegenConfigs}; /// Implementation of [`CircuitCodegen`] for [`PkAggregationCircuit`]. impl CircuitCodegen for PkAggregationCircuit { type Preset = BfvPreset; - type Input = PkAggregationCircuitInput; + type Data = PkAggregationCircuitData; type Error = CircuitsErrors; - fn codegen(&self, preset: Self::Preset, input: &Self::Input) -> Result { - let inputs = Inputs::compute(preset, input)?; + fn codegen(&self, preset: Self::Preset, data: &Self::Data) -> Result { + let inputs = Inputs::compute(preset, data)?; let configs = Configs::compute(preset, &())?; let toml = generate_toml(inputs)?; @@ -85,7 +85,7 @@ mod tests { let committee = CiphernodesCommitteeSize::Small.values(); let prefix: &str = ::PREFIX; - let sample = PkAggregationCircuitInput::generate_sample(preset, committee).unwrap(); + let sample = PkAggregationCircuitData::generate_sample(preset, committee).unwrap(); let inputs = Inputs::compute(preset, &sample).unwrap(); let configs = Configs::compute(preset, &()).unwrap(); diff --git a/crates/zk-helpers/src/circuits/threshold/pk_aggregation/computation.rs b/crates/zk-helpers/src/circuits/threshold/pk_aggregation/computation.rs index 61e8e2d7df..0234aee8fb 100644 --- a/crates/zk-helpers/src/circuits/threshold/pk_aggregation/computation.rs +++ b/crates/zk-helpers/src/circuits/threshold/pk_aggregation/computation.rs @@ -15,7 +15,7 @@ use crate::compute_pk_aggregation_commitment; use crate::crt_polynomial_to_toml_json; use crate::get_zkp_modulus; use crate::threshold::pk_aggregation::circuit::PkAggregationCircuit; -use crate::threshold::pk_aggregation::circuit::PkAggregationCircuitInput; +use crate::threshold::pk_aggregation::circuit::PkAggregationCircuitData; use crate::CircuitsErrors; use crate::{CircuitComputation, Computation}; use e3_fhe_params::build_pair_for_preset; @@ -36,14 +36,14 @@ pub struct PkAggregationComputationOutput { /// Implementation of [`CircuitComputation`] for [`PkAggregationCircuit`]. impl CircuitComputation for PkAggregationCircuit { type Preset = BfvPreset; - type Input = PkAggregationCircuitInput; + type Data = PkAggregationCircuitData; type Output = PkAggregationComputationOutput; type Error = CircuitsErrors; - fn compute(preset: Self::Preset, input: &Self::Input) -> Result { + fn compute(preset: Self::Preset, data: &Self::Data) -> Result { let bounds = Bounds::compute(preset, &())?; let bits = Bits::compute(preset, &())?; - let inputs = Inputs::compute(preset, &input)?; + let inputs = Inputs::compute(preset, &data)?; Ok(PkAggregationComputationOutput { bounds, @@ -83,10 +83,10 @@ pub struct Inputs { impl Computation for Configs { type Preset = BfvPreset; - type Input = (); + type Data = (); type Error = CircuitsErrors; - fn compute(preset: Self::Preset, _: &Self::Input) -> Result { + fn compute(preset: Self::Preset, _: &Self::Data) -> Result { let (threshold_params, _) = build_pair_for_preset(preset).map_err(|e| CircuitsErrors::Other(e.to_string()))?; @@ -107,10 +107,10 @@ impl Computation for Configs { impl Computation for Bits { type Preset = BfvPreset; - type Input = (); + type Data = (); type Error = CircuitsErrors; - fn compute(preset: Self::Preset, _: &Self::Input) -> Result { + fn compute(preset: Self::Preset, _: &Self::Data) -> Result { let (threshold_params, _) = build_pair_for_preset(preset).map_err(|e| CircuitsErrors::Other(e.to_string()))?; @@ -122,10 +122,10 @@ impl Computation for Bits { impl Computation for Bounds { type Preset = BfvPreset; - type Input = (); + type Data = (); type Error = CircuitsErrors; - fn compute(preset: Self::Preset, _: &Self::Input) -> Result { + fn compute(preset: Self::Preset, _: &Self::Data) -> Result { let (threshold_params, _) = build_pair_for_preset(preset).map_err(|e| CircuitsErrors::Other(e.to_string()))?; @@ -149,10 +149,10 @@ impl Computation for Bounds { impl Computation for Inputs { type Preset = BfvPreset; - type Input = PkAggregationCircuitInput; + type Data = PkAggregationCircuitData; type Error = CircuitsErrors; - fn compute(preset: Self::Preset, input: &Self::Input) -> Result { + fn compute(preset: Self::Preset, data: &Self::Data) -> Result { let (threshold_params, _) = build_pair_for_preset(preset).map_err(|e| CircuitsErrors::Other(e.to_string()))?; @@ -165,12 +165,12 @@ impl Computation for Inputs { // key is also in [0, q_i). Centered representatives would make the sum before reduction // inconsistent and could break the aggregation check. - let mut pk0: Vec = input.pk0_shares.clone(); + let mut pk0: Vec = data.pk0_shares.clone(); // pk1 is the same (common random polynomial a) for all parties - let mut pk1: Vec = (0..input.committee.h).map(|_| input.a.clone()).collect(); + let mut pk1: Vec = (0..data.committee.h).map(|_| data.a.clone()).collect(); // Extract pk0_agg from aggregated public key - let mut pk0_agg = CrtPolynomial::from_fhe_polynomial(&input.public_key.c.c[0]); - let mut pk1_agg = input.a.clone(); + let mut pk0_agg = CrtPolynomial::from_fhe_polynomial(&data.public_key.c.c[0]); + let mut pk1_agg = data.a.clone(); // Compute expected_threshold_pk_commitments for each honest party // Each commitment is computed from pk0[i] and pk1[i] for party i @@ -181,11 +181,11 @@ impl Computation for Inputs { pk0_agg.reduce_uniform(zkp_modulus); pk1_agg.reverse(); - pk1_agg.scalar_mul(&BigInt::from(input.committee.h)); + pk1_agg.scalar_mul(&BigInt::from(data.committee.h)); pk1_agg.reduce(moduli)?; pk1_agg.reduce_uniform(zkp_modulus); - for party_index in 0..input.committee.h { + for party_index in 0..data.committee.h { pk0[party_index].reverse(); pk0[party_index].reduce(moduli)?; pk0[party_index].reduce_uniform(zkp_modulus); diff --git a/crates/zk-helpers/src/circuits/threshold/pk_aggregation/sample.rs b/crates/zk-helpers/src/circuits/threshold/pk_aggregation/sample.rs index d0c28d86d9..23cb6bf335 100644 --- a/crates/zk-helpers/src/circuits/threshold/pk_aggregation/sample.rs +++ b/crates/zk-helpers/src/circuits/threshold/pk_aggregation/sample.rs @@ -10,7 +10,7 @@ //! the public key shares and aggregated public key are used as input for codegen and tests. use crate::{ - threshold::pk_aggregation::PkAggregationCircuitInput, CiphernodesCommittee, CircuitsErrors, + threshold::pk_aggregation::PkAggregationCircuitData, CiphernodesCommittee, CircuitsErrors, }; use e3_fhe_params::{build_pair_for_preset, BfvPreset}; use e3_polynomial::CrtPolynomial; @@ -22,7 +22,7 @@ use fhe::{ use rand::rngs::OsRng; use rand::thread_rng; -impl PkAggregationCircuitInput { +impl PkAggregationCircuitData { pub fn generate_sample( preset: BfvPreset, committee: CiphernodesCommittee, @@ -61,7 +61,7 @@ impl PkAggregationCircuitInput { CircuitsErrors::Sample(format!("Failed to aggregate public key: {:?}", e)) })?; - Ok(PkAggregationCircuitInput { + Ok(PkAggregationCircuitData { committee, public_key, pk0_shares, @@ -75,7 +75,7 @@ mod tests { use crate::{ computation::Computation, threshold::pk_aggregation::computation::Configs, - threshold::pk_aggregation::{Inputs, PkAggregationCircuitInput}, + threshold::pk_aggregation::{Inputs, PkAggregationCircuitData}, CiphernodesCommitteeSize, }; @@ -87,7 +87,7 @@ mod tests { let committee = CiphernodesCommitteeSize::Small.values(); let configs = Configs::compute(preset, &()).unwrap(); - let sample = PkAggregationCircuitInput::generate_sample(preset, committee).unwrap(); + let sample = PkAggregationCircuitData::generate_sample(preset, committee).unwrap(); let inputs = Inputs::compute(preset, &sample).unwrap(); assert_eq!(inputs.pk0.len(), sample.committee.h); diff --git a/crates/zk-helpers/src/circuits/threshold/pk_generation/circuit.rs b/crates/zk-helpers/src/circuits/threshold/pk_generation/circuit.rs index 2b2477b889..4358d01a65 100644 --- a/crates/zk-helpers/src/circuits/threshold/pk_generation/circuit.rs +++ b/crates/zk-helpers/src/circuits/threshold/pk_generation/circuit.rs @@ -21,7 +21,7 @@ impl Circuit for PkGenerationCircuit { } #[derive(Debug, Clone)] -pub struct PkGenerationCircuitInput { +pub struct PkGenerationCircuitData { pub committee: CiphernodesCommittee, pub pk0_share: CrtPolynomial, pub a: CrtPolynomial, diff --git a/crates/zk-helpers/src/circuits/threshold/pk_generation/codegen.rs b/crates/zk-helpers/src/circuits/threshold/pk_generation/codegen.rs index e623c482ff..4ab79196ca 100644 --- a/crates/zk-helpers/src/circuits/threshold/pk_generation/codegen.rs +++ b/crates/zk-helpers/src/circuits/threshold/pk_generation/codegen.rs @@ -11,7 +11,7 @@ use e3_fhe_params::BfvPreset; use crate::circuits::computation::Computation; use crate::threshold::pk_generation::circuit::PkGenerationCircuit; use crate::threshold::pk_generation::computation::{Configs, Inputs}; -use crate::threshold::pk_generation::PkGenerationCircuitInput; +use crate::threshold::pk_generation::PkGenerationCircuitData; use crate::utils::join_display; use crate::CircuitCodegen; use crate::CircuitsErrors; @@ -21,12 +21,12 @@ use crate::{Circuit, CodegenConfigs}; /// Implementation of [`CircuitCodegen`] for [`PkGenerationCircuit`]. impl CircuitCodegen for PkGenerationCircuit { type Preset = BfvPreset; - type Input = PkGenerationCircuitInput; + type Data = PkGenerationCircuitData; type Error = CircuitsErrors; - fn codegen(&self, preset: Self::Preset, input: &Self::Input) -> Result { - let inputs = Inputs::compute(preset, input)?; - let configs = Configs::compute(preset, &input.committee)?; + fn codegen(&self, preset: Self::Preset, data: &Self::Data) -> Result { + let inputs = Inputs::compute(preset, data)?; + let configs = Configs::compute(preset, &data.committee)?; let toml = generate_toml(inputs)?; let configs = generate_configs(preset, &configs); @@ -125,7 +125,7 @@ mod tests { use crate::codegen::write_artifacts; use crate::threshold::pk_generation::computation::{Bits, Bounds}; - use crate::threshold::pk_generation::PkGenerationCircuitInput; + use crate::threshold::pk_generation::PkGenerationCircuitData; use crate::CiphernodesCommitteeSize; use e3_fhe_params::BfvPreset; @@ -135,7 +135,7 @@ mod tests { fn test_toml_generation_and_structure() { let committee = CiphernodesCommitteeSize::Small.values(); let sample = - PkGenerationCircuitInput::generate_sample(BfvPreset::InsecureThreshold512, committee) + PkGenerationCircuitData::generate_sample(BfvPreset::InsecureThreshold512, committee) .unwrap(); let artifacts = PkGenerationCircuit .codegen(BfvPreset::InsecureThreshold512, &sample) diff --git a/crates/zk-helpers/src/circuits/threshold/pk_generation/computation.rs b/crates/zk-helpers/src/circuits/threshold/pk_generation/computation.rs index 3fcc7f7d03..2d5bef1b17 100644 --- a/crates/zk-helpers/src/circuits/threshold/pk_generation/computation.rs +++ b/crates/zk-helpers/src/circuits/threshold/pk_generation/computation.rs @@ -15,7 +15,7 @@ use crate::get_zkp_modulus; use crate::math::{cyclotomic_polynomial, decompose_residue}; use crate::polynomial_to_toml_json; use crate::threshold::pk_generation::circuit::PkGenerationCircuit; -use crate::threshold::pk_generation::circuit::PkGenerationCircuitInput; +use crate::threshold::pk_generation::circuit::PkGenerationCircuitData; use crate::CiphernodesCommittee; use crate::CircuitsErrors; use crate::{CircuitComputation, Computation}; @@ -45,14 +45,14 @@ pub struct PkGenerationComputationOutput { /// Implementation of [`CircuitComputation`] for [`PkGenerationCircuit`]. impl CircuitComputation for PkGenerationCircuit { type Preset = BfvPreset; - type Input = PkGenerationCircuitInput; + type Data = PkGenerationCircuitData; type Output = PkGenerationComputationOutput; type Error = CircuitsErrors; - fn compute(preset: Self::Preset, input: &Self::Input) -> Result { - let bounds = Bounds::compute(preset, &input.committee)?; + fn compute(preset: Self::Preset, data: &Self::Data) -> Result { + let bounds = Bounds::compute(preset, &data.committee)?; let bits = Bits::compute(preset, &bounds)?; - let inputs = Inputs::compute(preset, input)?; + let inputs = Inputs::compute(preset, data)?; Ok(PkGenerationComputationOutput { bounds, @@ -105,16 +105,16 @@ pub struct Inputs { impl Computation for Configs { type Preset = BfvPreset; - type Input = CiphernodesCommittee; + type Data = CiphernodesCommittee; type Error = CircuitsErrors; - fn compute(preset: Self::Preset, input: &Self::Input) -> Result { + fn compute(preset: Self::Preset, data: &Self::Data) -> Result { let (threshold_params, _) = build_pair_for_preset(preset).map_err(|e| CircuitsErrors::Other(e.to_string()))?; let moduli = threshold_params.moduli().to_vec(); - let bounds = Bounds::compute(preset, input)?; + let bounds = Bounds::compute(preset, data)?; let bits = Bits::compute(preset, &bounds)?; Ok(Configs { @@ -129,25 +129,25 @@ impl Computation for Configs { impl Computation for Bits { type Preset = BfvPreset; - type Input = Bounds; + type Data = Bounds; type Error = CircuitsErrors; - fn compute(_: Self::Preset, input: &Self::Input) -> Result { + fn compute(_: Self::Preset, data: &Self::Data) -> Result { // Calculate bit widths for each bound type - let eek_bit = calculate_bit_width(BigInt::from(input.eek_bound.clone())); - let sk_bit = calculate_bit_width(BigInt::from(input.sk_bound.clone())); - let e_sm_bit = calculate_bit_width(BigInt::from(input.e_sm_bound.clone())); - let pk_bit = calculate_bit_width(BigInt::from(input.pk_bound.clone())); + let eek_bit = calculate_bit_width(BigInt::from(data.eek_bound.clone())); + let sk_bit = calculate_bit_width(BigInt::from(data.sk_bound.clone())); + let e_sm_bit = calculate_bit_width(BigInt::from(data.e_sm_bound.clone())); + let pk_bit = calculate_bit_width(BigInt::from(data.pk_bound.clone())); // For r1, use the maximum of all low and up bounds let mut r1_bit = 0; - for bound in &input.r1_bounds { + for bound in &data.r1_bounds { r1_bit = r1_bit.max(calculate_bit_width(BigInt::from(bound.clone()))); } // For r2, use the maximum of all bounds let mut r2_bit = 0; - for bound in &input.r2_bounds { + for bound in &data.r2_bounds { r2_bit = r2_bit.max(calculate_bit_width(BigInt::from(bound.clone()))); } @@ -164,10 +164,10 @@ impl Computation for Bits { impl Computation for Bounds { type Preset = BfvPreset; - type Input = CiphernodesCommittee; + type Data = CiphernodesCommittee; type Error = CircuitsErrors; - fn compute(preset: Self::Preset, input: &Self::Input) -> Result { + fn compute(preset: Self::Preset, data: &Self::Data) -> Result { let (threshold_params, _) = build_pair_for_preset(preset).map_err(|e| CircuitsErrors::Other(e.to_string()))?; @@ -186,7 +186,7 @@ impl Computation for Bounds { let smudging_config = SmudgingBoundCalculatorConfig::new( threshold_params.clone(), - input.n, + data.n, num_ciphertexts as usize, preset.metadata().lambda, ); @@ -241,10 +241,10 @@ impl Computation for Bounds { impl Computation for Inputs { type Preset = BfvPreset; - type Input = PkGenerationCircuitInput; + type Data = PkGenerationCircuitData; type Error = CircuitsErrors; - fn compute(preset: Self::Preset, input: &Self::Input) -> Result { + fn compute(preset: Self::Preset, data: &Self::Data) -> Result { let (threshold_params, _) = build_pair_for_preset(preset).map_err(|e| CircuitsErrors::Other(e.to_string()))?; @@ -267,11 +267,11 @@ impl Computation for Inputs { Polynomial, )> = izip!( moduli.clone(), - input.pk0_share.limbs.clone(), - input.a.limbs.clone(), - input.eek.limbs.clone(), - input.e_sm.limbs.clone(), - input.sk.limbs.clone(), + data.pk0_share.limbs.clone(), + data.a.limbs.clone(), + data.eek.limbs.clone(), + data.e_sm.limbs.clone(), + data.sk.limbs.clone(), ) .enumerate() .par_bridge() @@ -320,8 +320,8 @@ impl Computation for Inputs { let mut a = CrtPolynomial::new(vec![]); let mut e_sm = CrtPolynomial::new(vec![]); - let mut sk = input.sk.limbs[0].clone(); - let mut eek = input.eek.limbs[0].clone(); + let mut sk = data.sk.limbs[0].clone(); + let mut eek = data.eek.limbs[0].clone(); sk.reverse(); sk.center(&moduli[0]); diff --git a/crates/zk-helpers/src/circuits/threshold/pk_generation/sample.rs b/crates/zk-helpers/src/circuits/threshold/pk_generation/sample.rs index 6950a65367..bc4450d29d 100644 --- a/crates/zk-helpers/src/circuits/threshold/pk_generation/sample.rs +++ b/crates/zk-helpers/src/circuits/threshold/pk_generation/sample.rs @@ -10,7 +10,7 @@ //! for codegen and tests. use crate::{ - threshold::pk_generation::PkGenerationCircuitInput, CiphernodesCommittee, CircuitsErrors, + threshold::pk_generation::PkGenerationCircuitData, CiphernodesCommittee, CircuitsErrors, }; use e3_fhe_params::{build_pair_for_preset, BfvPreset}; use e3_polynomial::CrtPolynomial; @@ -23,7 +23,7 @@ use fhe::{ use rand::thread_rng; use std::ops::Deref; -impl PkGenerationCircuitInput { +impl PkGenerationCircuitData { pub fn generate_sample( preset: BfvPreset, committee: CiphernodesCommittee, @@ -68,7 +68,7 @@ impl PkGenerationCircuitInput { let e_sm = e_sm_rns_zeroizing.deref().clone(); - Ok(PkGenerationCircuitInput { + Ok(PkGenerationCircuitData { committee, pk0_share: CrtPolynomial::from_fhe_polynomial(&pk0_share), a: CrtPolynomial::from_fhe_polynomial(&a), @@ -83,7 +83,7 @@ impl PkGenerationCircuitInput { mod tests { use crate::{ computation::Computation, - threshold::pk_generation::{Inputs, PkGenerationCircuitInput}, + threshold::pk_generation::{Inputs, PkGenerationCircuitData}, CiphernodesCommitteeSize, }; @@ -93,7 +93,7 @@ mod tests { fn test_generate_sample() { let committee = CiphernodesCommitteeSize::Small.values(); let sample = - PkGenerationCircuitInput::generate_sample(BfvPreset::InsecureThreshold512, committee) + PkGenerationCircuitData::generate_sample(BfvPreset::InsecureThreshold512, committee) .unwrap(); let inputs = Inputs::compute(BfvPreset::InsecureThreshold512, &sample).unwrap(); diff --git a/crates/zk-helpers/src/circuits/threshold/share_decryption/circuit.rs b/crates/zk-helpers/src/circuits/threshold/share_decryption/circuit.rs index b07c9fc12d..54a7429569 100644 --- a/crates/zk-helpers/src/circuits/threshold/share_decryption/circuit.rs +++ b/crates/zk-helpers/src/circuits/threshold/share_decryption/circuit.rs @@ -21,7 +21,7 @@ pub struct ShareDecryptionCircuit; /// Input to the share decryption circuit: ciphertext, public key, and the party's /// aggregated secret share (s), smudging error (e), and computed decryption share (d_share). -pub struct ShareDecryptionCircuitInput { +pub struct ShareDecryptionCircuitData { pub ciphertext: Ciphertext, pub public_key: PublicKey, pub s: CrtPolynomial, diff --git a/crates/zk-helpers/src/circuits/threshold/share_decryption/codegen.rs b/crates/zk-helpers/src/circuits/threshold/share_decryption/codegen.rs index 35d0b399e9..c51aa16b11 100644 --- a/crates/zk-helpers/src/circuits/threshold/share_decryption/codegen.rs +++ b/crates/zk-helpers/src/circuits/threshold/share_decryption/codegen.rs @@ -9,7 +9,7 @@ use crate::circuits::computation::Computation; use crate::threshold::share_decryption::computation::Inputs; use crate::threshold::share_decryption::{ - Configs, ShareDecryptionCircuit, ShareDecryptionCircuitInput, + Configs, ShareDecryptionCircuit, ShareDecryptionCircuitData, }; use crate::utils::join_display; use crate::Circuit; @@ -22,11 +22,11 @@ use e3_fhe_params::BfvPreset; /// Implementation of [`CircuitCodegen`] for [`ShareDecryptionCircuit`]. impl CircuitCodegen for ShareDecryptionCircuit { type Preset = BfvPreset; - type Input = ShareDecryptionCircuitInput; + type Data = ShareDecryptionCircuitData; type Error = CircuitsErrors; - fn codegen(&self, preset: Self::Preset, input: &Self::Input) -> Result { - let inputs = Inputs::compute(preset, input)?; + fn codegen(&self, preset: Self::Preset, data: &Self::Data) -> Result { + let inputs = Inputs::compute(preset, data)?; let configs = Configs::compute(preset, &())?; let toml = generate_toml(inputs)?; @@ -110,7 +110,7 @@ mod tests { use crate::circuits::computation::Computation; use crate::codegen::write_artifacts; use crate::threshold::share_decryption::computation::{Bits, Bounds}; - use crate::threshold::share_decryption::ShareDecryptionCircuitInput; + use crate::threshold::share_decryption::ShareDecryptionCircuitData; use crate::CiphernodesCommitteeSize; use e3_fhe_params::BfvPreset; @@ -120,11 +120,9 @@ mod tests { fn test_toml_generation_and_structure() { let committee = CiphernodesCommitteeSize::Small.values(); - let sample = ShareDecryptionCircuitInput::generate_sample( - BfvPreset::InsecureThreshold512, - committee, - ) - .unwrap(); + let sample = + ShareDecryptionCircuitData::generate_sample(BfvPreset::InsecureThreshold512, committee) + .unwrap(); let artifacts = ShareDecryptionCircuit .codegen(BfvPreset::InsecureThreshold512, &sample) .unwrap(); diff --git a/crates/zk-helpers/src/circuits/threshold/share_decryption/computation.rs b/crates/zk-helpers/src/circuits/threshold/share_decryption/computation.rs index 412278306d..995b67aa05 100644 --- a/crates/zk-helpers/src/circuits/threshold/share_decryption/computation.rs +++ b/crates/zk-helpers/src/circuits/threshold/share_decryption/computation.rs @@ -17,7 +17,7 @@ use crate::crt_polynomial_to_toml_json; use crate::decompose_residue; use crate::get_zkp_modulus; use crate::threshold::share_decryption::circuit::ShareDecryptionCircuit; -use crate::threshold::share_decryption::circuit::ShareDecryptionCircuitInput; +use crate::threshold::share_decryption::circuit::ShareDecryptionCircuitData; use crate::CircuitsErrors; use crate::{CircuitComputation, Computation}; use e3_fhe_params::build_pair_for_preset; @@ -43,14 +43,14 @@ pub struct ShareDecryptionComputationOutput { /// Implementation of [`CircuitComputation`] for [`ShareDecryptionCircuit`]. impl CircuitComputation for ShareDecryptionCircuit { type Preset = BfvPreset; - type Input = ShareDecryptionCircuitInput; + type Data = ShareDecryptionCircuitData; type Output = ShareDecryptionComputationOutput; type Error = CircuitsErrors; - fn compute(preset: Self::Preset, input: &Self::Input) -> Result { + fn compute(preset: Self::Preset, data: &Self::Data) -> Result { let bounds = Bounds::compute(preset, &())?; let bits = Bits::compute(preset, &bounds)?; - let inputs = Inputs::compute(preset, input)?; + let inputs = Inputs::compute(preset, data)?; Ok(ShareDecryptionComputationOutput { bounds, @@ -100,10 +100,10 @@ pub struct Inputs { impl Computation for Configs { type Preset = BfvPreset; - type Input = (); + type Data = (); type Error = CircuitsErrors; - fn compute(preset: Self::Preset, _: &Self::Input) -> Result { + fn compute(preset: Self::Preset, _: &Self::Data) -> Result { let (threshold_params, _) = build_pair_for_preset(preset).map_err(|e| CircuitsErrors::Other(e.to_string()))?; @@ -124,19 +124,19 @@ impl Computation for Configs { impl Computation for Bits { type Preset = BfvPreset; - type Input = Bounds; + type Data = Bounds; type Error = CircuitsErrors; - fn compute(_: Self::Preset, input: &Self::Input) -> Result { + fn compute(_: Self::Preset, data: &Self::Data) -> Result { // For r1, use the maximum of all low and up bounds let mut r1_bit = 0; - for bound in input.r1_bounds.iter() { + for bound in data.r1_bounds.iter() { r1_bit = r1_bit.max(calculate_bit_width(BigInt::from(bound.clone()))); } // For r2, use the maximum of all bounds let mut r2_bit = 0; - for bound in &input.r2_bounds { + for bound in &data.r2_bounds { r2_bit = r2_bit.max(calculate_bit_width(BigInt::from(bound.clone()))); } @@ -153,10 +153,10 @@ impl Computation for Bits { impl Computation for Bounds { type Preset = BfvPreset; - type Input = (); + type Data = (); type Error = CircuitsErrors; - fn compute(preset: Self::Preset, _: &Self::Input) -> Result { + fn compute(preset: Self::Preset, _: &Self::Data) -> Result { let (threshold_params, _) = build_pair_for_preset(preset).map_err(|e| CircuitsErrors::Other(e.to_string()))?; @@ -204,10 +204,10 @@ impl Computation for Bounds { impl Computation for Inputs { type Preset = BfvPreset; - type Input = ShareDecryptionCircuitInput; + type Data = ShareDecryptionCircuitData; type Error = CircuitsErrors; - fn compute(preset: Self::Preset, input: &Self::Input) -> Result { + fn compute(preset: Self::Preset, data: &Self::Data) -> Result { let (threshold_params, _) = build_pair_for_preset(preset).map_err(|e| CircuitsErrors::Other(e.to_string()))?; @@ -220,8 +220,8 @@ impl Computation for Inputs { let n = threshold_params.degree() as u64; // Extract and convert ciphertext polynomials - let ct0 = CrtPolynomial::from_fhe_polynomial(&input.ciphertext.c[0]); - let ct1 = CrtPolynomial::from_fhe_polynomial(&input.ciphertext.c[1]); + let ct0 = CrtPolynomial::from_fhe_polynomial(&data.ciphertext.c[0]); + let ct1 = CrtPolynomial::from_fhe_polynomial(&data.ciphertext.c[1]); // Create cyclotomic polynomial x^N + 1 let mut cyclo = vec![BigInt::from(0u64); (n + 1) as usize]; @@ -242,9 +242,9 @@ impl Computation for Inputs { moduli.clone(), ct0.limbs.clone(), ct1.limbs.clone(), - input.s.limbs.clone(), - input.e.limbs.clone(), - input.d_share.limbs.clone(), + data.s.limbs.clone(), + data.e.limbs.clone(), + data.d_share.limbs.clone(), ) .enumerate() .par_bridge() diff --git a/crates/zk-helpers/src/circuits/threshold/share_decryption/sample.rs b/crates/zk-helpers/src/circuits/threshold/share_decryption/sample.rs index 81a13728fd..d30cd32bfb 100644 --- a/crates/zk-helpers/src/circuits/threshold/share_decryption/sample.rs +++ b/crates/zk-helpers/src/circuits/threshold/share_decryption/sample.rs @@ -12,7 +12,7 @@ use std::sync::Arc; use crate::{ - threshold::share_decryption::ShareDecryptionCircuitInput, CiphernodesCommittee, CircuitsErrors, + threshold::share_decryption::ShareDecryptionCircuitData, CiphernodesCommittee, CircuitsErrors, }; use e3_fhe_params::{build_pair_for_preset, BfvPreset}; use e3_polynomial::CrtPolynomial; @@ -25,7 +25,7 @@ use fhe_traits::{FheEncoder, FheEncrypter}; use ndarray::ArrayView; use rand::{rngs::OsRng, thread_rng}; -impl ShareDecryptionCircuitInput { +impl ShareDecryptionCircuitData { /// Generates a random secret key, public key, and plaintext for the given BFV parameters. pub fn generate_sample( preset: BfvPreset, @@ -255,7 +255,7 @@ mod tests { #[test] fn test_generate_template_succeeds_and_has_correct_structure() { let committee = CiphernodesCommitteeSize::Small.values(); - let sample = ShareDecryptionCircuitInput::generate_sample(PRESET, committee).unwrap(); + let sample = ShareDecryptionCircuitData::generate_sample(PRESET, committee).unwrap(); let degree = PRESET.metadata().degree; let num_moduli = PRESET.metadata().num_moduli; @@ -297,7 +297,7 @@ mod tests { #[test] fn test_generate_template_polynomials_consistent() { let committee = CiphernodesCommitteeSize::Small.values(); - let sample = ShareDecryptionCircuitInput::generate_sample(PRESET, committee).unwrap(); + let sample = ShareDecryptionCircuitData::generate_sample(PRESET, committee).unwrap(); let n = sample.s.limbs.len(); assert_eq!(sample.e.limbs.len(), n, "e must have same limb count as s"); @@ -312,8 +312,8 @@ mod tests { fn test_generate_template_repeatable() { let committee = CiphernodesCommitteeSize::Small.values(); - let a = ShareDecryptionCircuitInput::generate_sample(PRESET, committee.clone()).unwrap(); - let b = ShareDecryptionCircuitInput::generate_sample(PRESET, committee).unwrap(); + let a = ShareDecryptionCircuitData::generate_sample(PRESET, committee.clone()).unwrap(); + let b = ShareDecryptionCircuitData::generate_sample(PRESET, committee).unwrap(); assert_eq!(a.public_key.c.c.len(), b.public_key.c.c.len()); assert_eq!(a.s.limbs.len(), b.s.limbs.len()); diff --git a/crates/zk-helpers/src/circuits/threshold/user_data_encryption/circuit.rs b/crates/zk-helpers/src/circuits/threshold/user_data_encryption/circuit.rs index e4960a2e9d..2cb46bbe01 100644 --- a/crates/zk-helpers/src/circuits/threshold/user_data_encryption/circuit.rs +++ b/crates/zk-helpers/src/circuits/threshold/user_data_encryption/circuit.rs @@ -19,7 +19,7 @@ impl Circuit for UserDataEncryptionCircuit { const DKG_INPUT_TYPE: Option = None; } -pub struct UserDataEncryptionCircuitInput { +pub struct UserDataEncryptionCircuitData { pub public_key: PublicKey, pub plaintext: Plaintext, } diff --git a/crates/zk-helpers/src/circuits/threshold/user_data_encryption/codegen.rs b/crates/zk-helpers/src/circuits/threshold/user_data_encryption/codegen.rs index 4b60bc9352..dc8879490e 100644 --- a/crates/zk-helpers/src/circuits/threshold/user_data_encryption/codegen.rs +++ b/crates/zk-helpers/src/circuits/threshold/user_data_encryption/codegen.rs @@ -9,7 +9,7 @@ use crate::circuits::computation::Computation; use crate::threshold::user_data_encryption::circuit::UserDataEncryptionCircuit; use crate::threshold::user_data_encryption::computation::{Configs, Inputs}; -use crate::threshold::user_data_encryption::UserDataEncryptionCircuitInput; +use crate::threshold::user_data_encryption::UserDataEncryptionCircuitData; use crate::utils::join_display; use crate::Circuit; use crate::CircuitCodegen; @@ -23,11 +23,11 @@ use serde_json; /// Implementation of [`CircuitCodegen`] for [`UserDataEncryptionCircuit`]. impl CircuitCodegen for UserDataEncryptionCircuit { type Preset = BfvPreset; - type Input = UserDataEncryptionCircuitInput; + type Data = UserDataEncryptionCircuitData; type Error = CircuitsErrors; - fn codegen(&self, preset: Self::Preset, input: &Self::Input) -> Result { - let inputs = Inputs::compute(preset, input)?; + fn codegen(&self, preset: Self::Preset, data: &Self::Data) -> Result { + let inputs = Inputs::compute(preset, data)?; let configs = Configs::compute(preset, &())?; let toml = generate_toml(inputs)?; @@ -201,7 +201,7 @@ mod tests { use super::*; use crate::circuits::computation::Computation; use crate::codegen::write_artifacts; - use crate::threshold::user_data_encryption::circuit::UserDataEncryptionCircuitInput; + use crate::threshold::user_data_encryption::circuit::UserDataEncryptionCircuitData; use crate::threshold::user_data_encryption::computation::{Bits, Bounds}; use e3_fhe_params::BfvPreset; @@ -210,7 +210,7 @@ mod tests { #[test] fn test_toml_generation_and_structure() { let sample = - UserDataEncryptionCircuitInput::generate_sample(BfvPreset::InsecureThreshold512) + UserDataEncryptionCircuitData::generate_sample(BfvPreset::InsecureThreshold512) .unwrap(); let artifacts = UserDataEncryptionCircuit .codegen(BfvPreset::InsecureThreshold512, &sample) diff --git a/crates/zk-helpers/src/circuits/threshold/user_data_encryption/computation.rs b/crates/zk-helpers/src/circuits/threshold/user_data_encryption/computation.rs index 4efb9ea5b4..708975cc73 100644 --- a/crates/zk-helpers/src/circuits/threshold/user_data_encryption/computation.rs +++ b/crates/zk-helpers/src/circuits/threshold/user_data_encryption/computation.rs @@ -18,7 +18,7 @@ use crate::math::{compute_k0is, compute_q_mod_t, compute_q_product}; use crate::math::{cyclotomic_polynomial, decompose_residue}; use crate::polynomial_to_toml_json; use crate::threshold::user_data_encryption::circuit::UserDataEncryptionCircuit; -use crate::threshold::user_data_encryption::circuit::UserDataEncryptionCircuitInput; +use crate::threshold::user_data_encryption::circuit::UserDataEncryptionCircuitData; use crate::utils::compute_modulus_bit; use crate::CircuitsErrors; use crate::{CircuitComputation, Computation}; @@ -56,14 +56,14 @@ pub struct UserDataEncryptionComputationOutput { /// Implementation of [`CircuitComputation`] for [`UserDataEncryptionCircuit`]. impl CircuitComputation for UserDataEncryptionCircuit { type Preset = BfvPreset; - type Input = UserDataEncryptionCircuitInput; + type Data = UserDataEncryptionCircuitData; type Output = UserDataEncryptionComputationOutput; type Error = CircuitsErrors; - fn compute(preset: Self::Preset, input: &Self::Input) -> Result { + fn compute(preset: Self::Preset, data: &Self::Data) -> Result { let bounds = Bounds::compute(preset, &())?; let bits = Bits::compute(preset, &bounds)?; - let inputs = Inputs::compute(preset, input)?; + let inputs = Inputs::compute(preset, data)?; Ok(UserDataEncryptionComputationOutput { bounds, @@ -136,10 +136,10 @@ pub struct Inputs { impl Computation for Configs { type Preset = BfvPreset; - type Input = (); + type Data = (); type Error = CircuitsErrors; - fn compute(preset: Self::Preset, _: &Self::Input) -> Result { + fn compute(preset: Self::Preset, _: &Self::Data) -> Result { let (threshold_params, _) = build_pair_for_preset(preset).map_err(|e| CircuitsErrors::Sample(e.to_string()))?; @@ -172,45 +172,45 @@ impl Computation for Configs { impl Computation for Bits { type Preset = BfvPreset; - type Input = Bounds; + type Data = Bounds; type Error = CircuitsErrors; - fn compute(_: Self::Preset, input: &Self::Input) -> Result { - let max_pk_bound = input.pk_bounds.iter().max().unwrap(); + fn compute(_: Self::Preset, data: &Self::Data) -> Result { + let max_pk_bound = data.pk_bounds.iter().max().unwrap(); let pk_bit = calculate_bit_width(BigInt::from(max_pk_bound.clone())); // We can safely assume that the ct bound is the same as the pk bound. let ct_bit = calculate_bit_width(BigInt::from(max_pk_bound.clone())); - let u_bit = calculate_bit_width(BigInt::from(input.u_bound.clone())); - let e0_bit = calculate_bit_width(BigInt::from(input.e0_bound.clone())); - let e1_bit = calculate_bit_width(BigInt::from(input.e1_bound.clone())); + let u_bit = calculate_bit_width(BigInt::from(data.u_bound.clone())); + let e0_bit = calculate_bit_width(BigInt::from(data.e0_bound.clone())); + let e1_bit = calculate_bit_width(BigInt::from(data.e1_bound.clone())); // For k1, use the maximum of low and up bounds - let k1_low_bit = calculate_bit_width(BigInt::from(input.k1_low_bound.clone())); - let k1_up_bit = calculate_bit_width(BigInt::from(input.k1_up_bound.clone())); + let k1_low_bit = calculate_bit_width(BigInt::from(data.k1_low_bound.clone())); + let k1_up_bit = calculate_bit_width(BigInt::from(data.k1_up_bound.clone())); let k_bit = k1_low_bit.max(k1_up_bit); // For r1, use the maximum of all low and up bounds let mut r1_bit = 0; - for bound in input.r1_low_bounds.iter().chain(input.r1_up_bounds.iter()) { + for bound in data.r1_low_bounds.iter().chain(data.r1_up_bounds.iter()) { r1_bit = r1_bit.max(calculate_bit_width(BigInt::from(bound.clone()))); } // For r2, use the maximum of all bounds let mut r2_bit = 0; - for bound in &input.r2_bounds { + for bound in &data.r2_bounds { r2_bit = r2_bit.max(calculate_bit_width(BigInt::from(bound.clone()))); } // For p1, use the maximum of all bounds let mut p1_bit = 0; - for bound in &input.p1_bounds { + for bound in &data.p1_bounds { p1_bit = p1_bit.max(calculate_bit_width(BigInt::from(bound.clone()))); } // For p2, use the maximum of all bounds let mut p2_bit = 0; - for bound in &input.p2_bounds { + for bound in &data.p2_bounds { p2_bit = p2_bit.max(calculate_bit_width(BigInt::from(bound.clone()))); } @@ -231,10 +231,10 @@ impl Computation for Bits { impl Computation for Bounds { type Preset = BfvPreset; - type Input = (); + type Data = (); type Error = CircuitsErrors; - fn compute(preset: Self::Preset, _: &Self::Input) -> Result { + fn compute(preset: Self::Preset, _: &Self::Data) -> Result { let (threshold_params, _) = build_pair_for_preset(preset).map_err(|e| CircuitsErrors::Sample(e.to_string()))?; @@ -354,22 +354,22 @@ impl Computation for Bounds { impl Computation for Inputs { type Preset = BfvPreset; - type Input = UserDataEncryptionCircuitInput; + type Data = UserDataEncryptionCircuitData; type Error = CircuitsErrors; - fn compute(preset: Self::Preset, input: &Self::Input) -> Result { + fn compute(preset: Self::Preset, data: &Self::Data) -> Result { let (threshold_params, _) = build_pair_for_preset(preset).map_err(|e| CircuitsErrors::Sample(e.to_string()))?; let pk_bit = compute_modulus_bit(&threshold_params); - let pk = input.public_key.clone(); - let pt = input.plaintext.clone(); + let pk = data.public_key.clone(); + let pt = data.plaintext.clone(); // Encrypt using the provided public key to ensure ciphertext matches the key. - let (ct, u_rns, e0_rns, e1_rns) = input + let (ct, u_rns, e0_rns, e1_rns) = data .public_key - .try_encrypt_extended(&input.plaintext, &mut thread_rng())?; + .try_encrypt_extended(&data.plaintext, &mut thread_rng())?; // Context and plaintext modulus (use same ctx for e0 reconstruction and loop). let ctx = threshold_params.ctx_at_level(pt.level())?; diff --git a/crates/zk-helpers/src/circuits/threshold/user_data_encryption/sample.rs b/crates/zk-helpers/src/circuits/threshold/user_data_encryption/sample.rs index 7d3eee2a4e..d4e79897c9 100644 --- a/crates/zk-helpers/src/circuits/threshold/user_data_encryption/sample.rs +++ b/crates/zk-helpers/src/circuits/threshold/user_data_encryption/sample.rs @@ -10,14 +10,14 @@ //! for codegen and tests. use crate::{ - threshold::user_data_encryption::circuit::UserDataEncryptionCircuitInput, CircuitsErrors, + threshold::user_data_encryption::circuit::UserDataEncryptionCircuitData, CircuitsErrors, }; use e3_fhe_params::{build_pair_for_preset, BfvPreset}; use fhe::bfv::{Encoding, Plaintext, PublicKey, SecretKey}; use fhe_traits::FheEncoder; use rand::thread_rng; -impl UserDataEncryptionCircuitInput { +impl UserDataEncryptionCircuitData { /// Generates a random secret key, public key, and plaintext for the given BFV parameters. pub fn generate_sample(preset: BfvPreset) -> Result { let (threshold_params, _) = build_pair_for_preset(preset).map_err(|e| { @@ -41,13 +41,13 @@ impl UserDataEncryptionCircuitInput { #[cfg(test)] mod tests { - use crate::threshold::user_data_encryption::circuit::UserDataEncryptionCircuitInput; + use crate::threshold::user_data_encryption::circuit::UserDataEncryptionCircuitData; use e3_fhe_params::BfvPreset; #[test] fn test_generate_sample() { let sample = - UserDataEncryptionCircuitInput::generate_sample(BfvPreset::InsecureThreshold512) + UserDataEncryptionCircuitData::generate_sample(BfvPreset::InsecureThreshold512) .unwrap(); assert_eq!(sample.public_key.c.c.len(), 2); diff --git a/crates/zk-helpers/src/circuits/threshold/user_data_encryption/utils.rs b/crates/zk-helpers/src/circuits/threshold/user_data_encryption/utils.rs index e668b932fc..ee5010d5b3 100644 --- a/crates/zk-helpers/src/circuits/threshold/user_data_encryption/utils.rs +++ b/crates/zk-helpers/src/circuits/threshold/user_data_encryption/utils.rs @@ -164,7 +164,7 @@ mod tests { use super::*; use crate::circuits::computation::Computation; use crate::threshold::user_data_encryption::computation::Inputs; - use crate::threshold::user_data_encryption::UserDataEncryptionCircuitInput; + use crate::threshold::user_data_encryption::UserDataEncryptionCircuitData; use e3_fhe_params::{build_pair_for_preset, BfvPreset}; use fhe_traits::DeserializeParametrized; @@ -172,7 +172,7 @@ mod tests { fn test_bfv_public_key_to_greco() { let (threshold_params, _) = build_pair_for_preset(BfvPreset::InsecureThreshold512).unwrap(); let sample = - UserDataEncryptionCircuitInput::generate_sample(BfvPreset::InsecureThreshold512) + UserDataEncryptionCircuitData::generate_sample(BfvPreset::InsecureThreshold512) .unwrap(); let inputs = Inputs::compute(BfvPreset::InsecureThreshold512, &sample).unwrap(); @@ -191,7 +191,7 @@ mod tests { let (threshold_params, _) = build_pair_for_preset(BfvPreset::InsecureThreshold512).unwrap(); let sample = - UserDataEncryptionCircuitInput::generate_sample(BfvPreset::InsecureThreshold512) + UserDataEncryptionCircuitData::generate_sample(BfvPreset::InsecureThreshold512) .unwrap(); let inputs = Inputs::compute(BfvPreset::InsecureThreshold512, &sample).unwrap(); diff --git a/crates/zk-prover/src/circuits/dkg/pk.rs b/crates/zk-prover/src/circuits/dkg/pk.rs index b120db2db8..1fe7d89bd3 100644 --- a/crates/zk-prover/src/circuits/dkg/pk.rs +++ b/crates/zk-prover/src/circuits/dkg/pk.rs @@ -7,12 +7,12 @@ use crate::traits::Provable; use e3_events::CircuitName; use e3_fhe_params::BfvPreset; -use e3_zk_helpers::circuits::dkg::pk::circuit::{PkCircuit, PkCircuitInput}; +use e3_zk_helpers::circuits::dkg::pk::circuit::{PkCircuit, PkCircuitData}; use e3_zk_helpers::circuits::dkg::pk::computation::Inputs; impl Provable for PkCircuit { type Params = BfvPreset; - type Input = PkCircuitInput; + type Input = PkCircuitData; type Inputs = Inputs; fn circuit(&self) -> CircuitName { diff --git a/crates/zk-prover/src/circuits/threshold/pk_generation.rs b/crates/zk-prover/src/circuits/threshold/pk_generation.rs index ea65c7e539..39148594a8 100644 --- a/crates/zk-prover/src/circuits/threshold/pk_generation.rs +++ b/crates/zk-prover/src/circuits/threshold/pk_generation.rs @@ -8,13 +8,13 @@ use crate::traits::Provable; use e3_events::CircuitName; use e3_fhe_params::BfvPreset; use e3_zk_helpers::circuits::threshold::pk_generation::circuit::{ - PkGenerationCircuit, PkGenerationCircuitInput, + PkGenerationCircuit, PkGenerationCircuitData, }; use e3_zk_helpers::circuits::threshold::pk_generation::computation::Inputs; impl Provable for PkGenerationCircuit { type Params = BfvPreset; - type Input = PkGenerationCircuitInput; + type Input = PkGenerationCircuitData; type Inputs = Inputs; fn circuit(&self) -> CircuitName { diff --git a/crates/zk-prover/src/traits.rs b/crates/zk-prover/src/traits.rs index 117ead32d8..ca95be8b0f 100644 --- a/crates/zk-prover/src/traits.rs +++ b/crates/zk-prover/src/traits.rs @@ -29,7 +29,7 @@ pub trait Provable: Send + Sync { fn build_inputs(&self, params: &Self::Params, input: &Self::Input) -> Result where - Self::Inputs: Computation + serde::Serialize, + Self::Inputs: Computation + serde::Serialize, ::Error: Display, { let inputs = Self::Inputs::compute(params.clone(), input) @@ -49,7 +49,7 @@ pub trait Provable: Send + Sync { e3_id: &str, ) -> Result where - Self::Inputs: Computation + serde::Serialize, + Self::Inputs: Computation + serde::Serialize, ::Error: Display, { let inputs = self.build_inputs(params, input)?; diff --git a/crates/zk-prover/tests/local_e2e_tests.rs b/crates/zk-prover/tests/local_e2e_tests.rs index 6a7aad5664..5f901642ba 100644 --- a/crates/zk-prover/tests/local_e2e_tests.rs +++ b/crates/zk-prover/tests/local_e2e_tests.rs @@ -15,9 +15,9 @@ mod common; use common::fixtures_dir; use e3_fhe_params::BfvPreset; use e3_zk_helpers::circuits::dkg::pk::circuit::PkCircuit; -use e3_zk_helpers::circuits::dkg::pk::circuit::PkCircuitInput; +use e3_zk_helpers::circuits::dkg::pk::circuit::PkCircuitData; use e3_zk_helpers::circuits::{commitments::compute_dkg_pk_commitment, CircuitComputation}; -use e3_zk_helpers::threshold::pk_generation::{PkGenerationCircuit, PkGenerationCircuitInput}; +use e3_zk_helpers::threshold::pk_generation::{PkGenerationCircuit, PkGenerationCircuitData}; use e3_zk_helpers::CiphernodesCommitteeSize; use e3_zk_helpers::{ compute_share_computation_e_sm_commitment, compute_share_computation_sk_commitment, @@ -108,7 +108,7 @@ async fn setup_pk_generation_test() -> Option<( tempfile::TempDir, ZkProver, PkGenerationCircuit, - PkGenerationCircuitInput, + PkGenerationCircuitData, BfvPreset, &'static str, )> { @@ -119,7 +119,7 @@ async fn setup_pk_generation_test() -> Option<( setup_circuit_fixtures(&backend, &["threshold", "pk_generation"], "pk_generation").await; - let sample = PkGenerationCircuitInput::generate_sample(preset, committee).ok()?; + let sample = PkGenerationCircuitData::generate_sample(preset, committee).ok()?; let prover = ZkProver::new(&backend); Some(( @@ -138,7 +138,7 @@ async fn setup_pk_bfv_test() -> Option<( tempfile::TempDir, ZkProver, PkCircuit, - PkCircuitInput, + PkCircuitData, BfvPreset, &'static str, )> { @@ -148,7 +148,7 @@ async fn setup_pk_bfv_test() -> Option<( setup_circuit_fixtures(&backend, &["dkg", "pk"], "pk").await; - let sample = PkCircuitInput::generate_sample(preset).ok()?; + let sample = PkCircuitData::generate_sample(preset).ok()?; let prover = ZkProver::new(&backend); Some((backend, temp, prover, PkCircuit, sample, preset, "0")) diff --git a/examples/CRISP/crates/zk-inputs/src/lib.rs b/examples/CRISP/crates/zk-inputs/src/lib.rs index d2424d4104..473860536d 100644 --- a/examples/CRISP/crates/zk-inputs/src/lib.rs +++ b/examples/CRISP/crates/zk-inputs/src/lib.rs @@ -15,7 +15,7 @@ use e3_fhe_params::BfvParamSet; use e3_fhe_params::DEFAULT_BFV_PRESET; use e3_polynomial::CrtPolynomial; use e3_zk_helpers::circuits::threshold::user_data_encryption::circuit::UserDataEncryptionCircuit; -use e3_zk_helpers::circuits::threshold::user_data_encryption::circuit::UserDataEncryptionCircuitInput; +use e3_zk_helpers::circuits::threshold::user_data_encryption::circuit::UserDataEncryptionCircuitData; use e3_zk_helpers::commitments::compute_ciphertext_commitment; use e3_zk_helpers::utils::compute_modulus_bit; use e3_zk_helpers::CircuitComputation; @@ -94,7 +94,7 @@ impl ZKInputsGenerator { let user_data_encryption_computation_output = UserDataEncryptionCircuit::compute( DEFAULT_BFV_PRESET, - &UserDataEncryptionCircuitInput { + &UserDataEncryptionCircuitData { public_key: pk, plaintext: pt, }, @@ -158,7 +158,7 @@ impl ZKInputsGenerator { let user_data_encryption_computation_output = UserDataEncryptionCircuit::compute( DEFAULT_BFV_PRESET, - &UserDataEncryptionCircuitInput { + &UserDataEncryptionCircuitData { public_key: pk, plaintext: pt, }, diff --git a/packages/enclave-contracts/contracts/interfaces/IEnclave.sol b/packages/enclave-contracts/contracts/interfaces/IEnclave.sol index 8a7ead42f9..67a0a81382 100644 --- a/packages/enclave-contracts/contracts/interfaces/IEnclave.sol +++ b/packages/enclave-contracts/contracts/interfaces/IEnclave.sol @@ -349,7 +349,10 @@ interface IEnclave { /// @dev Updates E3 lifecycle to KeyPublished stage. /// @param e3Id ID of the E3. /// @param committeePublicKeyHash Hash of the committee public key. - function onCommitteePublished(uint256 e3Id, bytes32 committeePublicKeyHash) external; + function onCommitteePublished( + uint256 e3Id, + bytes32 committeePublicKeyHash + ) external; /// @notice Called by authorized contracts to mark an E3 as failed with a specific reason. /// @dev Updates E3 lifecycle to Failed stage with the given reason. diff --git a/packages/enclave-contracts/tasks/ciphernode.ts b/packages/enclave-contracts/tasks/ciphernode.ts index f09a5a1bad..8007725b2c 100644 --- a/packages/enclave-contracts/tasks/ciphernode.ts +++ b/packages/enclave-contracts/tasks/ciphernode.ts @@ -33,14 +33,18 @@ export const ciphernodeAdd = task( const [signer] = await ethers.getSigners(); console.log(`Registering ciphernode: ${signer.address}`); - const { deployAndSaveBondingRegistry } = - await import("../scripts/deployAndSave/bondingRegistry"); - const { deployAndSaveEnclaveTicketToken } = - await import("../scripts/deployAndSave/enclaveTicketToken"); - const { deployAndSaveEnclaveToken } = - await import("../scripts/deployAndSave/enclaveToken"); - const { deployAndSaveMockStableToken } = - await import("../scripts/deployAndSave/mockStableToken"); + const { deployAndSaveBondingRegistry } = await import( + "../scripts/deployAndSave/bondingRegistry" + ); + const { deployAndSaveEnclaveTicketToken } = await import( + "../scripts/deployAndSave/enclaveTicketToken" + ); + const { deployAndSaveEnclaveToken } = await import( + "../scripts/deployAndSave/enclaveToken" + ); + const { deployAndSaveMockStableToken } = await import( + "../scripts/deployAndSave/mockStableToken" + ); const { bondingRegistry } = await deployAndSaveBondingRegistry({ hre }); const { enclaveToken } = await deployAndSaveEnclaveToken({ hre }); const { enclaveTicketToken } = await deployAndSaveEnclaveTicketToken({ @@ -162,8 +166,9 @@ export const ciphernodeRemove = task( const [signer] = await ethers.getSigners(); console.log(`Deregistering ciphernode: ${signer.address}`); - const { deployAndSaveBondingRegistry } = - await import("../scripts/deployAndSave/bondingRegistry"); + const { deployAndSaveBondingRegistry } = await import( + "../scripts/deployAndSave/bondingRegistry" + ); const { bondingRegistry } = await deployAndSaveBondingRegistry({ hre }); const bondingRegistryConnected = bondingRegistry.connect(signer); @@ -222,12 +227,14 @@ export const ciphernodeMintTokens = task( ); } - const { deployAndSaveEnclaveToken } = - await import("../scripts/deployAndSave/enclaveToken"); + const { deployAndSaveEnclaveToken } = await import( + "../scripts/deployAndSave/enclaveToken" + ); const { enclaveToken } = await deployAndSaveEnclaveToken({ hre }); - const { deployAndSaveMockStableToken } = - await import("../scripts/deployAndSave/mockStableToken"); + const { deployAndSaveMockStableToken } = await import( + "../scripts/deployAndSave/mockStableToken" + ); const { mockStableToken } = await deployAndSaveMockStableToken({ hre, }); @@ -334,16 +341,19 @@ export const ciphernodeAdminAdd = task( console.log(`Admin wallet: ${adminWallet.address}`); console.log(`Registering ciphernode: ${ciphernodeAddress}`); - const { deployAndSaveBondingRegistry } = - await import("../scripts/deployAndSave/bondingRegistry"); + const { deployAndSaveBondingRegistry } = await import( + "../scripts/deployAndSave/bondingRegistry" + ); const { bondingRegistry } = await deployAndSaveBondingRegistry({ hre }); - const { deployAndSaveEnclaveToken } = - await import("../scripts/deployAndSave/enclaveToken"); + const { deployAndSaveEnclaveToken } = await import( + "../scripts/deployAndSave/enclaveToken" + ); const { enclaveToken } = await deployAndSaveEnclaveToken({ hre }); - const { deployAndSaveMockStableToken } = - await import("../scripts/deployAndSave/mockStableToken"); + const { deployAndSaveMockStableToken } = await import( + "../scripts/deployAndSave/mockStableToken" + ); const { mockStableToken: mockUSDC } = await deployAndSaveMockStableToken({ hre, }); @@ -536,11 +546,13 @@ export const updateSubmissionWindow = task( }) .setAction(async () => ({ default: async ({ newWindow }, hre) => { - const { deployAndSaveCiphernodeRegistryOwnable } = - await import("../scripts/deployAndSave/ciphernodeRegistryOwnable"); + const { deployAndSaveCiphernodeRegistryOwnable } = await import( + "../scripts/deployAndSave/ciphernodeRegistryOwnable" + ); - const { deployAndSavePoseidonT3 } = - await import("../scripts/deployAndSave/poseidonT3"); + const { deployAndSavePoseidonT3 } = await import( + "../scripts/deployAndSave/poseidonT3" + ); const poseidonT3 = await deployAndSavePoseidonT3({ hre }); const { ciphernodeRegistry } = diff --git a/packages/enclave-contracts/tasks/enclave.ts b/packages/enclave-contracts/tasks/enclave.ts index 1de9724a1d..7be1108a2c 100644 --- a/packages/enclave-contracts/tasks/enclave.ts +++ b/packages/enclave-contracts/tasks/enclave.ts @@ -85,10 +85,12 @@ export const requestCommittee = task( const connection = await hre.network.connect(); const { ethers } = connection; - const { deployAndSaveEnclave } = - await import("../scripts/deployAndSave/enclave"); - const { deployAndSaveMockStableToken } = - await import("../scripts/deployAndSave/mockStableToken"); + const { deployAndSaveEnclave } = await import( + "../scripts/deployAndSave/enclave" + ); + const { deployAndSaveMockStableToken } = await import( + "../scripts/deployAndSave/mockStableToken" + ); const { enclave } = await deployAndSaveEnclave({ hre, @@ -208,8 +210,9 @@ export const enableE3 = task("enclave:enableE3", "Enable an E3 program") }) .setAction(async () => ({ default: async ({ e3Address }, hre) => { - const { deployAndSaveEnclave } = - await import("../scripts/deployAndSave/enclave"); + const { deployAndSaveEnclave } = await import( + "../scripts/deployAndSave/enclave" + ); const { enclave } = await deployAndSaveEnclave({ hre, @@ -255,11 +258,13 @@ export const publishCommittee = task( }) .setAction(async () => ({ default: async ({ e3Id, nodes, publicKey, publicKeyHash }, hre) => { - const { deployAndSaveCiphernodeRegistryOwnable } = - await import("../scripts/deployAndSave/ciphernodeRegistryOwnable"); + const { deployAndSaveCiphernodeRegistryOwnable } = await import( + "../scripts/deployAndSave/ciphernodeRegistryOwnable" + ); - const { deployAndSavePoseidonT3 } = - await import("../scripts/deployAndSave/poseidonT3"); + const { deployAndSavePoseidonT3 } = await import( + "../scripts/deployAndSave/poseidonT3" + ); const poseidonT3 = await deployAndSavePoseidonT3({ hre }); const { ciphernodeRegistry } = @@ -331,8 +336,9 @@ export const publishCiphertext = task( }) .setAction(async () => ({ default: async ({ e3Id, data, dataFile, proof, proofFile }, hre) => { - const { deployAndSaveEnclave } = - await import("../scripts/deployAndSave/enclave"); + const { deployAndSaveEnclave } = await import( + "../scripts/deployAndSave/enclave" + ); const { enclave } = await deployAndSaveEnclave({ hre, @@ -402,8 +408,9 @@ export const publishPlaintext = task( }) .setAction(async () => ({ default: async ({ e3Id, data, dataFile, proof, proofFile }, hre) => { - const { deployAndSaveEnclave } = - await import("../scripts/deployAndSave/enclave"); + const { deployAndSaveEnclave } = await import( + "../scripts/deployAndSave/enclave" + ); const { enclave } = await deployAndSaveEnclave({ hre, diff --git a/packages/enclave-contracts/tasks/program.ts b/packages/enclave-contracts/tasks/program.ts index e9aeffa234..b9104227ce 100644 --- a/packages/enclave-contracts/tasks/program.ts +++ b/packages/enclave-contracts/tasks/program.ts @@ -38,8 +38,9 @@ export const publishInput = task( }) .setAction(async () => ({ default: async ({ e3Id, data, dataFile, programAddress }, hre) => { - const { deployAndSaveMockProgram } = - await import("../scripts/deployAndSave/mockProgram"); + const { deployAndSaveMockProgram } = await import( + "../scripts/deployAndSave/mockProgram" + ); const { MockE3Program__factory } = await import("../types"); const { ethers } = await hre.network.connect();