From dabb8bc8da89a7d044e27eba0b33102e94c1fcdd Mon Sep 17 00:00:00 2001 From: Cedoor Date: Wed, 11 Feb 2026 16:47:06 +0100 Subject: [PATCH 1/2] refactor: rename witness to inputs --- crates/bfv-client/src/client.rs | 8 ++-- crates/zk-helpers/README.md | 25 ++++++------ crates/zk-helpers/src/bin/zk_cli.rs | 32 ++++++++-------- crates/zk-helpers/src/circuits/codegen.rs | 4 +- crates/zk-helpers/src/circuits/computation.rs | 6 +-- .../zk-helpers/src/circuits/dkg/pk/codegen.rs | 12 +++--- .../src/circuits/dkg/pk/computation.rs | 24 ++++++------ crates/zk-helpers/src/circuits/dkg/pk/mod.rs | 2 +- .../circuits/dkg/share_computation/circuit.rs | 2 +- .../circuits/dkg/share_computation/codegen.rs | 18 ++++----- .../dkg/share_computation/computation.rs | 36 +++++++++--------- .../src/circuits/dkg/share_computation/mod.rs | 2 +- .../circuits/dkg/share_decryption/circuit.rs | 2 +- .../circuits/dkg/share_decryption/codegen.rs | 12 +++--- .../dkg/share_decryption/computation.rs | 38 +++++++++---------- .../src/circuits/dkg/share_decryption/mod.rs | 2 +- .../circuits/dkg/share_encryption/circuit.rs | 2 +- .../circuits/dkg/share_encryption/codegen.rs | 12 +++--- .../dkg/share_encryption/computation.rs | 34 ++++++++--------- .../src/circuits/dkg/share_encryption/mod.rs | 2 +- .../decrypted_shares_aggregation/circuit.rs | 4 +- .../decrypted_shares_aggregation/codegen.rs | 12 +++--- .../computation.rs | 38 +++++++++---------- .../decrypted_shares_aggregation/mod.rs | 2 +- .../decrypted_shares_aggregation/sample.rs | 24 ++++++------ .../decrypted_shares_aggregation/utils.rs | 2 +- .../threshold/pk_aggregation/codegen.rs | 16 ++++---- .../threshold/pk_aggregation/computation.rs | 20 +++++----- .../threshold/pk_aggregation/sample.rs | 12 +++--- .../threshold/pk_generation/codegen.rs | 10 ++--- .../threshold/pk_generation/computation.rs | 20 +++++----- .../threshold/pk_generation/sample.rs | 14 +++---- .../threshold/share_decryption/codegen.rs | 10 ++--- .../threshold/share_decryption/computation.rs | 20 +++++----- .../threshold/user_data_encryption/codegen.rs | 10 ++--- .../user_data_encryption/computation.rs | 22 +++++------ .../threshold/user_data_encryption/utils.rs | 16 ++++---- crates/zk-prover/src/circuits/dkg/pk.rs | 4 +- .../src/circuits/threshold/pk_generation.rs | 4 +- crates/zk-prover/src/circuits/utils.rs | 6 +-- crates/zk-prover/src/error.rs | 3 ++ crates/zk-prover/src/traits.rs | 31 +++++++-------- crates/zk-prover/tests/local_e2e_tests.rs | 12 +++--- examples/CRISP/crates/zk-inputs/src/lib.rs | 8 ++-- 44 files changed, 299 insertions(+), 296 deletions(-) diff --git a/crates/bfv-client/src/client.rs b/crates/bfv-client/src/client.rs index 7519bd7c96..e605694a0d 100644 --- a/crates/bfv-client/src/client.rs +++ b/crates/bfv-client/src/client.rs @@ -7,7 +7,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::Witness as UserDataEncryptionWitness; +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}; use fhe::Error as FheError; @@ -101,7 +101,7 @@ where let plaintext = Plaintext::try_encode(&data, Encoding::poly(), ¶ms) .map_err(|e: FheError| anyhow!("Error encoding plaintext: {}", e))?; - let witness = UserDataEncryptionWitness::compute( + let inputs = UserDataEncryptionInputs::compute( DEFAULT_BFV_PRESET, &UserDataEncryptionCircuitInput { public_key: pk, @@ -109,8 +109,8 @@ where }, )?; - let encrypted_data = witness.ciphertext.clone(); - let circuit_inputs = witness.to_json()?.to_string(); + let encrypted_data = inputs.ciphertext.clone(); + let circuit_inputs = inputs.to_json()?.to_string(); Ok(VerifiableEncryptionResult { encrypted_data, diff --git a/crates/zk-helpers/README.md b/crates/zk-helpers/README.md index aa0b4f0276..f499b4de7a 100644 --- a/crates/zk-helpers/README.md +++ b/crates/zk-helpers/README.md @@ -1,7 +1,8 @@ # zk-helpers ZK circuit artifact generation for the Noir prover. Produces `configs.nr` and optionally -`Prover.toml` for the Enclave circuits. +`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 @@ -15,20 +16,20 @@ cargo run -p e3-zk-helpers --bin zk_cli -- --list_circuits cargo run -p e3-zk-helpers --bin zk_cli -- --circuit pk --preset insecure cargo run -p e3-zk-helpers --bin zk_cli -- --circuit share-computation --preset insecure -# Generate configs.nr and Prover.toml (--witness required for share-computation) +# Generate configs.nr and Prover.toml (--inputs required for share-computation) cargo run -p e3-zk-helpers --bin zk_cli -- --circuit pk --preset insecure --toml -cargo run -p e3-zk-helpers --bin zk_cli -- --circuit share-computation --preset insecure --witness secret-key --toml +cargo run -p e3-zk-helpers --bin zk_cli -- --circuit share-computation --preset insecure --inputs secret-key --toml # Generate only Prover.toml (no configs.nr), e.g. for benchmarks where circuits use lib configs cargo run -p e3-zk-helpers --bin zk_cli -- --circuit pk --preset insecure --toml --no-configs ``` -| Flag | Description | -| ------------------ | ------------------------------------------------------------------------------ | -| `--list_circuits` | List circuits and exit | -| `--circuit ` | Circuit name (e.g. `pk`, `share-computation`, `threshold-share-decryption`) | -| `--preset ` | Security preset: `insecure` (512) or `secure` (8192) | -| `--witness ` | For DKG witness circuits when using `--toml`: `secret-key` or `smudging-noise` | -| `--output ` | Output dir (default: `output`) | -| `--toml` | Also write Prover.toml (default: configs.nr only) | -| `--no-configs` | With `--toml`: do not write configs.nr (e.g. for circuit benchmarks) | +| Flag | Description | +| ------------------ | ---------------------------------------------------------------------------- | +| `--list_circuits` | List circuits and exit | +| `--circuit ` | Circuit name (e.g. `pk`, `share-computation`, `threshold-share-decryption`) | +| `--preset ` | Security preset: `insecure` (512) or `secure` (8192) | +| `--inputs ` | For DKG circuit inputs when using `--toml`: `secret-key` or `smudging-noise` | +| `--output ` | Output dir (default: `output`) | +| `--toml` | Also write Prover.toml (default: configs.nr only) | +| `--no-configs` | With `--toml`: do not write configs.nr (e.g. for circuit benchmarks) | diff --git a/crates/zk-helpers/src/bin/zk_cli.rs b/crates/zk-helpers/src/bin/zk_cli.rs index da103b7293..3b2d9c5eb7 100644 --- a/crates/zk-helpers/src/bin/zk_cli.rs +++ b/crates/zk-helpers/src/bin/zk_cli.rs @@ -69,11 +69,11 @@ fn clear_terminal() { let _ = std::io::stdout().flush(); } -/// Print a summary of what will be generated (circuit, preset, witness, output, artifacts). +/// Print a summary of what will be generated (circuit, preset, inputs, output, artifacts). fn print_generation_info( circuit: &str, preset: BfvPreset, - has_witness: bool, + has_inputs: bool, dkg_input_type: DkgInputType, output: &std::path::Path, write_prover_toml: bool, @@ -87,9 +87,9 @@ fn print_generation_info( meta.degree, meta.num_moduli ); - if has_witness { + if has_inputs { println!( - " Witness: {}", + " Inputs: {}", match dkg_input_type { DkgInputType::SecretKey => "secret-key", DkgInputType::SmudgingNoise => "smudging-noise", @@ -151,9 +151,9 @@ struct Cli { /// Preset: "insecure"|"secure" or λ (2|80). Drives both threshold and DKG params. #[arg(long, required_unless_present = "list_circuits")] preset: Option, - /// For share-computation only: witness type "secret-key" or "smudging-noise". Required when writing Prover.toml for share-computation. Ignored for pk (always secret key). + /// For share-computation only: inputs type "secret-key" or "smudging-noise". Required when writing Prover.toml for share-computation. Ignored for pk (always secret key). #[arg(long)] - witness: Option, + inputs: Option, /// Output directory for generated artifacts. #[arg(long, default_value = "output")] output: PathBuf, @@ -227,24 +227,24 @@ fn main() -> Result<()> { let write_prover_toml = args.toml; let no_configs = args.no_configs && args.toml; - // DKG circuits have a witness-type choice (secret-key vs smudging-noise) excluding `pk` or C0 circuit. - let has_witness_type = circuit_meta.name() == ShareComputationCircuit::NAME + // DKG circuits have a inputs-type choice (secret-key vs smudging-noise) excluding `pk` or C0 circuit. + let has_inputs_type = circuit_meta.name() == ShareComputationCircuit::NAME || circuit_meta.name() == ShareEncryptionCircuit::NAME || circuit_meta.name() == DkgShareDecryptionCircuit::NAME; - let dkg_input_type = if has_witness_type { - // Share-computation: require --witness when generating Prover.toml; default secret-key for configs-only. - let witness_str = if !args.toml { - args.witness.as_deref().unwrap_or("secret-key") + let dkg_input_type = if has_inputs_type { + // Share-computation: require --inputs when generating Prover.toml; default secret-key for configs-only. + let inputs_str = if !args.toml { + args.inputs.as_deref().unwrap_or("secret-key") } else { - args.witness.as_deref().ok_or_else(|| { + args.inputs.as_deref().ok_or_else(|| { anyhow!( - "circuit {} requires --witness (secret-key or smudging-noise) when writing Prover.toml", + "circuit {} requires --inputs (secret-key or smudging-noise) when writing Prover.toml", circuit ) })? }; - let arg = parse_input_type(witness_str)?; + let arg = parse_input_type(inputs_str)?; match arg { DkgInputTypeArg::SecretKey => DkgInputType::SecretKey, DkgInputTypeArg::SmudgingNoise => DkgInputType::SmudgingNoise, @@ -258,7 +258,7 @@ fn main() -> Result<()> { print_generation_info( &circuit, preset, - has_witness_type, + has_inputs_type, dkg_input_type.clone(), &args.output, write_prover_toml, diff --git a/crates/zk-helpers/src/circuits/codegen.rs b/crates/zk-helpers/src/circuits/codegen.rs index e3f8a8d8f3..6a1d802792 100644 --- a/crates/zk-helpers/src/circuits/codegen.rs +++ b/crates/zk-helpers/src/circuits/codegen.rs @@ -12,7 +12,7 @@ use crate::errors::CircuitsErrors; use std::path::Path; -/// Prover TOML file content (witness and circuit inputs). +/// Prover TOML file content (circuit inputs). pub type CodegenToml = String; /// Noir configs file content (global constants for the prover). pub type CodegenConfigs = String; @@ -20,7 +20,7 @@ pub type CodegenConfigs = String; /// Generated files for a circuit: Prover TOML and Noir configs. #[derive(Debug, Clone)] pub struct Artifacts { - /// Prover.toml content (witness and circuit inputs). + /// Prover.toml content (circuit inputs). pub toml: CodegenToml, /// configs.nr content (constants for the Noir prover). pub configs: CodegenConfigs, diff --git a/crates/zk-helpers/src/circuits/computation.rs b/crates/zk-helpers/src/circuits/computation.rs index d3ae2aa0f5..88d1127e64 100644 --- a/crates/zk-helpers/src/circuits/computation.rs +++ b/crates/zk-helpers/src/circuits/computation.rs @@ -7,7 +7,7 @@ //! Computation traits and artifact types. //! //! [`Computation`] is a generic trait for computing values from parameters and input. -//! [`CircuitComputation`] extends it for circuits that produce witness/bounds/bits. +//! [`CircuitComputation`] extends it for circuits that produce inputs/bounds/bits. //! [`Toml`] and [`Configs`] are the string types used for Prover.toml and configs.nr. /// Variant for input types for DKG. @@ -38,13 +38,13 @@ pub trait Computation: Sized { } } -/// Circuit-specific computation: parameters and input produce bounds, bits, witness, etc. +/// Circuit-specific computation: parameters and input produce bounds, bits, circuit inputs, etc. pub trait CircuitComputation: crate::registry::Circuit { type Preset; type Input; type Output; type Error; - /// Computes circuit-specific data (bounds, bits, witness) from parameters and input. + /// Computes circuit-specific data (bounds, bits, inputs) from parameters and input. fn compute(preset: Self::Preset, input: &Self::Input) -> Result; } diff --git a/crates/zk-helpers/src/circuits/dkg/pk/codegen.rs b/crates/zk-helpers/src/circuits/dkg/pk/codegen.rs index fc1223c8b4..3f7be69dcb 100644 --- a/crates/zk-helpers/src/circuits/dkg/pk/codegen.rs +++ b/crates/zk-helpers/src/circuits/dkg/pk/codegen.rs @@ -8,7 +8,7 @@ use crate::circuits::dkg::pk::circuit::PkCircuit; use crate::circuits::dkg::pk::circuit::PkCircuitInput; -use crate::circuits::dkg::pk::computation::{Bits, PkComputationOutput, Witness}; +use crate::circuits::dkg::pk::computation::{Bits, Inputs, PkComputationOutput}; use crate::Artifacts; use crate::Circuit; use crate::CircuitCodegen; @@ -27,18 +27,18 @@ impl CircuitCodegen for PkCircuit { type Error = CircuitsErrors; fn codegen(&self, preset: Self::Preset, input: &Self::Input) -> Result { - let PkComputationOutput { witness, bits, .. } = PkCircuit::compute(preset, input)?; + let PkComputationOutput { inputs, bits, .. } = PkCircuit::compute(preset, input)?; - let toml = generate_toml(witness)?; + let toml = generate_toml(inputs)?; let configs = generate_configs(preset, &bits); Ok(Artifacts { toml, configs }) } } -/// Builds the Prover TOML string from the pk witness (pk0is, pk1is). -pub fn generate_toml(witness: Witness) -> Result { - let json = witness +/// Builds the Prover TOML string from the pk input (pk0is, pk1is). +pub fn generate_toml(inputs: Inputs) -> Result { + let json = inputs .to_json() .map_err(|e| CircuitsErrors::SerdeJson(e))?; diff --git a/crates/zk-helpers/src/circuits/dkg/pk/computation.rs b/crates/zk-helpers/src/circuits/dkg/pk/computation.rs index 18f59a40f1..31b7a90827 100644 --- a/crates/zk-helpers/src/circuits/dkg/pk/computation.rs +++ b/crates/zk-helpers/src/circuits/dkg/pk/computation.rs @@ -4,10 +4,10 @@ // without even the implied warranty of MERCHANTABILITY // or FITNESS FOR A PARTICULAR PURPOSE. -//! Computation types for the pk circuit: constants, bounds, bit widths, and witness. +//! Computation types for the pk circuit: constants, bounds, bit widths, and input. //! -//! [`Constants`], [`Bounds`], [`Bits`], and [`Witness`] are produced from BFV parameters -//! and (for witness) a public key. They implement [`Computation`] and are used by codegen. +//! [`Constants`], [`Bounds`], [`Bits`], and [`Inputs`] are produced from BFV parameters +//! 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; @@ -23,12 +23,12 @@ use e3_polynomial::CrtPolynomial; use num_bigint::BigUint; use serde::{Deserialize, Serialize}; -/// Output of [`CircuitComputation::compute`] for [`PkCircuit`]: bounds, bit widths, and witness. +/// Output of [`CircuitComputation::compute`] for [`PkCircuit`]: bounds, bit widths, and input. #[derive(Debug)] pub struct PkComputationOutput { pub bounds: Bounds, pub bits: Bits, - pub witness: Witness, + pub inputs: Inputs, } /// Implementation of [`CircuitComputation`] for [`PkCircuit`]. @@ -41,12 +41,12 @@ impl CircuitComputation for PkCircuit { fn compute(preset: Self::Preset, input: &Self::Input) -> Result { let bounds = Bounds::compute(preset, &())?; let bits = Bits::compute(preset, &())?; - let witness = Witness::compute(preset, input)?; + let inputs = Inputs::compute(preset, input)?; Ok(PkComputationOutput { bounds, bits, - witness, + inputs, }) } } @@ -73,9 +73,9 @@ pub struct Bounds { pub pk_bound: BigUint, } -/// Witness data for the pk circuit: public key polynomials in CRT form for the prover. +/// Input for the pk circuit: public key polynomials in CRT form for the prover. #[derive(Debug, Clone, Serialize, Deserialize)] -pub struct Witness { +pub struct Inputs { /// Public key polynomials (pk0, pk1) for each CRT basis. pub pk0is: CrtPolynomial, pub pk1is: CrtPolynomial, @@ -137,7 +137,7 @@ impl Computation for Bounds { } } -impl Computation for Witness { +impl Computation for Inputs { type Preset = BfvPreset; type Input = PkCircuitInput; type Error = CircuitsErrors; @@ -155,10 +155,10 @@ impl Computation for Witness { pk0is.reduce_uniform(zkp_modulus); pk1is.reduce_uniform(zkp_modulus); - Ok(Witness { pk0is, pk1is }) + Ok(Inputs { pk0is, pk1is }) } - // Used as witness for Nargo execution. + // Used as inputs for Nargo execution. fn to_json(&self) -> serde_json::Result { let pk0is = crt_polynomial_to_toml_json(&self.pk0is); let pk1is = crt_polynomial_to_toml_json(&self.pk1is); diff --git a/crates/zk-helpers/src/circuits/dkg/pk/mod.rs b/crates/zk-helpers/src/circuits/dkg/pk/mod.rs index deb60507dc..faa06d83f0 100644 --- a/crates/zk-helpers/src/circuits/dkg/pk/mod.rs +++ b/crates/zk-helpers/src/circuits/dkg/pk/mod.rs @@ -11,4 +11,4 @@ pub mod sample; pub use circuit::{PkCircuit, PkCircuitInput}; pub use codegen::{generate_configs, generate_toml}; -pub use computation::{Bits, Bounds, Configs, PkComputationOutput, Witness}; +pub use computation::{Bits, Bounds, Configs, Inputs, PkComputationOutput}; 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 fcde32480d..b196de58f4 100644 --- a/crates/zk-helpers/src/circuits/dkg/share_computation/circuit.rs +++ b/crates/zk-helpers/src/circuits/dkg/share_computation/circuit.rs @@ -24,7 +24,7 @@ impl Circuit for ShareComputationCircuit { } pub struct ShareComputationCircuitInput { - /// Which secret type this input is for (determines which branch to use in witness). + /// Which secret type this input is for (determines which branch to use in input). 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 6f8c3e4866..f6c5afb681 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, ShareComputationCircuit, - ShareComputationCircuitInput, ShareComputationOutput, Witness, + Inputs, ShareComputationCircuitInput, ShareComputationOutput, }; use crate::circuits::{Artifacts, CircuitCodegen, CircuitsErrors, CodegenToml}; use crate::codegen::CodegenConfigs; @@ -29,10 +29,10 @@ impl CircuitCodegen for ShareComputationCircuit { type Error = CircuitsErrors; fn codegen(&self, preset: Self::Preset, input: &Self::Input) -> Result { - let ShareComputationOutput { witness, bits, .. } = + let ShareComputationOutput { inputs, bits, .. } = ShareComputationCircuit::compute(preset, input)?; - let toml = generate_toml(&witness, input.dkg_input_type.clone())?; + let toml = generate_toml(&inputs, input.dkg_input_type.clone())?; let configs = generate_configs( preset, &bits, @@ -45,15 +45,15 @@ impl CircuitCodegen for ShareComputationCircuit { } pub fn generate_toml( - witness: &Witness, + inputs: &Inputs, dkg_input_type: DkgInputType, ) -> Result { - let mut json = witness + let mut json = inputs .to_json() .map_err(|e| CircuitsErrors::SerdeJson(e))?; let obj = json.as_object_mut().ok_or(CircuitsErrors::Other( - "witness json is not an object".to_string(), + "input json is not an object".to_string(), ))?; obj.remove("secret_crt"); @@ -61,11 +61,11 @@ pub fn generate_toml( let (key, value) = match dkg_input_type { DkgInputType::SecretKey => ( "sk_secret", - poly_coefficients_to_toml_json(witness.secret_crt.limb(0).coefficients()), + poly_coefficients_to_toml_json(inputs.secret_crt.limb(0).coefficients()), ), DkgInputType::SmudgingNoise => ( "e_sm_secret", - serde_json::Value::Array(crt_polynomial_to_toml_json(&witness.secret_crt)), + serde_json::Value::Array(crt_polynomial_to_toml_json(&inputs.secret_crt)), ), }; @@ -77,7 +77,7 @@ pub fn generate_toml( /// Builds the configs.nr string (N, L, parity matrix, bit parameters, configs) for the Noir prover. /// /// `n_parties` and `threshold` are used to build the parity matrix (Reed–Solomon generator null space) -/// and must match the committee size used for the witness/sample. +/// and must match the committee size used for the input/sample. pub fn generate_configs( preset: BfvPreset, bits: &Bits, 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 885537b706..4f71202f8e 100644 --- a/crates/zk-helpers/src/circuits/dkg/share_computation/computation.rs +++ b/crates/zk-helpers/src/circuits/dkg/share_computation/computation.rs @@ -4,10 +4,10 @@ // without even the implied warranty of MERCHANTABILITY // or FITNESS FOR A PARTICULAR PURPOSE. -//! Computation types for the share-computation circuit: constants, bounds, bit widths, and witness. +//! Computation types for the share-computation circuit: constants, bounds, bit widths, and input. //! -//! [`Configs`], [`Bounds`], [`Bits`], and [`Witness`] are produced from BFV parameters -//! and (for witness) secret plus shares. Witness values are normalized to [0, q_j) per modulus +//! [`Configs`], [`Bounds`], [`Bits`], and [`Inputs`] are produced from BFV parameters +//! and (for input) secret plus shares. Input values are normalized to [0, q_j) per modulus //! and then to the ZKP field modulus so the Noir circuit's range check and parity check succeed. use crate::circuits::commitments::{ @@ -28,12 +28,12 @@ use fhe::trbfv::{SmudgingBoundCalculator, SmudgingBoundCalculatorConfig}; use num_bigint::{BigInt, BigUint}; use serde::{Deserialize, Serialize}; -/// Output of [`CircuitComputation::compute`] for [`ShareComputationCircuit`]: bounds, bit widths, and witness. +/// Output of [`CircuitComputation::compute`] for [`ShareComputationCircuit`]: bounds, bit widths, and input. #[derive(Debug)] pub struct ShareComputationOutput { pub bounds: Bounds, pub bits: Bits, - pub witness: Witness, + pub inputs: Inputs, } /// Implementation of [`CircuitComputation`] for [`ShareComputationCircuit`]. @@ -46,12 +46,12 @@ impl CircuitComputation for ShareComputationCircuit { fn compute(preset: Self::Preset, input: &Self::Input) -> Result { let bounds = Bounds::compute(preset, input)?; let bits = Bits::compute(preset, &bounds)?; - let witness = Witness::compute(preset, input)?; + let inputs = Inputs::compute(preset, input)?; Ok(ShareComputationOutput { bounds, bits, - witness, + inputs, }) } } @@ -80,13 +80,13 @@ pub struct Bounds { pub e_sm_bound: BigUint, } -/// Witness data for the share-computation circuit: secret in CRT form, y (secret + shares per coeff/modulus), and commitment. +/// Input for the share-computation circuit: secret in CRT form, y (secret + shares per coeff/modulus), and commitment. /// /// All coefficients are reduced to the ZKP field modulus for serialization. Before that, /// secret_crt and y are normalized so that per modulus j: secret and shares are in [0, q_j), /// ensuring the circuit's secret consistency (y[i][j][0] == e_sm_secret[j][i]), range check, and parity check pass. #[derive(Debug, Clone, Serialize, Deserialize)] -pub struct Witness { +pub struct Inputs { /// Secret polynomial in CRT form (SK or smudging noise). Coefficients in [0, zkp_modulus) for serialization. pub secret_crt: CrtPolynomial, /// y[coeff_idx][mod_idx][0] = secret at (mod_idx, coeff_idx); y[coeff_idx][mod_idx][1 + party] = share for party. Values in [0, zkp_modulus). @@ -175,7 +175,7 @@ impl Computation for Bounds { } } -impl Computation for Witness { +impl Computation for Inputs { type Preset = BfvPreset; type Input = ShareComputationCircuitInput; type Error = CircuitsErrors; @@ -237,14 +237,14 @@ impl Computation for Witness { } } - Ok(Witness { + Ok(Inputs { secret_crt, y, expected_secret_commitment, }) } - // Used as witness for Nargo execution. + // Used as input for Nargo execution. fn to_json(&self) -> serde_json::Result { let secret_crt = crt_polynomial_to_toml_json(&self.secret_crt); let y = bigint_3d_to_json_values(&self.y); @@ -286,7 +286,7 @@ mod tests { } #[test] - fn test_witness_smudging_noise_secret_consistency() { + fn test_input_smudging_noise_secret_consistency() { let committee = CiphernodesCommitteeSize::Small.values(); let sample = ShareComputationCircuitInput::generate_sample( BfvPreset::InsecureThreshold512, @@ -294,14 +294,14 @@ mod tests { DkgInputType::SmudgingNoise, ) .unwrap(); - let witness = Witness::compute(BfvPreset::InsecureThreshold512, &sample).unwrap(); - let degree = witness.secret_crt.limb(0).coefficients().len(); - let num_moduli = witness.secret_crt.limbs.len(); + let inputs = Inputs::compute(BfvPreset::InsecureThreshold512, &sample).unwrap(); + let degree = inputs.secret_crt.limb(0).coefficients().len(); + let num_moduli = inputs.secret_crt.limbs.len(); for coeff_idx in 0..degree { for mod_idx in 0..num_moduli { let secret_coeff = - witness.secret_crt.limb(mod_idx).coefficients()[coeff_idx].clone(); - let y_secret = witness.y[coeff_idx][mod_idx][0].clone(); + inputs.secret_crt.limb(mod_idx).coefficients()[coeff_idx].clone(); + let y_secret = inputs.y[coeff_idx][mod_idx][0].clone(); assert_eq!( secret_coeff, y_secret, "secret consistency: secret_crt[{mod_idx}][{coeff_idx}] must equal y[{coeff_idx}][{mod_idx}][0]" 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 d1105ce5d0..8578d3bdf1 100644 --- a/crates/zk-helpers/src/circuits/dkg/share_computation/mod.rs +++ b/crates/zk-helpers/src/circuits/dkg/share_computation/mod.rs @@ -11,5 +11,5 @@ pub mod sample; pub mod utils; pub use circuit::{ShareComputationCircuit, ShareComputationCircuitInput}; -pub use computation::{Bits, Bounds, Configs, ShareComputationOutput, Witness}; +pub use computation::{Bits, Bounds, Configs, Inputs, ShareComputationOutput}; pub use sample::SecretShares; 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 bec0bf27d1..e6c63b9a6a 100644 --- a/crates/zk-helpers/src/circuits/dkg/share_decryption/circuit.rs +++ b/crates/zk-helpers/src/circuits/dkg/share_decryption/circuit.rs @@ -26,7 +26,7 @@ impl Circuit for ShareDecryptionCircuit { /// Input to the share-decryption circuit: secret key and honest parties' ciphertexts. pub struct ShareDecryptionCircuitInput { - /// DKG secret key used to decrypt (private witness). + /// 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). pub honest_ciphertexts: Vec>, 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 ca3c6a26b2..0e6ca980d8 100644 --- a/crates/zk-helpers/src/circuits/dkg/share_decryption/codegen.rs +++ b/crates/zk-helpers/src/circuits/dkg/share_decryption/codegen.rs @@ -11,7 +11,7 @@ use crate::circuits::dkg::share_decryption::Configs; use crate::circuits::dkg::share_decryption::ShareDecryptionCircuit; use crate::circuits::dkg::share_decryption::ShareDecryptionCircuitInput; use crate::circuits::dkg::share_decryption::ShareDecryptionOutput; -use crate::circuits::dkg::share_decryption::Witness; +use crate::circuits::dkg::share_decryption::Inputs; use crate::circuits::{Artifacts, CircuitCodegen, CircuitsErrors, CodegenToml}; use crate::codegen::CodegenConfigs; use crate::computation::Computation; @@ -25,9 +25,9 @@ impl CircuitCodegen for ShareDecryptionCircuit { type Error = CircuitsErrors; fn codegen(&self, preset: Self::Preset, input: &Self::Input) -> Result { - let ShareDecryptionOutput { witness, .. } = ShareDecryptionCircuit::compute(preset, input)?; + let ShareDecryptionOutput { inputs, .. } = ShareDecryptionCircuit::compute(preset, input)?; - let toml = generate_toml(&witness)?; + let toml = generate_toml(&inputs)?; let configs = Configs::compute(preset, input)?; let configs_str = generate_configs(preset, &configs); @@ -38,9 +38,9 @@ impl CircuitCodegen for ShareDecryptionCircuit { } } -/// Serializes the witness to TOML string for the Noir prover (Prover.toml). -pub fn generate_toml(witness: &Witness) -> Result { - let json = witness +/// Serializes the input to TOML string for the Noir prover (Prover.toml). +pub fn generate_toml(inputs: &Inputs) -> Result { + let json = inputs .to_json() .map_err(|e| CircuitsErrors::SerdeJson(e))?; 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 c8af802e69..65341234f0 100644 --- a/crates/zk-helpers/src/circuits/dkg/share_decryption/computation.rs +++ b/crates/zk-helpers/src/circuits/dkg/share_decryption/computation.rs @@ -4,10 +4,10 @@ // without even the implied warranty of MERCHANTABILITY // or FITNESS FOR A PARTICULAR PURPOSE. -//! Computation types for the share-decryption circuit: configs, bounds, bit widths, and witness. +//! Computation types for the share-decryption circuit: configs, bounds, bit widths, and input. //! -//! [`Configs`], [`Bounds`], [`Bits`], and [`Witness`] are produced from BFV parameters -//! and (for witness) honest ciphertexts and secret key. Witness values are normalized for the ZKP +//! [`Configs`], [`Bounds`], [`Bits`], and [`Inputs`] are produced from BFV parameters +//! and (for input) honest ciphertexts and secret key. Input values are normalized for the ZKP //! field so the Noir circuit's range checks and commitment checks succeed. use crate::circuits::commitments::compute_share_encryption_commitment_from_message; @@ -24,15 +24,15 @@ use num_bigint::BigInt; use serde::{Deserialize, Serialize}; use std::ops::Deref; -/// Output of [`CircuitComputation::compute`] for [`ShareDecryptionCircuit`]: bounds, bit widths, and witness. +/// Output of [`CircuitComputation::compute`] for [`ShareDecryptionCircuit`]: bounds, bit widths, and input. #[derive(Debug)] pub struct ShareDecryptionOutput { /// Coefficient bounds used to derive bit widths. pub bounds: Bounds, /// Bit widths used by the Noir prover for packing. pub bits: Bits, - /// Witness data for the share-decryption circuit. - pub witness: Witness, + /// Input for the share-decryption circuit. + pub inputs: Inputs, } /// Implementation of [`CircuitComputation`] for [`ShareDecryptionCircuit`]. @@ -45,12 +45,12 @@ impl CircuitComputation for ShareDecryptionCircuit { fn compute(preset: Self::Preset, input: &Self::Input) -> Result { let bounds = Bounds::compute(preset, input)?; let bits = Bits::compute(preset, &bounds)?; - let witness = Witness::compute(preset, input)?; + let inputs = Inputs::compute(preset, input)?; Ok(ShareDecryptionOutput { bounds, bits, - witness, + inputs, }) } } @@ -79,12 +79,12 @@ pub struct Bits { #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct Bounds {} -/// Witness data for the share-decryption circuit: expected commitments and decrypted shares. +/// Input for the share-decryption circuit: expected commitments and decrypted shares. /// /// Coefficients are reduced to the ZKP field modulus for serialization. The circuit verifies /// that decrypted shares match the expected commitments from the share-encryption circuit. #[derive(Debug, Clone, Serialize, Deserialize)] -pub struct Witness { +pub struct Inputs { /// Expected message commitments from share-encryption (CIRCUIT 3) for H honest parties: [party_idx][mod_idx]. pub expected_commitments: Vec>, // [H][L] /// Decrypted share coefficients per party and modulus: [party_idx][mod_idx][coeff_idx]. @@ -142,7 +142,7 @@ impl Computation for Bounds { } } -impl Computation for Witness { +impl Computation for Inputs { type Preset = BfvPreset; type Input = ShareDecryptionCircuitInput; type Error = CircuitsErrors; @@ -188,14 +188,14 @@ impl Computation for Witness { decrypted_shares.push(party_shares); } - Ok(Witness { + Ok(Inputs { expected_commitments, decrypted_shares, }) } - // Used as witness for Nargo execution. - /// Serializes witness so that `decrypted_shares` matches Noir's `[[Polynomial; L]; H]`: + // Used as input for Nargo execution. + /// Serializes input so that `decrypted_shares` matches Noir's `[[Polynomial; L]; H]`: /// each polynomial is `{ "coefficients": [string, ...] }`. fn to_json(&self) -> serde_json::Result { let expected_commitments = bigint_2d_to_json_values(&self.expected_commitments); @@ -266,7 +266,7 @@ mod tests { } #[test] - fn test_witness_decryption_consistency() { + fn test_input_decryption_consistency() { let committee = CiphernodesCommitteeSize::Small.values(); let sample = ShareDecryptionCircuitInput::generate_sample( BfvPreset::InsecureThreshold512, @@ -274,15 +274,15 @@ mod tests { DkgInputType::SecretKey, ) .unwrap(); - let witness = Witness::compute(BfvPreset::InsecureThreshold512, &sample).unwrap(); + let inputs = Inputs::compute(BfvPreset::InsecureThreshold512, &sample).unwrap(); - // Witness should have one row per honest party + // Inputs should have one row per honest party assert_eq!( - witness.expected_commitments.len(), + inputs.expected_commitments.len(), sample.honest_ciphertexts.len() ); assert_eq!( - witness.decrypted_shares.len(), + inputs.decrypted_shares.len(), sample.honest_ciphertexts.len() ); } 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 5313a42a56..c29f92bb13 100644 --- a/crates/zk-helpers/src/circuits/dkg/share_decryption/mod.rs +++ b/crates/zk-helpers/src/circuits/dkg/share_decryption/mod.rs @@ -11,4 +11,4 @@ pub mod codegen; pub mod computation; pub mod sample; pub use circuit::{ShareDecryptionCircuit, ShareDecryptionCircuitInput}; -pub use computation::{Bits, Bounds, Configs, ShareDecryptionOutput, Witness}; +pub use computation::{Bits, Bounds, Configs, Inputs, ShareDecryptionOutput}; 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 ec3bcd3bf5..40bd0bbb69 100644 --- a/crates/zk-helpers/src/circuits/dkg/share_encryption/circuit.rs +++ b/crates/zk-helpers/src/circuits/dkg/share_encryption/circuit.rs @@ -35,7 +35,7 @@ pub struct ShareEncryptionCircuitInput { pub ciphertext: Ciphertext, /// DKG public key used to encrypt. pub public_key: PublicKey, - /// Secret key (for witness; not revealed in proof). + /// Secret key (for input; not revealed in proof). pub secret_key: SecretKey, /// Encryption randomness u in RNS form (from try_encrypt_extended). pub u_rns: Poly, 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 6ec6af8dc4..ee3e1d612b 100644 --- a/crates/zk-helpers/src/circuits/dkg/share_encryption/codegen.rs +++ b/crates/zk-helpers/src/circuits/dkg/share_encryption/codegen.rs @@ -11,7 +11,7 @@ use crate::circuits::dkg::share_encryption::Configs; use crate::circuits::dkg::share_encryption::ShareEncryptionCircuit; use crate::circuits::dkg::share_encryption::ShareEncryptionCircuitInput; use crate::circuits::dkg::share_encryption::ShareEncryptionOutput; -use crate::circuits::dkg::share_encryption::Witness; +use crate::circuits::dkg::share_encryption::Inputs; use crate::circuits::{Artifacts, CircuitCodegen, CircuitsErrors, CodegenToml}; use crate::codegen::CodegenConfigs; use crate::computation::Computation; @@ -26,9 +26,9 @@ impl CircuitCodegen for ShareEncryptionCircuit { type Error = CircuitsErrors; fn codegen(&self, preset: Self::Preset, input: &Self::Input) -> Result { - let ShareEncryptionOutput { witness, .. } = ShareEncryptionCircuit::compute(preset, input)?; + let ShareEncryptionOutput { inputs, .. } = ShareEncryptionCircuit::compute(preset, input)?; - let toml = generate_toml(&witness)?; + let toml = generate_toml(&inputs)?; let configs = Configs::compute(preset, input)?; let configs_str = generate_configs(preset, &configs); @@ -39,9 +39,9 @@ impl CircuitCodegen for ShareEncryptionCircuit { } } -/// Serializes the witness to TOML string for the Noir prover (Prover.toml). -pub fn generate_toml(witness: &Witness) -> Result { - let json = witness +/// Serializes the input to TOML string for the Noir prover (Prover.toml). +pub fn generate_toml(inputs: &Inputs) -> Result { + let json = inputs .to_json() .map_err(|e| CircuitsErrors::SerdeJson(e))?; 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 fcd032ae2a..53b5b5ea1b 100644 --- a/crates/zk-helpers/src/circuits/dkg/share_encryption/computation.rs +++ b/crates/zk-helpers/src/circuits/dkg/share_encryption/computation.rs @@ -4,10 +4,10 @@ // without even the implied warranty of MERCHANTABILITY // or FITNESS FOR A PARTICULAR PURPOSE. -//! Computation types for the share-encryption circuit: configs, bounds, bit widths, and witness. +//! Computation types for the share-encryption circuit: configs, bounds, bit widths, and input. //! -//! [`Configs`], [`Bounds`], [`Bits`], and [`Witness`] are produced from BFV parameters -//! and (for witness) plaintext, ciphertext, and encryption randomness. Witness values are +//! [`Configs`], [`Bounds`], [`Bits`], and [`Inputs`] are produced from BFV parameters +//! and (for input) plaintext, ciphertext, and encryption randomness. Input values are //! normalized for the ZKP field so the Noir circuit's range checks and commitment checks succeed. use crate::circuits::commitments::{ @@ -41,15 +41,15 @@ use rayon::iter::ParallelIterator; use rayon::prelude::ParallelBridge; use serde::{Deserialize, Serialize}; -/// Output of [`CircuitComputation::compute`] for [`ShareEncryptionCircuit`]: bounds, bit widths, and witness. +/// Output of [`CircuitComputation::compute`] for [`ShareEncryptionCircuit`]: bounds, bit widths, and input. #[derive(Debug)] pub struct ShareEncryptionOutput { /// Coefficient bounds used to derive bit widths. pub bounds: Bounds, /// Bit widths used by the Noir prover for packing. pub bits: Bits, - /// Witness data for the share-encryption circuit. - pub witness: Witness, + /// Input for the share-encryption circuit. + pub inputs: Inputs, } /// Implementation of [`CircuitComputation`] for [`ShareEncryptionCircuit`]. @@ -62,12 +62,12 @@ impl CircuitComputation for ShareEncryptionCircuit { fn compute(preset: Self::Preset, input: &Self::Input) -> Result { let bounds = Bounds::compute(preset, input)?; let bits = Bits::compute(preset, &bounds)?; - let witness = Witness::compute(preset, input)?; + let inputs = Inputs::compute(preset, input)?; Ok(ShareEncryptionOutput { bounds, bits, - witness, + inputs, }) } } @@ -117,12 +117,12 @@ pub struct Bounds { pub p2_bounds: Vec, } -/// Witness data for the share-encryption circuit: CRT limbs for pk, ct, randomness, and message. +/// Input for the share-encryption circuit: CRT limbs for pk, ct, randomness, and message. /// /// Coefficients are reduced to the ZKP field modulus for serialization. The circuit verifies /// that the ciphertext and commitments match the public inputs. #[derive(Debug, Clone, Serialize, Deserialize)] -pub struct Witness { +pub struct Inputs { /// Public key and ciphertext polynomials in CRT form (per modulus). pub pk0is: CrtPolynomial, pub pk1is: CrtPolynomial, @@ -344,7 +344,7 @@ impl Computation for Bounds { } } -impl Computation for Witness { +impl Computation for Inputs { type Preset = BfvPreset; type Input = ShareEncryptionCircuitInput; type Error = CircuitsErrors; @@ -682,7 +682,7 @@ impl Computation for Witness { let pk_commitment = compute_dkg_pk_commitment(&pk0is, &pk1is, pk_bit); let msg_commitment = compute_share_encryption_commitment_from_message(&message, msg_bit); - Ok(Witness { + Ok(Inputs { pk0is, pk1is, ct0is, @@ -702,7 +702,7 @@ impl Computation for Witness { }) } - // Used as witness for Nargo execution. + // Used as input for Nargo execution. fn to_json(&self) -> serde_json::Result { let pk0is = crt_polynomial_to_toml_json(&self.pk0is); let pk1is = crt_polynomial_to_toml_json(&self.pk1is); @@ -801,7 +801,7 @@ mod tests { } #[test] - fn test_witness_message_consistency() { + fn test_input_message_consistency() { let sd = BfvPreset::InsecureThreshold512.search_defaults().unwrap(); let committee = CiphernodesCommitteeSize::Small.values(); let sample = ShareEncryptionCircuitInput::generate_sample( @@ -812,13 +812,13 @@ mod tests { sd.lambda, ) .unwrap(); - let witness = Witness::compute(BfvPreset::InsecureThreshold512, &sample).unwrap(); + let inputs = Inputs::compute(BfvPreset::InsecureThreshold512, &sample).unwrap(); - // witness.message is plaintext coefficients (reversed, as used in circuit) + // inputs.message is plaintext coefficients (reversed, as used in circuit) let expected_message = Polynomial::from_u64_vector(sample.plaintext.value.deref().to_vec()); let mut expected = expected_message; expected.reverse(); - assert_eq!(witness.message.coefficients(), expected.coefficients()); + assert_eq!(inputs.message.coefficients(), expected.coefficients()); } } 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 a52d988af2..578cfc4d8a 100644 --- a/crates/zk-helpers/src/circuits/dkg/share_encryption/mod.rs +++ b/crates/zk-helpers/src/circuits/dkg/share_encryption/mod.rs @@ -11,4 +11,4 @@ pub mod codegen; pub mod computation; pub mod sample; pub use circuit::{ShareEncryptionCircuit, ShareEncryptionCircuitInput}; -pub use computation::{Bits, Bounds, Configs, ShareEncryptionOutput, Witness}; +pub use computation::{Bits, Bounds, Configs, Inputs, ShareEncryptionOutput}; 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 5e78ab057d..89c7284f84 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 @@ -21,8 +21,8 @@ impl Circuit for DecryptedSharesAggregationCircuit { const DKG_INPUT_TYPE: Option = None; } -/// Raw input for witness computation: decryption share polynomials from T+1 parties, -/// party IDs (1-based), and decoded message. Witness::compute runs Lagrange + CRT. +/// 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 committee: CiphernodesCommittee, 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 5d7e74043b..947dffaa0a 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 @@ -10,7 +10,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, Witness}; +use crate::threshold::decrypted_shares_aggregation::computation::{Configs, Inputs}; use crate::threshold::decrypted_shares_aggregation::DecryptedSharesAggregationCircuitInput; use crate::Circuit; use crate::CircuitCodegen; @@ -24,10 +24,10 @@ impl CircuitCodegen for DecryptedSharesAggregationCircuit { type Error = CircuitsErrors; fn codegen(&self, preset: Self::Preset, input: &Self::Input) -> Result { - let witness = Witness::compute(preset, input)?; + let inputs = Inputs::compute(preset, input)?; let configs = Configs::compute(preset, &())?; - let toml = generate_toml(witness)?; + let toml = generate_toml(inputs)?; let configs_str = generate_configs(preset, &configs); Ok(Artifacts { @@ -37,15 +37,15 @@ impl CircuitCodegen for DecryptedSharesAggregationCircuit { } } -pub fn generate_toml(witness: Witness) -> Result { - let json = witness.to_json().map_err(CircuitsErrors::SerdeJson)?; +pub fn generate_toml(inputs: Inputs) -> Result { + let json = inputs.to_json().map_err(CircuitsErrors::SerdeJson)?; Ok(toml::to_string(&json)?) } /// Generates the decrypted_shares_aggregation config fragment for threshold.nr. /// Emits L, QIS, PLAINTEXT_MODULUS, Q_INVERSE_MOD_T so the circuit uses the same -/// crypto params as the witness (avoids "Cannot satisfy constraint" from config mismatch). +/// crypto params as the input (avoids "Cannot satisfy constraint" from config mismatch). pub fn generate_configs(_preset: BfvPreset, configs: &Configs) -> CodegenConfigs { let prefix = ::PREFIX; let qis_str = configs 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 9a34198b28..677481536c 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 @@ -4,11 +4,11 @@ // without even the implied warranty of MERCHANTABILITY // or FITNESS FOR A PARTICULAR PURPOSE. -//! Bounds, configs, bits, and witness computation for the Decryption Share Aggregation TRBFV circuit. +//! Bounds, configs, bits, and input computation for the Decryption Share Aggregation TRBFV circuit. //! //! Uses [`crate::threshold::decrypted_shares_aggregation::utils`] for Q/delta, modular inverses, -//! Lagrange-at-zero recovery, and scalar CRT reconstruction. Witness coefficients are normalized -//! with [`e3_polynomial::reduce`] in [`Witness::standard_form`], consistent with other circuits. +//! Lagrange-at-zero recovery, and scalar CRT reconstruction. Input coefficients are normalized +//! with [`e3_polynomial::reduce`] in [`Input::standard_form`], consistent with other circuits. use crate::calculate_bit_width; use crate::get_zkp_modulus; @@ -30,7 +30,7 @@ use serde::{Deserialize, Serialize}; pub struct DecryptedSharesAggregationComputationOutput { pub bounds: Bounds, pub bits: Bits, - pub witness: Witness, + pub inputs: Inputs, } impl CircuitComputation for DecryptedSharesAggregationCircuit { @@ -42,12 +42,12 @@ impl CircuitComputation for DecryptedSharesAggregationCircuit { fn compute(preset: Self::Preset, input: &Self::Input) -> Result { let bounds = Bounds::compute(preset, &())?; let bits = Bits::compute(preset, &bounds)?; - let witness = Witness::compute(preset, input)?; + let inputs = Inputs::compute(preset, input)?; Ok(DecryptedSharesAggregationComputationOutput { bounds, bits, - witness, + inputs, }) } } @@ -79,10 +79,10 @@ pub struct Configs { pub max_msg_non_zero_coeffs: usize, } -/// Witness for decrypted shares aggregation (same shape as old DecSharesAggTrBfvVectors). +/// Input for decrypted shares aggregation (same shape as old DecSharesAggTrBfvVectors). /// All coefficients reduced to [0, zkp_modulus) in standard_form. #[derive(Debug, Clone, Serialize, Deserialize)] -pub struct Witness { +pub struct Inputs { /// [party][modulus][coeff] pub decryption_shares: Vec>>, /// Party IDs (1-based: 1, 2, ..., T+1) @@ -152,7 +152,7 @@ impl Computation for Configs { } } -impl Computation for Witness { +impl Computation for Inputs { type Preset = BfvPreset; type Input = DecryptedSharesAggregationCircuitInput; type Error = CircuitsErrors; @@ -220,7 +220,7 @@ impl Computation for Witness { .map(|&x| BigInt::from(x)) .collect(); - // 3. Message (pad to degree for computation, then truncate to MAX_MSG_NON_ZERO_COEFFS for witness) + // 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(); message.resize(degree, BigInt::zero()); @@ -292,22 +292,22 @@ impl Computation for Witness { .map(|row| truncate(&row)) .collect(); - let witness = Witness { + let inputs = Inputs { decryption_shares, party_ids, message, u_global, crt_quotients, }; - Ok(witness.standard_form()) + Ok(inputs.standard_form()) } } -impl Witness { +impl Inputs { /// Reduce all coefficients to [0, zkp_modulus). Uses `e3_polynomial::reduce` like other circuits. pub fn standard_form(&self) -> Self { let zkp_modulus = get_zkp_modulus(); - Witness { + Inputs { decryption_shares: self .decryption_shares .iter() @@ -341,7 +341,7 @@ impl Witness { } } - /// Serializes the witness to JSON for Prover.toml. Each polynomial is emitted as + /// Serializes the input to JSON for Prover.toml. Each polynomial is emitted as /// `{ "coefficients": [string, ...] }` to match Noir's `Polynomial` struct. pub fn to_json(&self) -> serde_json::Result { use crate::bigint_1d_to_json_values; @@ -416,10 +416,10 @@ mod tests { let out = DecryptedSharesAggregationCircuit::compute(preset, &input).unwrap(); let configs = Configs::compute(preset, &()).unwrap(); - assert_eq!(out.witness.decryption_shares.len(), committee.threshold + 1); - assert_eq!(out.witness.party_ids.len(), committee.threshold + 1); - assert_eq!(out.witness.message.len(), configs.max_msg_non_zero_coeffs); - assert_eq!(out.witness.u_global.len(), configs.max_msg_non_zero_coeffs); + assert_eq!(out.inputs.decryption_shares.len(), committee.threshold + 1); + assert_eq!(out.inputs.party_ids.len(), committee.threshold + 1); + assert_eq!(out.inputs.message.len(), configs.max_msg_non_zero_coeffs); + assert_eq!(out.inputs.u_global.len(), configs.max_msg_non_zero_coeffs); assert!(out.bits.noise_bit > 0); } } diff --git a/crates/zk-helpers/src/circuits/threshold/decrypted_shares_aggregation/mod.rs b/crates/zk-helpers/src/circuits/threshold/decrypted_shares_aggregation/mod.rs index 0ffa414de5..15d3a571d2 100644 --- a/crates/zk-helpers/src/circuits/threshold/decrypted_shares_aggregation/mod.rs +++ b/crates/zk-helpers/src/circuits/threshold/decrypted_shares_aggregation/mod.rs @@ -8,7 +8,7 @@ //! //! Proves correct aggregation of T+1 decryption shares (Lagrange interpolation at 0 per modulus, //! CRT reconstruction to u_global, and CRT quotients). Input: decryption share polynomials, -//! 1-based party IDs, and the decoded message. Output: witness (decryption_shares, party_ids, +//! 1-based party IDs, and the decoded message. Output: input (decryption_shares, party_ids, //! message, u_global, crt_quotients) in standard form for the Noir circuit. pub mod circuit; 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 2e55192036..82c563fc89 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 @@ -8,7 +8,7 @@ //! //! Produces TRBFV parties with secret/public key shares, collects and aggregates shares, //! encrypts a message, computes T+1 decryption shares, and decrypts to obtain the message. -//! The result is used as input for witness computation and codegen. +//! The result is used as inputs for computation and codegen. use crate::circuits::computation::Computation; use crate::threshold::decrypted_shares_aggregation::computation::Configs; @@ -268,15 +268,13 @@ impl DecryptedSharesAggregationCircuitInput { mod tests { use crate::{ computation::Computation, - threshold::decrypted_shares_aggregation::{ - DecryptedSharesAggregationCircuitInput, Witness, - }, + threshold::decrypted_shares_aggregation::{DecryptedSharesAggregationCircuitInput, Inputs}, CiphernodesCommitteeSize, }; use e3_fhe_params::BfvPreset; use num_bigint::BigInt; - /// Sample generation and witness computation: output shapes match circuit expectations. + /// Sample generation and input computation: output shapes match circuit expectations. #[test] fn test_generate_sample() { let preset = BfvPreset::InsecureThreshold512; @@ -284,36 +282,36 @@ mod tests { let sample = DecryptedSharesAggregationCircuitInput::generate_sample(preset, committee).unwrap(); - let witness = Witness::compute(preset, &sample).unwrap(); + let inputs = Inputs::compute(preset, &sample).unwrap(); assert_eq!( - witness.decryption_shares.len(), + inputs.decryption_shares.len(), sample.committee.threshold + 1 ); - assert_eq!(witness.party_ids.len(), sample.reconstructing_parties.len()); + assert_eq!(inputs.party_ids.len(), sample.reconstructing_parties.len()); let configs = crate::threshold::decrypted_shares_aggregation::computation::Configs::compute( preset, &(), ) .unwrap(); - assert_eq!(witness.message.len(), configs.max_msg_non_zero_coeffs); + assert_eq!(inputs.message.len(), configs.max_msg_non_zero_coeffs); } - /// Witness message matches sample (ascending order: index 0 = constant term). + /// Input message matches sample (ascending order: index 0 = constant term). #[test] - fn test_witness_message_matches_sample() { + fn test_input_message_matches_sample() { use crate::threshold::decrypted_shares_aggregation::computation::Configs; let preset = BfvPreset::InsecureThreshold512; let committee = CiphernodesCommitteeSize::Small.values(); let sample = DecryptedSharesAggregationCircuitInput::generate_sample(preset, committee).unwrap(); - let witness = Witness::compute(preset, &sample).unwrap(); + let inputs = Inputs::compute(preset, &sample).unwrap(); let configs = Configs::compute(preset, &()).unwrap(); let n = configs.max_msg_non_zero_coeffs; for i in 0..n { let expected = sample.message_vec.get(i).copied().unwrap_or(0); - let w = &witness.message[i]; + let w = &inputs.message[i]; let exp = BigInt::from(expected); assert_eq!(w, &exp, "message coeff {} mismatch", i); } diff --git a/crates/zk-helpers/src/circuits/threshold/decrypted_shares_aggregation/utils.rs b/crates/zk-helpers/src/circuits/threshold/decrypted_shares_aggregation/utils.rs index 0242fd4df7..ab9d75763f 100644 --- a/crates/zk-helpers/src/circuits/threshold/decrypted_shares_aggregation/utils.rs +++ b/crates/zk-helpers/src/circuits/threshold/decrypted_shares_aggregation/utils.rs @@ -9,7 +9,7 @@ //! **Generic BFV math** lives in [`crate::math`] and is re-exported here for convenience. //! **This module** adds only Shamir + scalar CRT helpers: [`lagrange_recover_at_zero`] and //! [`crt_reconstruct`]. Coefficient reduction uses [`e3_polynomial::reduce`] in -//! [`super::computation::Witness::standard_form`]. +//! [`super::computation::Inputs::standard_form`]. use crate::math; use crate::CircuitsErrors; 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 d87c963530..081f5a657e 100644 --- a/crates/zk-helpers/src/circuits/threshold/pk_aggregation/codegen.rs +++ b/crates/zk-helpers/src/circuits/threshold/pk_aggregation/codegen.rs @@ -10,7 +10,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, Witness}; +use crate::threshold::pk_aggregation::computation::{Configs, Inputs}; use crate::threshold::pk_aggregation::PkAggregationCircuitInput; use crate::utils::join_display; use crate::CircuitCodegen; @@ -25,18 +25,18 @@ impl CircuitCodegen for PkAggregationCircuit { type Error = CircuitsErrors; fn codegen(&self, preset: Self::Preset, input: &Self::Input) -> Result { - let witness = Witness::compute(preset, input)?; + let inputs = Inputs::compute(preset, input)?; let configs = Configs::compute(preset, &())?; - let toml = generate_toml(witness)?; + let toml = generate_toml(inputs)?; let configs = generate_configs(preset, &configs); Ok(Artifacts { toml, configs }) } } -pub fn generate_toml(witness: Witness) -> Result { - let json = witness +pub fn generate_toml(inputs: Inputs) -> Result { + let json = inputs .to_json() .map_err(|e| CircuitsErrors::SerdeJson(e))?; @@ -88,12 +88,12 @@ mod tests { let prefix: &str = ::PREFIX; let sample = PkAggregationCircuitInput::generate_sample(preset, committee).unwrap(); - let witness = Witness::compute(preset, &sample).unwrap(); + let inputs = Inputs::compute(preset, &sample).unwrap(); let configs = Configs::compute(preset, &()).unwrap(); let qis_str = join_display(&configs.moduli, ", "); - let parsed: serde_json::Value = witness.to_json().unwrap(); + let parsed: serde_json::Value = inputs.to_json().unwrap(); let pk0 = parsed .get("pk0") .and_then(|value| value.as_array()) @@ -115,7 +115,7 @@ mod tests { assert!(!pk0_agg.is_empty()); assert!(!pk1_agg.is_empty()); - let codegen_toml = generate_toml(witness).unwrap(); + let codegen_toml = generate_toml(inputs).unwrap(); let codegen_configs = generate_configs(preset, &configs); assert!(codegen_toml.contains("pk0")); 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 f2cd4584dc..61e8e2d7df 100644 --- a/crates/zk-helpers/src/circuits/threshold/pk_aggregation/computation.rs +++ b/crates/zk-helpers/src/circuits/threshold/pk_aggregation/computation.rs @@ -4,10 +4,10 @@ // without even the implied warranty of MERCHANTABILITY // or FITNESS FOR A PARTICULAR PURPOSE. -//! Computation types for the public key aggregation circuit: constants, bounds, bit widths, and witness. +//! Computation types for the public key aggregation circuit: constants, bounds, bit widths, and input. //! -//! [`Configs`], [`Bounds`], [`Bits`], and [`Witness`] are produced from BFV parameters -//! and (for witness) public key shares and aggregated public key. They implement [`Computation`] and are used by codegen. +//! [`Configs`], [`Bounds`], [`Bits`], and [`Inputs`] are produced from BFV parameters +//! and (for input) public key shares and aggregated public key. They implement [`Computation`] and are used by codegen. use crate::bigint_1d_to_json_values; use crate::compute_modulus_bit; @@ -25,12 +25,12 @@ use num_bigint::BigInt; use num_bigint::BigUint; use serde::{Deserialize, Serialize}; -/// Output of [`CircuitComputation::compute`] for [`PkAggregationCircuit`]: bounds, bit widths, and witness. +/// Output of [`CircuitComputation::compute`] for [`PkAggregationCircuit`]: bounds, bit widths, and input. #[derive(Debug)] pub struct PkAggregationComputationOutput { pub bounds: Bounds, pub bits: Bits, - pub witness: Witness, + pub inputs: Inputs, } /// Implementation of [`CircuitComputation`] for [`PkAggregationCircuit`]. @@ -43,12 +43,12 @@ impl CircuitComputation for PkAggregationCircuit { fn compute(preset: Self::Preset, input: &Self::Input) -> Result { let bounds = Bounds::compute(preset, &())?; let bits = Bits::compute(preset, &())?; - let witness = Witness::compute(preset, &input)?; + let inputs = Inputs::compute(preset, &input)?; Ok(PkAggregationComputationOutput { bounds, bits, - witness, + inputs, }) } } @@ -73,7 +73,7 @@ pub struct Bounds { } #[derive(Debug, Clone, Serialize, Deserialize)] -pub struct Witness { +pub struct Inputs { pub expected_threshold_pk_commitments: Vec, pub pk0: Vec, pub pk1: Vec, @@ -147,7 +147,7 @@ impl Computation for Bounds { } } -impl Computation for Witness { +impl Computation for Inputs { type Preset = BfvPreset; type Input = PkAggregationCircuitInput; type Error = CircuitsErrors; @@ -200,7 +200,7 @@ impl Computation for Witness { expected_threshold_pk_commitments.push(commitment); } - Ok(Witness { + Ok(Inputs { expected_threshold_pk_commitments, pk0, pk1, 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 e0ea142094..d0c28d86d9 100644 --- a/crates/zk-helpers/src/circuits/threshold/pk_aggregation/sample.rs +++ b/crates/zk-helpers/src/circuits/threshold/pk_aggregation/sample.rs @@ -75,7 +75,7 @@ mod tests { use crate::{ computation::Computation, threshold::pk_aggregation::computation::Configs, - threshold::pk_aggregation::{PkAggregationCircuitInput, Witness}, + threshold::pk_aggregation::{Inputs, PkAggregationCircuitInput}, CiphernodesCommitteeSize, }; @@ -88,11 +88,11 @@ mod tests { let configs = Configs::compute(preset, &()).unwrap(); let sample = PkAggregationCircuitInput::generate_sample(preset, committee).unwrap(); - let witness = Witness::compute(preset, &sample).unwrap(); + let inputs = Inputs::compute(preset, &sample).unwrap(); - assert_eq!(witness.pk0.len(), sample.committee.h); - assert_eq!(witness.pk1.len(), sample.committee.h); - assert_eq!(witness.pk0_agg.limbs.len(), configs.l); - assert_eq!(witness.pk1_agg.limbs.len(), configs.l); + assert_eq!(inputs.pk0.len(), sample.committee.h); + assert_eq!(inputs.pk1.len(), sample.committee.h); + assert_eq!(inputs.pk0_agg.limbs.len(), configs.l); + assert_eq!(inputs.pk1_agg.limbs.len(), configs.l); } } 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 abf295203e..a37e51e195 100644 --- a/crates/zk-helpers/src/circuits/threshold/pk_generation/codegen.rs +++ b/crates/zk-helpers/src/circuits/threshold/pk_generation/codegen.rs @@ -10,7 +10,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, Witness}; +use crate::threshold::pk_generation::computation::{Configs, Inputs}; use crate::threshold::pk_generation::PkGenerationCircuitInput; use crate::utils::join_display; use crate::CircuitCodegen; @@ -25,18 +25,18 @@ impl CircuitCodegen for PkGenerationCircuit { type Error = CircuitsErrors; fn codegen(&self, preset: Self::Preset, input: &Self::Input) -> Result { - let witness = Witness::compute(preset, input)?; + let inputs = Inputs::compute(preset, input)?; let configs = Configs::compute(preset, &input.committee)?; - let toml = generate_toml(witness)?; + let toml = generate_toml(inputs)?; let configs = generate_configs(preset, &configs); Ok(Artifacts { toml, configs }) } } -pub fn generate_toml(witness: Witness) -> Result { - let json = witness +pub fn generate_toml(inputs: Inputs) -> Result { + let json = inputs .to_json() .map_err(|e| CircuitsErrors::SerdeJson(e))?; 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 ed5356cdbf..3fcc7f7d03 100644 --- a/crates/zk-helpers/src/circuits/threshold/pk_generation/computation.rs +++ b/crates/zk-helpers/src/circuits/threshold/pk_generation/computation.rs @@ -4,10 +4,10 @@ // without even the implied warranty of MERCHANTABILITY // or FITNESS FOR A PARTICULAR PURPOSE. -//! Computation types for the public key generation circuit: constants, bounds, bit widths, and witness. +//! Computation types for the public key generation circuit: constants, bounds, bit widths, and inputs. //! -//! [`Configs`], [`Bounds`], [`Bits`], and [`Witness`] are produced from BFV parameters -//! and (for witness) a public key. They implement [`Computation`] and are used by codegen. +//! [`Configs`], [`Bounds`], [`Bits`], and [`Inputs`] are produced from BFV parameters +//! and (for input) a public key. They implement [`Computation`] and are used by codegen. use crate::calculate_bit_width; use crate::crt_polynomial_to_toml_json; @@ -34,12 +34,12 @@ use rayon::iter::ParallelBridge; use rayon::iter::ParallelIterator; use serde::{Deserialize, Serialize}; -/// Output of [`CircuitComputation::compute`] for [`PkGenerationCircuit`]: bounds, bit widths, and witness. +/// Output of [`CircuitComputation::compute`] for [`PkGenerationCircuit`]: bounds, bit widths, and input. #[derive(Debug)] pub struct PkGenerationComputationOutput { pub bounds: Bounds, pub bits: Bits, - pub witness: Witness, + pub inputs: Inputs, } /// Implementation of [`CircuitComputation`] for [`PkGenerationCircuit`]. @@ -52,12 +52,12 @@ impl CircuitComputation for PkGenerationCircuit { fn compute(preset: Self::Preset, input: &Self::Input) -> Result { let bounds = Bounds::compute(preset, &input.committee)?; let bits = Bits::compute(preset, &bounds)?; - let witness = Witness::compute(preset, input)?; + let inputs = Inputs::compute(preset, input)?; Ok(PkGenerationComputationOutput { bounds, bits, - witness, + inputs, }) } } @@ -92,7 +92,7 @@ pub struct Bounds { } #[derive(Debug, Clone, Serialize, Deserialize)] -pub struct Witness { +pub struct Inputs { pub a: CrtPolynomial, pub eek: Polynomial, pub sk: Polynomial, @@ -239,7 +239,7 @@ impl Computation for Bounds { } } -impl Computation for Witness { +impl Computation for Inputs { type Preset = BfvPreset; type Input = PkGenerationCircuitInput; type Error = CircuitsErrors; @@ -346,7 +346,7 @@ impl Computation for Witness { eek.reduce(zkp_modulus); sk.reduce(zkp_modulus); - Ok(Witness { + Ok(Inputs { a: a.clone(), eek, sk, 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 315209b937..6950a65367 100644 --- a/crates/zk-helpers/src/circuits/threshold/pk_generation/sample.rs +++ b/crates/zk-helpers/src/circuits/threshold/pk_generation/sample.rs @@ -83,7 +83,7 @@ impl PkGenerationCircuitInput { mod tests { use crate::{ computation::Computation, - threshold::pk_generation::{PkGenerationCircuitInput, Witness}, + threshold::pk_generation::{Inputs, PkGenerationCircuitInput}, CiphernodesCommitteeSize, }; @@ -95,12 +95,12 @@ mod tests { let sample = PkGenerationCircuitInput::generate_sample(BfvPreset::InsecureThreshold512, committee) .unwrap(); - let witness = Witness::compute(BfvPreset::InsecureThreshold512, &sample).unwrap(); + let inputs = Inputs::compute(BfvPreset::InsecureThreshold512, &sample).unwrap(); - assert_eq!(witness.pk0is.limbs.len(), 2); - assert_eq!(witness.a.limbs.len(), 2); - assert_eq!(witness.e_sm.limbs.len(), 2); - assert_eq!(witness.r1is.limbs.len(), 2); - assert_eq!(witness.r2is.limbs.len(), 2); + assert_eq!(inputs.pk0is.limbs.len(), 2); + assert_eq!(inputs.a.limbs.len(), 2); + assert_eq!(inputs.e_sm.limbs.len(), 2); + assert_eq!(inputs.r1is.limbs.len(), 2); + assert_eq!(inputs.r2is.limbs.len(), 2); } } 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 280ff7f033..bbb3be2e33 100644 --- a/crates/zk-helpers/src/circuits/threshold/share_decryption/codegen.rs +++ b/crates/zk-helpers/src/circuits/threshold/share_decryption/codegen.rs @@ -7,7 +7,7 @@ //! Code generation for the threshold share decryption circuit: Prover.toml and configs.nr. use crate::circuits::computation::Computation; -use crate::threshold::share_decryption::computation::Witness; +use crate::threshold::share_decryption::computation::Inputs; use crate::threshold::share_decryption::{ Configs, ShareDecryptionCircuit, ShareDecryptionCircuitInput, }; @@ -26,18 +26,18 @@ impl CircuitCodegen for ShareDecryptionCircuit { type Error = CircuitsErrors; fn codegen(&self, preset: Self::Preset, input: &Self::Input) -> Result { - let witness = Witness::compute(preset, input)?; + let inputs = Inputs::compute(preset, input)?; let configs = Configs::compute(preset, &())?; - let toml = generate_toml(witness)?; + let toml = generate_toml(inputs)?; let configs = generate_configs(preset, &configs); Ok(Artifacts { toml, configs }) } } -pub fn generate_toml(witness: Witness) -> Result { - let json = witness +pub fn generate_toml(inputs: Inputs) -> Result { + let json = inputs .to_json() .map_err(|e| CircuitsErrors::SerdeJson(e))?; 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 5bae8c0b22..412278306d 100644 --- a/crates/zk-helpers/src/circuits/threshold/share_decryption/computation.rs +++ b/crates/zk-helpers/src/circuits/threshold/share_decryption/computation.rs @@ -4,10 +4,10 @@ // without even the implied warranty of MERCHANTABILITY // or FITNESS FOR A PARTICULAR PURPOSE. -//! Computation types for the threshold share decryption circuit: constants, bounds, bit widths, and witness. +//! Computation types for the threshold share decryption circuit: constants, bounds, bit widths, and inputs. //! -//! [`Configs`], [`Bounds`], [`Bits`], and [`Witness`] are produced from BFV parameters -//! and (for witness) ciphertext plus aggregated shares (s, e, d_share). They implement +//! [`Configs`], [`Bounds`], [`Bits`], and [`Inputs`] are produced from BFV parameters +//! and (for input) ciphertext plus aggregated shares (s, e, d_share). They implement //! [`Computation`] and are used by codegen. use crate::calculate_bit_width; @@ -32,12 +32,12 @@ use rayon::iter::ParallelBridge; use rayon::iter::ParallelIterator; use serde::{Deserialize, Serialize}; -/// Output of [`CircuitComputation::compute`] for [`ShareDecryptionCircuit`]: bounds, bit widths, and witness. +/// Output of [`CircuitComputation::compute`] for [`ShareDecryptionCircuit`]: bounds, bit widths, and inputs. #[derive(Debug)] pub struct ShareDecryptionComputationOutput { pub bounds: Bounds, pub bits: Bits, - pub witness: Witness, + pub inputs: Inputs, } /// Implementation of [`CircuitComputation`] for [`ShareDecryptionCircuit`]. @@ -50,12 +50,12 @@ impl CircuitComputation for ShareDecryptionCircuit { fn compute(preset: Self::Preset, input: &Self::Input) -> Result { let bounds = Bounds::compute(preset, &())?; let bits = Bits::compute(preset, &bounds)?; - let witness = Witness::compute(preset, input)?; + let inputs = Inputs::compute(preset, input)?; Ok(ShareDecryptionComputationOutput { bounds, bits, - witness, + inputs, }) } } @@ -86,7 +86,7 @@ pub struct Bounds { } #[derive(Debug, Clone, Serialize, Deserialize)] -pub struct Witness { +pub struct Inputs { pub ct0: CrtPolynomial, pub ct1: CrtPolynomial, pub sk: CrtPolynomial, @@ -202,7 +202,7 @@ impl Computation for Bounds { } } -impl Computation for Witness { +impl Computation for Inputs { type Preset = BfvPreset; type Input = ShareDecryptionCircuitInput; type Error = CircuitsErrors; @@ -322,7 +322,7 @@ impl Computation for Witness { let expected_sk_commitment = compute_aggregated_shares_commitment(&sk, modulus_bit); let expected_e_sm_commitment = compute_aggregated_shares_commitment(&e_sm, modulus_bit); - Ok(Witness { + Ok(Inputs { ct0, ct1, sk, 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 8a27945c2b..bf6b997950 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 @@ -8,7 +8,7 @@ use crate::circuits::computation::Computation; use crate::threshold::user_data_encryption::circuit::UserDataEncryptionCircuit; -use crate::threshold::user_data_encryption::computation::{Configs, Witness}; +use crate::threshold::user_data_encryption::computation::{Configs, Inputs}; use crate::threshold::user_data_encryption::UserDataEncryptionCircuitInput; use crate::utils::join_display; use crate::Circuit; @@ -27,10 +27,10 @@ impl CircuitCodegen for UserDataEncryptionCircuit { type Error = CircuitsErrors; fn codegen(&self, preset: Self::Preset, input: &Self::Input) -> Result { - let witness = Witness::compute(preset, input)?; + let inputs = Inputs::compute(preset, input)?; let configs = Configs::compute(preset, &())?; - let toml = generate_toml(witness)?; + let toml = generate_toml(inputs)?; let configs = generate_configs(preset, &configs); Ok(Artifacts { toml, configs }) @@ -56,8 +56,8 @@ pub struct TomlJson { pub pk_commitment: String, } -pub fn generate_toml(witness: Witness) -> Result { - let json = witness +pub fn generate_toml(inputs: Inputs) -> Result { + let json = inputs .to_json() .map_err(|e| CircuitsErrors::SerdeJson(e))?; 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 8c22e94d1e..4efb9ea5b4 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 @@ -4,10 +4,10 @@ // without even the implied warranty of MERCHANTABILITY // or FITNESS FOR A PARTICULAR PURPOSE. -//! Computation types for the user data encryption circuit: constants, bounds, bit widths, and witness. +//! Computation types for the user data encryption circuit: constants, bounds, bit widths, and inputs. //! -//! [`Configs`], [`Bounds`], [`Bits`], and [`Witness`] are produced from BFV parameters -//! and (for witness) a public key. They implement [`Computation`] and are used by codegen. +//! [`Configs`], [`Bounds`], [`Bits`], and [`Inputs`] are produced from BFV parameters +//! and (for input) a public key. They implement [`Computation`] and are used by codegen. use crate::calculate_bit_width; use crate::commitments::compute_pk_aggregation_commitment; @@ -45,12 +45,12 @@ use rayon::prelude::ParallelBridge; use serde::{Deserialize, Serialize}; use std::ops::Deref; -/// Output of [`CircuitComputation::compute`] for [`UserDataEncryptionCircuit`]: bounds, bit widths, and witness. +/// Output of [`CircuitComputation::compute`] for [`UserDataEncryptionCircuit`]: bounds, bit widths, and inputs. #[derive(Debug)] pub struct UserDataEncryptionComputationOutput { pub bounds: Bounds, pub bits: Bits, - pub witness: Witness, + pub inputs: Inputs, } /// Implementation of [`CircuitComputation`] for [`UserDataEncryptionCircuit`]. @@ -63,12 +63,12 @@ impl CircuitComputation for UserDataEncryptionCircuit { fn compute(preset: Self::Preset, input: &Self::Input) -> Result { let bounds = Bounds::compute(preset, &())?; let bits = Bits::compute(preset, &bounds)?; - let witness = Witness::compute(preset, input)?; + let inputs = Inputs::compute(preset, input)?; Ok(UserDataEncryptionComputationOutput { bounds, bits, - witness, + inputs, }) } } @@ -114,7 +114,7 @@ pub struct Bounds { } #[derive(Debug, Clone, Serialize, Deserialize)] -pub struct Witness { +pub struct Inputs { pub pk0is: CrtPolynomial, pub pk1is: CrtPolynomial, pub ct0is: CrtPolynomial, @@ -352,7 +352,7 @@ impl Computation for Bounds { } } -impl Computation for Witness { +impl Computation for Inputs { type Preset = BfvPreset; type Input = UserDataEncryptionCircuitInput; type Error = CircuitsErrors; @@ -693,7 +693,7 @@ impl Computation for Witness { let pk_commitment = compute_pk_aggregation_commitment(&pk0is, &pk1is, pk_bit); let ct_commitment = compute_ciphertext_commitment(&ct0is, &ct1is, pk_bit); - Ok(Witness { + Ok(Inputs { pk0is, pk1is, ct0is, @@ -714,7 +714,7 @@ impl Computation for Witness { }) } - // Used as witness for Nargo execution. + // Used as input for Nargo execution. fn to_json(&self) -> serde_json::Result { let pk0is = crt_polynomial_to_toml_json(&self.pk0is); let pk1is = crt_polynomial_to_toml_json(&self.pk1is); 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 76718258a1..e668b932fc 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 @@ -163,7 +163,7 @@ pub fn compute_ciphertext_commitment( mod tests { use super::*; use crate::circuits::computation::Computation; - use crate::threshold::user_data_encryption::computation::Witness; + use crate::threshold::user_data_encryption::computation::Inputs; use crate::threshold::user_data_encryption::UserDataEncryptionCircuitInput; use e3_fhe_params::{build_pair_for_preset, BfvPreset}; use fhe_traits::DeserializeParametrized; @@ -175,15 +175,15 @@ mod tests { UserDataEncryptionCircuitInput::generate_sample(BfvPreset::InsecureThreshold512) .unwrap(); - let witness = Witness::compute(BfvPreset::InsecureThreshold512, &sample).unwrap(); + let inputs = Inputs::compute(BfvPreset::InsecureThreshold512, &sample).unwrap(); // Convert using our function let (actual_pk0is, actual_pk1is) = bfv_public_key_to_greco(&threshold_params, &sample.public_key).unwrap(); // Verify the structure matches - assert_eq!(actual_pk0is, witness.pk0is); - assert_eq!(actual_pk1is, witness.pk1is); + assert_eq!(actual_pk0is, inputs.pk0is); + assert_eq!(actual_pk1is, inputs.pk1is); } #[test] @@ -194,16 +194,16 @@ mod tests { UserDataEncryptionCircuitInput::generate_sample(BfvPreset::InsecureThreshold512) .unwrap(); - let witness = Witness::compute(BfvPreset::InsecureThreshold512, &sample).unwrap(); + let inputs = Inputs::compute(BfvPreset::InsecureThreshold512, &sample).unwrap(); - let ciphertext = Ciphertext::from_bytes(&witness.ciphertext, &threshold_params).unwrap(); + let ciphertext = Ciphertext::from_bytes(&inputs.ciphertext, &threshold_params).unwrap(); // Convert using our function let (actual_ct0is, actual_ct1is) = bfv_ciphertext_to_greco(&threshold_params, &ciphertext).unwrap(); // Verify the structure matches - assert_eq!(actual_ct0is, witness.ct0is); - assert_eq!(actual_ct1is, witness.ct1is); + assert_eq!(actual_ct0is, inputs.ct0is); + assert_eq!(actual_ct1is, inputs.ct1is); } } diff --git a/crates/zk-prover/src/circuits/dkg/pk.rs b/crates/zk-prover/src/circuits/dkg/pk.rs index 37a841f844..b120db2db8 100644 --- a/crates/zk-prover/src/circuits/dkg/pk.rs +++ b/crates/zk-prover/src/circuits/dkg/pk.rs @@ -8,12 +8,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::computation::Witness; +use e3_zk_helpers::circuits::dkg::pk::computation::Inputs; impl Provable for PkCircuit { type Params = BfvPreset; type Input = PkCircuitInput; - type Witness = Witness; + type Inputs = Inputs; fn circuit(&self) -> CircuitName { CircuitName::PkBfv diff --git a/crates/zk-prover/src/circuits/threshold/pk_generation.rs b/crates/zk-prover/src/circuits/threshold/pk_generation.rs index 9408106ca2..ea65c7e539 100644 --- a/crates/zk-prover/src/circuits/threshold/pk_generation.rs +++ b/crates/zk-prover/src/circuits/threshold/pk_generation.rs @@ -10,12 +10,12 @@ use e3_fhe_params::BfvPreset; use e3_zk_helpers::circuits::threshold::pk_generation::circuit::{ PkGenerationCircuit, PkGenerationCircuitInput, }; -use e3_zk_helpers::circuits::threshold::pk_generation::computation::Witness; +use e3_zk_helpers::circuits::threshold::pk_generation::computation::Inputs; impl Provable for PkGenerationCircuit { type Params = BfvPreset; type Input = PkGenerationCircuitInput; - type Witness = Witness; + type Inputs = Inputs; fn circuit(&self) -> CircuitName { CircuitName::PkGeneration diff --git a/crates/zk-prover/src/circuits/utils.rs b/crates/zk-prover/src/circuits/utils.rs index 61db09662a..edaf2010ec 100644 --- a/crates/zk-prover/src/circuits/utils.rs +++ b/crates/zk-prover/src/circuits/utils.rs @@ -10,13 +10,13 @@ use crate::error::ZkError; use acir::FieldElement; use noirc_abi::{input_parser::InputValue, InputMap}; -/// Converts witness JSON (from `Witness::to_json()`) to `InputMap` for Noir ABI. +/// Converts inputs JSON (from `Inputs::to_json()`) to `InputMap` for Noir ABI. /// Expects the same structure: CRT fields as arrays of `{coefficients: [...]}`, /// polynomial fields as `{coefficients: [...]}`. -pub fn witness_json_to_input_map(json: &serde_json::Value) -> Result { +pub fn inputs_json_to_input_map(json: &serde_json::Value) -> Result { let obj = json .as_object() - .ok_or_else(|| ZkError::SerializationError("witness json must be an object".into()))?; + .ok_or_else(|| ZkError::SerializationError("inputs json must be an object".into()))?; let mut inputs = InputMap::new(); for (key, value) in obj { diff --git a/crates/zk-prover/src/error.rs b/crates/zk-prover/src/error.rs index eefdde3e3b..78689d23b2 100644 --- a/crates/zk-prover/src/error.rs +++ b/crates/zk-prover/src/error.rs @@ -57,6 +57,9 @@ pub enum ZkError { #[error("Unsupported platform: {os}-{arch}")] UnsupportedPlatform { os: String, arch: String }, + #[error("Inputs generation failed: {0}")] + InputsGenerationFailed(String), + #[error("Witness generation failed: {0}")] WitnessGenerationFailed(String), diff --git a/crates/zk-prover/src/traits.rs b/crates/zk-prover/src/traits.rs index 9e4e7780f0..117ead32d8 100644 --- a/crates/zk-prover/src/traits.rs +++ b/crates/zk-prover/src/traits.rs @@ -6,7 +6,7 @@ use std::fmt::Display; -use crate::circuits::utils::witness_json_to_input_map; +use crate::circuits::utils::inputs_json_to_input_map; use crate::error::ZkError; use crate::prover::ZkProver; use crate::witness::{CompiledCircuit, WitnessGenerator}; @@ -16,28 +16,29 @@ use noirc_abi::InputMap; /// Trait for types that can generate ZK proofs. /// -/// Implementors specify the circuit, params, input, and witness types. -/// `build_witness`, `prove`, and `verify` use default implementations -/// that compute the witness via [`Computation::compute`] and serialize via +/// Implementors specify the circuit, params, and input types. +/// `build_inputs`, `prove`, and `verify` use default implementations +/// that compute the inputs via [`Computation::compute`] and serialize via /// [`Computation::to_json`]. pub trait Provable: Send + Sync { type Params: Send + Sync + Clone; type Input: Send + Sync; - type Witness; + type Inputs; fn circuit(&self) -> CircuitName; - fn build_witness(&self, params: &Self::Params, input: &Self::Input) -> Result + fn build_inputs(&self, params: &Self::Params, input: &Self::Input) -> Result where - Self::Witness: Computation + serde::Serialize, - ::Error: Display, + Self::Inputs: Computation + serde::Serialize, + ::Error: Display, { - let witness = Self::Witness::compute(params.clone(), input) - .map_err(|e| ZkError::WitnessGenerationFailed(e.to_string()))?; - let json = witness + let inputs = Self::Inputs::compute(params.clone(), input) + .map_err(|e| ZkError::InputsGenerationFailed(e.to_string()))?; + let json = inputs .to_json() .map_err(|e| ZkError::SerializationError(e.to_string()))?; - witness_json_to_input_map(&json) + + inputs_json_to_input_map(&json) } fn prove( @@ -48,10 +49,10 @@ pub trait Provable: Send + Sync { e3_id: &str, ) -> Result where - Self::Witness: Computation + serde::Serialize, - ::Error: Display, + Self::Inputs: Computation + serde::Serialize, + ::Error: Display, { - let inputs = self.build_witness(params, input)?; + let inputs = self.build_inputs(params, input)?; let circuit_name = self.circuit().as_str(); let circuit_path = prover diff --git a/crates/zk-prover/tests/local_e2e_tests.rs b/crates/zk-prover/tests/local_e2e_tests.rs index d914c7f48e..696c96fca4 100644 --- a/crates/zk-prover/tests/local_e2e_tests.rs +++ b/crates/zk-prover/tests/local_e2e_tests.rs @@ -229,16 +229,16 @@ async fn test_pk_generation_commitment_consistency() { // Recompute commitments from the witness let sk_commitment_expected = compute_share_computation_sk_commitment( - &computation_output.witness.sk, + &computation_output.inputs.sk, computation_output.bits.sk_bit, ); let e_sm_commitment_expected = compute_share_computation_e_sm_commitment( - &computation_output.witness.e_sm, + &computation_output.inputs.e_sm, computation_output.bits.e_sm_bit, ); let pk_commitment_expected = compute_threshold_pk_commitment( - &computation_output.witness.pk0is, - &computation_output.witness.pk1is, + &computation_output.inputs.pk0is, + &computation_output.inputs.pk1is, computation_output.bits.pk_bit, ); @@ -282,8 +282,8 @@ async fn test_pk_bfv_commitment_consistency() { let computation_output = PkCircuit::compute(preset, &sample).expect("computation should succeed"); let commitment_calculated = compute_dkg_pk_commitment( - &computation_output.witness.pk0is, - &computation_output.witness.pk1is, + &computation_output.inputs.pk0is, + &computation_output.inputs.pk1is, computation_output.bits.pk_bit, ); diff --git a/examples/CRISP/crates/zk-inputs/src/lib.rs b/examples/CRISP/crates/zk-inputs/src/lib.rs index 16cb1ba7cd..d2424d4104 100644 --- a/examples/CRISP/crates/zk-inputs/src/lib.rs +++ b/examples/CRISP/crates/zk-inputs/src/lib.rs @@ -101,7 +101,7 @@ impl ZKInputsGenerator { )?; let ct = Ciphertext::from_bytes( - &user_data_encryption_computation_output.witness.ciphertext, + &user_data_encryption_computation_output.inputs.ciphertext, &self.bfv_params, ) .with_context(|| "Failed to deserialize ciphertext")?; @@ -121,7 +121,7 @@ impl ZKInputsGenerator { let ciphertext_addition_witness_json = ciphertext_addition_inputs.to_json()?; let user_data_encryption_witness_json = - user_data_encryption_computation_output.witness.to_json()?; + user_data_encryption_computation_output.inputs.to_json()?; let inputs_json = utils::merge_json_objects( ciphertext_addition_witness_json, user_data_encryption_witness_json, @@ -165,7 +165,7 @@ impl ZKInputsGenerator { )?; let ct = Ciphertext::from_bytes( - &user_data_encryption_computation_output.witness.ciphertext, + &user_data_encryption_computation_output.inputs.ciphertext, &self.bfv_params, ) .with_context(|| "Failed to deserialize ciphertext")?; @@ -189,7 +189,7 @@ impl ZKInputsGenerator { let ciphertext_addition_witness_json = ciphertext_addition_inputs.to_json()?; let user_data_encryption_witness_json = - user_data_encryption_computation_output.witness.to_json()?; + user_data_encryption_computation_output.inputs.to_json()?; let inputs_json = utils::merge_json_objects( ciphertext_addition_witness_json, user_data_encryption_witness_json, From cedbb5eca39c811354d9740e02db83c6560f5e5a Mon Sep 17 00:00:00 2001 From: Cedoor Date: Wed, 11 Feb 2026 16:47:52 +0100 Subject: [PATCH 2/2] style: format rust code --- crates/zk-helpers/src/circuits/dkg/pk/codegen.rs | 4 +--- .../src/circuits/dkg/share_computation/codegen.rs | 8 +++----- .../src/circuits/dkg/share_decryption/codegen.rs | 6 ++---- .../src/circuits/dkg/share_encryption/codegen.rs | 6 ++---- .../src/circuits/threshold/pk_aggregation/codegen.rs | 4 +--- .../src/circuits/threshold/pk_generation/codegen.rs | 4 +--- .../src/circuits/threshold/share_decryption/codegen.rs | 4 +--- .../circuits/threshold/user_data_encryption/codegen.rs | 4 +--- 8 files changed, 12 insertions(+), 28 deletions(-) diff --git a/crates/zk-helpers/src/circuits/dkg/pk/codegen.rs b/crates/zk-helpers/src/circuits/dkg/pk/codegen.rs index 3f7be69dcb..bff02c880d 100644 --- a/crates/zk-helpers/src/circuits/dkg/pk/codegen.rs +++ b/crates/zk-helpers/src/circuits/dkg/pk/codegen.rs @@ -38,9 +38,7 @@ impl CircuitCodegen for PkCircuit { /// Builds the Prover TOML string from the pk input (pk0is, pk1is). pub fn generate_toml(inputs: Inputs) -> Result { - let json = inputs - .to_json() - .map_err(|e| CircuitsErrors::SerdeJson(e))?; + let json = inputs.to_json().map_err(|e| CircuitsErrors::SerdeJson(e))?; Ok(toml::to_string(&json)?) } 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 f6c5afb681..5c8479ef8c 100644 --- a/crates/zk-helpers/src/circuits/dkg/share_computation/codegen.rs +++ b/crates/zk-helpers/src/circuits/dkg/share_computation/codegen.rs @@ -9,8 +9,8 @@ use crate::circuits::computation::CircuitComputation; use crate::circuits::computation::Computation; use crate::circuits::dkg::share_computation::{ - utils::parity_matrix_constant_string, Bits, ShareComputationCircuit, - Inputs, ShareComputationCircuitInput, ShareComputationOutput, + utils::parity_matrix_constant_string, Bits, Inputs, ShareComputationCircuit, + ShareComputationCircuitInput, ShareComputationOutput, }; use crate::circuits::{Artifacts, CircuitCodegen, CircuitsErrors, CodegenToml}; use crate::codegen::CodegenConfigs; @@ -48,9 +48,7 @@ pub fn generate_toml( inputs: &Inputs, dkg_input_type: DkgInputType, ) -> Result { - let mut json = inputs - .to_json() - .map_err(|e| CircuitsErrors::SerdeJson(e))?; + let mut json = inputs.to_json().map_err(|e| CircuitsErrors::SerdeJson(e))?; let obj = json.as_object_mut().ok_or(CircuitsErrors::Other( "input json is not an object".to_string(), 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 0e6ca980d8..b1af47b23b 100644 --- a/crates/zk-helpers/src/circuits/dkg/share_decryption/codegen.rs +++ b/crates/zk-helpers/src/circuits/dkg/share_decryption/codegen.rs @@ -8,10 +8,10 @@ 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::ShareDecryptionOutput; -use crate::circuits::dkg::share_decryption::Inputs; use crate::circuits::{Artifacts, CircuitCodegen, CircuitsErrors, CodegenToml}; use crate::codegen::CodegenConfigs; use crate::computation::Computation; @@ -40,9 +40,7 @@ impl CircuitCodegen for ShareDecryptionCircuit { /// Serializes the input to TOML string for the Noir prover (Prover.toml). pub fn generate_toml(inputs: &Inputs) -> Result { - let json = inputs - .to_json() - .map_err(|e| CircuitsErrors::SerdeJson(e))?; + let json = inputs.to_json().map_err(|e| CircuitsErrors::SerdeJson(e))?; Ok(toml::to_string(&json)?) } 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 ee3e1d612b..fc71f9f7e5 100644 --- a/crates/zk-helpers/src/circuits/dkg/share_encryption/codegen.rs +++ b/crates/zk-helpers/src/circuits/dkg/share_encryption/codegen.rs @@ -8,10 +8,10 @@ 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::ShareEncryptionOutput; -use crate::circuits::dkg::share_encryption::Inputs; use crate::circuits::{Artifacts, CircuitCodegen, CircuitsErrors, CodegenToml}; use crate::codegen::CodegenConfigs; use crate::computation::Computation; @@ -41,9 +41,7 @@ impl CircuitCodegen for ShareEncryptionCircuit { /// Serializes the input to TOML string for the Noir prover (Prover.toml). pub fn generate_toml(inputs: &Inputs) -> Result { - let json = inputs - .to_json() - .map_err(|e| CircuitsErrors::SerdeJson(e))?; + let json = inputs.to_json().map_err(|e| CircuitsErrors::SerdeJson(e))?; Ok(toml::to_string(&json)?) } 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 081f5a657e..b29e99c6c3 100644 --- a/crates/zk-helpers/src/circuits/threshold/pk_aggregation/codegen.rs +++ b/crates/zk-helpers/src/circuits/threshold/pk_aggregation/codegen.rs @@ -36,9 +36,7 @@ impl CircuitCodegen for PkAggregationCircuit { } pub fn generate_toml(inputs: Inputs) -> Result { - let json = inputs - .to_json() - .map_err(|e| CircuitsErrors::SerdeJson(e))?; + let json = inputs.to_json().map_err(|e| CircuitsErrors::SerdeJson(e))?; Ok(toml::to_string(&json)?) } 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 a37e51e195..e623c482ff 100644 --- a/crates/zk-helpers/src/circuits/threshold/pk_generation/codegen.rs +++ b/crates/zk-helpers/src/circuits/threshold/pk_generation/codegen.rs @@ -36,9 +36,7 @@ impl CircuitCodegen for PkGenerationCircuit { } pub fn generate_toml(inputs: Inputs) -> Result { - let json = inputs - .to_json() - .map_err(|e| CircuitsErrors::SerdeJson(e))?; + let json = inputs.to_json().map_err(|e| CircuitsErrors::SerdeJson(e))?; Ok(toml::to_string(&json)?) } 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 bbb3be2e33..35d0b399e9 100644 --- a/crates/zk-helpers/src/circuits/threshold/share_decryption/codegen.rs +++ b/crates/zk-helpers/src/circuits/threshold/share_decryption/codegen.rs @@ -37,9 +37,7 @@ impl CircuitCodegen for ShareDecryptionCircuit { } pub fn generate_toml(inputs: Inputs) -> Result { - let json = inputs - .to_json() - .map_err(|e| CircuitsErrors::SerdeJson(e))?; + let json = inputs.to_json().map_err(|e| CircuitsErrors::SerdeJson(e))?; Ok(toml::to_string(&json)?) } 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 bf6b997950..4b60bc9352 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 @@ -57,9 +57,7 @@ pub struct TomlJson { } pub fn generate_toml(inputs: Inputs) -> Result { - let json = inputs - .to_json() - .map_err(|e| CircuitsErrors::SerdeJson(e))?; + let json = inputs.to_json().map_err(|e| CircuitsErrors::SerdeJson(e))?; Ok(toml::to_string(&json)?) }