From 78a2c7d64dbdd945ed271b5802c680c25fcdecd7 Mon Sep 17 00:00:00 2001 From: Zara Date: Tue, 27 Jan 2026 18:03:50 -0800 Subject: [PATCH] changed L to L_PRIME in enc_bfv --- .../bin/insecure/enc_bfv_e_sm/src/main.nr | 24 ++--- circuits/bin/insecure/enc_bfv_sk/src/main.nr | 24 ++--- .../bin/production/enc_bfv_e_sm/src/main.nr | 24 ++--- .../bin/production/enc_bfv_sk/src/main.nr | 24 ++--- circuits/lib/src/core/bfv_enc.nr | 98 +++++++++---------- 5 files changed, 97 insertions(+), 97 deletions(-) diff --git a/circuits/bin/insecure/enc_bfv_e_sm/src/main.nr b/circuits/bin/insecure/enc_bfv_e_sm/src/main.nr index 43ca54689a..9353e4bbde 100644 --- a/circuits/bin/insecure/enc_bfv_e_sm/src/main.nr +++ b/circuits/bin/insecure/enc_bfv_e_sm/src/main.nr @@ -6,7 +6,7 @@ use lib::configs::insecure::bfv::{ ENC_BFV_BIT_CT, ENC_BFV_BIT_E0, ENC_BFV_BIT_E1, ENC_BFV_BIT_MSG, ENC_BFV_BIT_P1, ENC_BFV_BIT_P2, - ENC_BFV_BIT_PK, ENC_BFV_BIT_R1, ENC_BFV_BIT_R2, ENC_BFV_BIT_U, ENC_BFV_CONFIGS_E_SM, L, N, + ENC_BFV_BIT_PK, ENC_BFV_BIT_R1, ENC_BFV_BIT_R2, ENC_BFV_BIT_U, ENC_BFV_CONFIGS_E_SM, L_PRIME, N, }; use lib::core::bfv_enc::EncryptionBfv; use lib::math::polynomial::Polynomial; @@ -14,22 +14,22 @@ use lib::math::polynomial::Polynomial; fn main( expected_pk_commitment: pub Field, expected_message_commitment: pub Field, - pk0is: [Polynomial; L], - pk1is: [Polynomial; L], - ct0is: pub [Polynomial; L], - ct1is: pub [Polynomial; L], + pk0is: [Polynomial; L_PRIME], + pk1is: [Polynomial; L_PRIME], + ct0is: pub [Polynomial; L_PRIME], + ct1is: pub [Polynomial; L_PRIME], u: Polynomial, e0: Polynomial, - e0is: [Polynomial; L], - e0_quotients: [Polynomial; L], + e0is: [Polynomial; L_PRIME], + e0_quotients: [Polynomial; L_PRIME], e1: Polynomial, message: Polynomial, - r1is: [Polynomial<(2 * N) - 1>; L], - r2is: [Polynomial; L], - p1is: [Polynomial<(2 * N) - 1>; L], - p2is: [Polynomial; L], + r1is: [Polynomial<(2 * N) - 1>; L_PRIME], + r2is: [Polynomial; L_PRIME], + p1is: [Polynomial<(2 * N) - 1>; L_PRIME], + p2is: [Polynomial; L_PRIME], ) { - let enc_bfv: EncryptionBfv = EncryptionBfv::new( + let enc_bfv: EncryptionBfv = EncryptionBfv::new( ENC_BFV_CONFIGS_E_SM, expected_pk_commitment, expected_message_commitment, diff --git a/circuits/bin/insecure/enc_bfv_sk/src/main.nr b/circuits/bin/insecure/enc_bfv_sk/src/main.nr index 11d4ed60e7..45585824bb 100644 --- a/circuits/bin/insecure/enc_bfv_sk/src/main.nr +++ b/circuits/bin/insecure/enc_bfv_sk/src/main.nr @@ -6,7 +6,7 @@ use lib::configs::insecure::bfv::{ ENC_BFV_BIT_CT, ENC_BFV_BIT_E0, ENC_BFV_BIT_E1, ENC_BFV_BIT_MSG, ENC_BFV_BIT_P1, ENC_BFV_BIT_P2, - ENC_BFV_BIT_PK, ENC_BFV_BIT_R1, ENC_BFV_BIT_R2, ENC_BFV_BIT_U, ENC_BFV_CONFIGS_SK, L, N, + ENC_BFV_BIT_PK, ENC_BFV_BIT_R1, ENC_BFV_BIT_R2, ENC_BFV_BIT_U, ENC_BFV_CONFIGS_SK, L_PRIME, N, }; use lib::core::bfv_enc::EncryptionBfv; use lib::math::polynomial::Polynomial; @@ -14,22 +14,22 @@ use lib::math::polynomial::Polynomial; fn main( expected_pk_commitment: pub Field, expected_message_commitment: pub Field, - pk0is: [Polynomial; L], - pk1is: [Polynomial; L], - ct0is: pub [Polynomial; L], - ct1is: pub [Polynomial; L], + pk0is: [Polynomial; L_PRIME], + pk1is: [Polynomial; L_PRIME], + ct0is: pub [Polynomial; L_PRIME], + ct1is: pub [Polynomial; L_PRIME], u: Polynomial, e0: Polynomial, - e0is: [Polynomial; L], - e0_quotients: [Polynomial; L], + e0is: [Polynomial; L_PRIME], + e0_quotients: [Polynomial; L_PRIME], e1: Polynomial, message: Polynomial, - r1is: [Polynomial<(2 * N) - 1>; L], - r2is: [Polynomial; L], - p1is: [Polynomial<(2 * N) - 1>; L], - p2is: [Polynomial; L], + r1is: [Polynomial<(2 * N) - 1>; L_PRIME], + r2is: [Polynomial; L_PRIME], + p1is: [Polynomial<(2 * N) - 1>; L_PRIME], + p2is: [Polynomial; L_PRIME], ) { - let enc_bfv: EncryptionBfv = EncryptionBfv::new( + let enc_bfv: EncryptionBfv = EncryptionBfv::new( ENC_BFV_CONFIGS_SK, expected_pk_commitment, expected_message_commitment, diff --git a/circuits/bin/production/enc_bfv_e_sm/src/main.nr b/circuits/bin/production/enc_bfv_e_sm/src/main.nr index dd2b492cb7..60712540da 100644 --- a/circuits/bin/production/enc_bfv_e_sm/src/main.nr +++ b/circuits/bin/production/enc_bfv_e_sm/src/main.nr @@ -6,7 +6,7 @@ use lib::configs::production::bfv::{ ENC_BFV_BIT_CT, ENC_BFV_BIT_E0, ENC_BFV_BIT_E1, ENC_BFV_BIT_MSG, ENC_BFV_BIT_P1, ENC_BFV_BIT_P2, - ENC_BFV_BIT_PK, ENC_BFV_BIT_R1, ENC_BFV_BIT_R2, ENC_BFV_BIT_U, ENC_BFV_CONFIGS_E_SM, L, N, + ENC_BFV_BIT_PK, ENC_BFV_BIT_R1, ENC_BFV_BIT_R2, ENC_BFV_BIT_U, ENC_BFV_CONFIGS_E_SM, L_PRIME, N, }; use lib::core::bfv_enc::EncryptionBfv; use lib::math::polynomial::Polynomial; @@ -14,22 +14,22 @@ use lib::math::polynomial::Polynomial; fn main( expected_pk_commitment: pub Field, expected_message_commitment: pub Field, - pk0is: [Polynomial; L], - pk1is: [Polynomial; L], - ct0is: pub [Polynomial; L], - ct1is: pub [Polynomial; L], + pk0is: [Polynomial; L_PRIME], + pk1is: [Polynomial; L_PRIME], + ct0is: pub [Polynomial; L_PRIME], + ct1is: pub [Polynomial; L_PRIME], u: Polynomial, e0: Polynomial, - e0is: [Polynomial; L], - e0_quotients: [Polynomial; L], + e0is: [Polynomial; L_PRIME], + e0_quotients: [Polynomial; L_PRIME], e1: Polynomial, message: Polynomial, - r1is: [Polynomial<(2 * N) - 1>; L], - r2is: [Polynomial; L], - p1is: [Polynomial<(2 * N) - 1>; L], - p2is: [Polynomial; L], + r1is: [Polynomial<(2 * N) - 1>; L_PRIME], + r2is: [Polynomial; L_PRIME], + p1is: [Polynomial<(2 * N) - 1>; L_PRIME], + p2is: [Polynomial; L_PRIME], ) { - let enc_bfv: EncryptionBfv = EncryptionBfv::new( + let enc_bfv: EncryptionBfv = EncryptionBfv::new( ENC_BFV_CONFIGS_E_SM, expected_pk_commitment, expected_message_commitment, diff --git a/circuits/bin/production/enc_bfv_sk/src/main.nr b/circuits/bin/production/enc_bfv_sk/src/main.nr index c290b8b2a1..4341e91d95 100644 --- a/circuits/bin/production/enc_bfv_sk/src/main.nr +++ b/circuits/bin/production/enc_bfv_sk/src/main.nr @@ -6,7 +6,7 @@ use lib::configs::production::bfv::{ ENC_BFV_BIT_CT, ENC_BFV_BIT_E0, ENC_BFV_BIT_E1, ENC_BFV_BIT_MSG, ENC_BFV_BIT_P1, ENC_BFV_BIT_P2, - ENC_BFV_BIT_PK, ENC_BFV_BIT_R1, ENC_BFV_BIT_R2, ENC_BFV_BIT_U, ENC_BFV_CONFIGS_SK, L, N, + ENC_BFV_BIT_PK, ENC_BFV_BIT_R1, ENC_BFV_BIT_R2, ENC_BFV_BIT_U, ENC_BFV_CONFIGS_SK, L_PRIME, N, }; use lib::core::bfv_enc::EncryptionBfv; use lib::math::polynomial::Polynomial; @@ -14,22 +14,22 @@ use lib::math::polynomial::Polynomial; fn main( expected_pk_commitment: pub Field, expected_message_commitment: pub Field, - pk0is: [Polynomial; L], - pk1is: [Polynomial; L], - ct0is: pub [Polynomial; L], - ct1is: pub [Polynomial; L], + pk0is: [Polynomial; L_PRIME], + pk1is: [Polynomial; L_PRIME], + ct0is: pub [Polynomial; L_PRIME], + ct1is: pub [Polynomial; L_PRIME], u: Polynomial, e0: Polynomial, - e0is: [Polynomial; L], - e0_quotients: [Polynomial; L], + e0is: [Polynomial; L_PRIME], + e0_quotients: [Polynomial; L_PRIME], e1: Polynomial, message: Polynomial, - r1is: [Polynomial<(2 * N) - 1>; L], - r2is: [Polynomial; L], - p1is: [Polynomial<(2 * N) - 1>; L], - p2is: [Polynomial; L], + r1is: [Polynomial<(2 * N) - 1>; L_PRIME], + r2is: [Polynomial; L_PRIME], + p1is: [Polynomial<(2 * N) - 1>; L_PRIME], + p2is: [Polynomial; L_PRIME], ) { - let enc_bfv: EncryptionBfv = EncryptionBfv::new( + let enc_bfv: EncryptionBfv = EncryptionBfv::new( ENC_BFV_CONFIGS_SK, expected_pk_commitment, expected_message_commitment, diff --git a/circuits/lib/src/core/bfv_enc.nr b/circuits/lib/src/core/bfv_enc.nr index 354f65ce8c..e2ec2375d8 100644 --- a/circuits/lib/src/core/bfv_enc.nr +++ b/circuits/lib/src/core/bfv_enc.nr @@ -12,17 +12,17 @@ use crate::math::modulo::U128::ModU128; use crate::math::polynomial::Polynomial; /// Cryptographic parameters for BFV encryption circuit. -pub struct Configs { +pub struct Configs { /// Plaintext modulus t pub t: Field, /// Q mod t (for scaling message) pub q_mod_t: Field, /// CRT moduli for each basis: [q_0, q_1, ..., q_{L-1}] - pub qis: [Field; L], + pub qis: [Field; L_PRIME], /// Scaling factors for each basis: [k0_0, k0_1, ..., k0_{L-1}] - pub k0is: [Field; L], + pub k0is: [Field; L_PRIME], /// Bounds for public key polynomials for each CRT basis - pub pk_bounds: [Field; L], + pub pk_bounds: [Field; L_PRIME], /// Bounds for error polynomials (e0) pub e0_bound: Field, /// Bounds for error polynomials (e1) @@ -30,34 +30,34 @@ pub struct Configs { /// Bound for secret polynomial u (ternary distribution) pub u_bound: Field, /// Lower bounds for r1 polynomials (modulus switching quotients) - pub r1_low_bounds: [Field; L], + pub r1_low_bounds: [Field; L_PRIME], /// Upper bounds for r1 polynomials (modulus switching quotients) - pub r1_up_bounds: [Field; L], + pub r1_up_bounds: [Field; L_PRIME], /// Bounds for r2 polynomials (cyclotomic reduction quotients) - pub r2_bounds: [Field; L], + pub r2_bounds: [Field; L_PRIME], /// Bounds for p1 polynomials (modulus switching quotients) - pub p1_bounds: [Field; L], + pub p1_bounds: [Field; L_PRIME], /// Bounds for p2 polynomials (cyclotomic reduction quotients) - pub p2_bounds: [Field; L], + pub p2_bounds: [Field; L_PRIME], /// Bound for message polynomial (m) pub msg_bound: Field, } -impl Configs { +impl Configs { pub fn new( t: Field, q_mod_t: Field, - qis: [Field; L], - k0is: [Field; L], - pk_bounds: [Field; L], + qis: [Field; L_PRIME], + k0is: [Field; L_PRIME], + pk_bounds: [Field; L_PRIME], e0_bound: Field, e1_bound: Field, u_bound: Field, - r1_low_bounds: [Field; L], - r1_up_bounds: [Field; L], - r2_bounds: [Field; L], - p1_bounds: [Field; L], - p2_bounds: [Field; L], + r1_low_bounds: [Field; L_PRIME], + r1_up_bounds: [Field; L_PRIME], + r2_bounds: [Field; L_PRIME], + p1_bounds: [Field; L_PRIME], + p2_bounds: [Field; L_PRIME], msg_bound: Field, ) -> Self { Configs { @@ -86,9 +86,9 @@ impl Configs { /// 2. Message commitment matches expected (from SK shares circuit) /// 3. Correct BFV encryption: ct0[l] = pk0[l] * u + e0[l] + k1 * k0[l] + r1[l] * q[l] + r2[l] * (X^N + 1) /// and ct1[l] = pk1[l] * u + e1 + p2[l] * (X^N + 1) + p1[l] * q[l] -pub struct EncryptionBfv { +pub struct EncryptionBfv { /// Circuit parameters - configs: Configs, + configs: Configs, /// Expected commitment to public key (from Circuit 0) /// (public witness) expected_pk_commitment: Field, @@ -96,54 +96,54 @@ pub struct EncryptionBfv; L], + pk0is: [Polynomial; L_PRIME], /// Public key component 1 for each CRT basis (committed witnesses) - pk1is: [Polynomial; L], + pk1is: [Polynomial; L_PRIME], /// Ciphertext component 0 for each CRT basis (public witnesses) - ct0is: [Polynomial; L], + ct0is: [Polynomial; L_PRIME], /// Ciphertext component 1 for each CRT basis (public witnesses) - ct1is: [Polynomial; L], + ct1is: [Polynomial; L_PRIME], /// Random ternary polynomial u (secret witness) u: Polynomial, /// Error polynomial e0 (secret witness) e0: Polynomial, /// Per-basis error polynomials e0[l] (secret witnesses) - e0is: [Polynomial; L], + e0is: [Polynomial; L_PRIME], /// CRT quotients for e0 (secret witnesses) - e0_quotients: [Polynomial; L], + e0_quotients: [Polynomial; L_PRIME], /// Error polynomial e1 (secret witness) e1: Polynomial, /// Raw message polynomial (secret witness) message: Polynomial, /// Modulus switching quotient polynomials r1 (secret witnesses, degree 2N-1) - r1is: [Polynomial<(2 * N) - 1>; L], + r1is: [Polynomial<(2 * N) - 1>; L_PRIME], /// Cyclotomic reduction quotient polynomials r2 (secret witnesses, degree N-1) - r2is: [Polynomial; L], + r2is: [Polynomial; L_PRIME], /// Modulus switching quotient polynomials p1 (secret witnesses, degree 2N-1) - p1is: [Polynomial<(2 * N) - 1>; L], + p1is: [Polynomial<(2 * N) - 1>; L_PRIME], /// Cyclotomic reduction quotient polynomials p2 (secret witnesses, degree N-1) - p2is: [Polynomial; L], + p2is: [Polynomial; L_PRIME], } -impl EncryptionBfv { +impl EncryptionBfv { pub fn new( - configs: Configs, + configs: Configs, expected_pk_commitment: Field, expected_message_commitment: Field, - pk0is: [Polynomial; L], - pk1is: [Polynomial; L], - ct0is: [Polynomial; L], - ct1is: [Polynomial; L], + pk0is: [Polynomial; L_PRIME], + pk1is: [Polynomial; L_PRIME], + ct0is: [Polynomial; L_PRIME], + ct1is: [Polynomial; L_PRIME], u: Polynomial, e0: Polynomial, - e0is: [Polynomial; L], - e0_quotients: [Polynomial; L], + e0is: [Polynomial; L_PRIME], + e0_quotients: [Polynomial; L_PRIME], e1: Polynomial, message: Polynomial, - r1is: [Polynomial<2 * N - 1>; L], - r2is: [Polynomial; L], - p1is: [Polynomial<2 * N - 1>; L], - p2is: [Polynomial; L], + r1is: [Polynomial<2 * N - 1>; L_PRIME], + r2is: [Polynomial; L_PRIME], + p1is: [Polynomial<2 * N - 1>; L_PRIME], + p2is: [Polynomial; L_PRIME], ) -> Self { EncryptionBfv { configs, @@ -169,7 +169,7 @@ impl(self.pk0is, self.pk1is) + compute_pk_bfv_commitment::(self.pk0is, self.pk1is) == self.expected_pk_commitment, "Public key commitment mismatch", ); @@ -248,7 +248,7 @@ impl(self.configs.msg_bound); - for i in 0..L { + for i in 0..L_PRIME { self.pk0is[i].range_check_2bounds::( self.configs.pk_bounds[i], self.configs.pk_bounds[i], @@ -326,7 +326,7 @@ impl) -> Vec { let inputs = self.payload(k1); - compute_bfv_enc_challenge::(inputs) + compute_bfv_enc_challenge::(inputs) } /// Verifies BFV encryption constraints using Fiat-Shamir challenges and the Schwartz-Zippel lemma @@ -338,7 +338,7 @@ impl