Skip to content

Commit 02a2e41

Browse files
committed
chore(zk): hash the value of k with the statement
1 parent bd2381a commit 02a2e41

File tree

6 files changed

+65
-1
lines changed

6 files changed

+65
-1
lines changed

tfhe-zk-pok/src/backward_compatibility/pke_v2.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ impl<G: Curve> Upgrade<Proof<G>> for ProofV2<G> {
181181
mode: hash_mode,
182182
proven_zero_bits_encoding: PkeV2ProvenZeroBitsEncoding::MsbZeroBitsCountOnly,
183183
hashed_bound_type: PkeV2HashedBoundType::SquaredEuclideanNorm,
184+
hash_k: false,
184185
},
185186
})
186187
}
@@ -394,6 +395,7 @@ where
394395
mode: hash_mode,
395396
proven_zero_bits_encoding: PkeV2ProvenZeroBitsEncoding::MsbZeroBitsCountOnly,
396397
hashed_bound_type: PkeV2HashedBoundType::SquaredEuclideanNorm,
398+
hash_k: false,
397399
},
398400
})
399401
}

tfhe-zk-pok/src/proofs/pke_v2/hashes.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ pub struct PkeV2HashConfig {
8686
pub(crate) mode: PkeV2HashMode,
8787
pub(crate) proven_zero_bits_encoding: PkeV2ProvenZeroBitsEncoding,
8888
pub(crate) hashed_bound_type: PkeV2HashedBoundType,
89+
/// Should we also hash the value of k with the statement
90+
pub(crate) hash_k: bool,
8991
}
9092

9193
impl Default for PkeV2HashConfig {
@@ -97,6 +99,7 @@ impl Default for PkeV2HashConfig {
9799
mode: PkeV2HashMode::Compact,
98100
proven_zero_bits_encoding: PkeV2ProvenZeroBitsEncoding::AnyBitAnySlot,
99101
hashed_bound_type: PkeV2HashedBoundType::InfiniteNorm,
102+
hash_k: true,
100103
}
101104
}
102105
}
@@ -113,6 +116,10 @@ impl PkeV2HashConfig {
113116
pub fn hashed_bound(&self) -> PkeV2HashedBoundType {
114117
self.hashed_bound_type
115118
}
119+
120+
pub fn hash_k(&self) -> bool {
121+
self.hash_k
122+
}
116123
}
117124

118125
/// Encode the bits proven to be 0 in a plaintext list.
@@ -349,9 +356,16 @@ impl<'a> RHash<'a> {
349356
PkeV2HashedBoundType::InfiniteNorm => B_inf.to_le_bytes().to_vec(),
350357
};
351358

359+
let hashed_k = if config.hash_k {
360+
k.to_le_bytes().to_vec()
361+
} else {
362+
Vec::new()
363+
};
364+
352365
let x_bytes = [
353366
q.to_le_bytes().as_slice(),
354367
(d as u64).to_le_bytes().as_slice(),
368+
&hashed_k.as_slice(),
355369
&hashed_bound,
356370
t_input.to_le_bytes().as_slice(),
357371
encoded_zero_bits.as_slice(),

tfhe-zk-pok/src/proofs/pke_v2/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2352,6 +2352,7 @@ mod tests {
23522352
proven_zero_bits_encoding:
23532353
PkeV2ProvenZeroBitsEncoding::MsbZeroBitsCountOnly,
23542354
hashed_bound_type: PkeV2HashedBoundType::SquaredEuclideanNorm,
2355+
hash_k: false,
23552356
};
23562357
let proof = prove_impl(
23572358
(&public_param, &public_commit),

tfhe/src/integer/ciphertext/compact_list.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,6 +1185,15 @@ impl IntegerProvenCompactCiphertextListConformanceParams {
11851185
..self
11861186
}
11871187
}
1188+
1189+
/// Reject the proof conformance if k is not hashed. This has no effect on
1190+
/// PkeV1 proofs
1191+
pub fn force_hash_k(self) -> Self {
1192+
Self {
1193+
zk_conformance_params: self.zk_conformance_params.force_hash_k(),
1194+
..self
1195+
}
1196+
}
11881197
}
11891198

11901199
#[cfg(feature = "zk-pok")]

tfhe/src/shortint/ciphertext/zk.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,15 @@ impl ProvenCompactCiphertextListConformanceParams {
279279
..self
280280
}
281281
}
282+
283+
/// Reject the proof conformance if k is not hashed. This has no effect on
284+
/// PkeV1 proofs
285+
pub fn force_hash_k(self) -> Self {
286+
Self {
287+
zk_conformance_params: self.zk_conformance_params.force_hash_k(),
288+
..self
289+
}
290+
}
282291
}
283292

284293
impl ParameterSetConformant for ProvenCompactCiphertextList {

tfhe/src/zk/mod.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ pub struct CompactPkeV2ProofConformanceParams {
123123
accepted_hash_mode: EnumSet<PkeV2HashMode>,
124124
accepted_proven_zero_bits_encoding: EnumSet<PkeV2ProvenZeroBitsEncoding>,
125125
accepted_hashed_bound_type: EnumSet<PkeV2HashedBoundType>,
126+
accepted_hash_k_mode: EnumSet<bool>,
126127
}
127128

128129
impl Default for CompactPkeV2ProofConformanceParams {
@@ -152,11 +153,16 @@ impl CompactPkeV2ProofConformanceParams {
152153
accepted_hashed_bound_type.insert(PkeV2HashedBoundType::SquaredEuclideanNorm);
153154
accepted_hashed_bound_type.insert(PkeV2HashedBoundType::InfiniteNorm);
154155

156+
let mut accepted_hash_k_mode = EnumSet::new();
157+
accepted_hash_k_mode.insert(true);
158+
accepted_hash_k_mode.insert(false);
159+
155160
Self {
156161
accepted_compute_load,
157162
accepted_hash_mode,
158163
accepted_proven_zero_bits_encoding,
159164
accepted_hashed_bound_type,
165+
accepted_hash_k_mode,
160166
}
161167
}
162168

@@ -209,6 +215,17 @@ impl CompactPkeV2ProofConformanceParams {
209215
..self
210216
}
211217
}
218+
219+
/// Reject the proof conformance if k is not hashed
220+
pub fn force_hash_k(self) -> Self {
221+
let mut accepted_hash_k_mode = self.accepted_hash_k_mode;
222+
accepted_hash_k_mode.remove(false);
223+
224+
Self {
225+
accepted_hash_k_mode,
226+
..self
227+
}
228+
}
212229
}
213230

214231
impl ParameterSetConformant for ProofV2<Curve> {
@@ -227,6 +244,9 @@ impl ParameterSetConformant for ProofV2<Curve> {
227244
&& parameter_set
228245
.accepted_hashed_bound_type
229246
.contains(self.hash_config().hashed_bound())
247+
&& parameter_set
248+
.accepted_hash_k_mode
249+
.contains(self.hash_config().hash_k())
230250
&& self.is_usable()
231251
}
232252
}
@@ -289,13 +309,22 @@ impl CompactPkeProofConformanceParams {
289309
forbidden_hashed_bound_type: ZkPkeV2HashedBoundType,
290310
) -> Self {
291311
match self {
292-
// There is no hash mode to configure in PkeV1
312+
// There is no hashed bound to configure in PkeV1
293313
Self::PkeV1(params) => Self::PkeV1(params),
294314
Self::PkeV2(params) => {
295315
Self::PkeV2(params.forbid_hashed_bound_type(forbidden_hashed_bound_type))
296316
}
297317
}
298318
}
319+
320+
/// Reject the proof conformance if k is not hashed. This has no effect on
321+
/// PkeV1 proofs
322+
pub fn force_hash_k(self) -> Self {
323+
match self {
324+
Self::PkeV1(params) => Self::PkeV1(params),
325+
Self::PkeV2(params) => Self::PkeV2(params.force_hash_k()),
326+
}
327+
}
299328
}
300329

301330
impl ParameterSetConformant for CompactPkeProof {

0 commit comments

Comments
 (0)