Skip to content

Commit 4097c19

Browse files
schoppmpcopybara-github
authored andcommitted
Implement unit tests for Verifier
Also simplify VerifierState, and implement Debug traits where needed. PiperOrigin-RevId: 831545309
1 parent 7547098 commit 4097c19

File tree

5 files changed

+297
-50
lines changed

5 files changed

+297
-50
lines changed

willow/src/testing_utils/testing_utils.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use kahe_traits::KaheBase;
1818
use rand::Rng;
1919
use shell_testing_parameters::{make_ahe_config, make_kahe_config};
2020
use single_thread_hkdf::Seed;
21+
use std::collections::HashMap;
2122
use vahe_shell::ShellVahe;
2223
use vahe_traits::{Recover, VaheBase};
2324
use willow_api_common::AggregationConfig;
@@ -65,6 +66,24 @@ pub fn ahe_decrypt_with_single_sk_share(
6566
common.vahe.recover(&partial_decryption, &rest_of_ciphertext, None)
6667
}
6768

69+
/// Generates an AggregationConfig for test cases in this file.
70+
pub fn generate_aggregation_config(
71+
vector_id: String,
72+
vector_length: isize,
73+
vector_bound: i64,
74+
max_number_of_decryptors: i64,
75+
max_number_of_clients: i64,
76+
) -> AggregationConfig {
77+
AggregationConfig {
78+
vector_lengths_and_bounds: HashMap::from([(vector_id, (vector_length, vector_bound))]),
79+
max_number_of_decryptors,
80+
max_number_of_clients,
81+
max_decryptor_dropouts: 0,
82+
session_id: String::from("test"),
83+
willow_version: (1, 0),
84+
}
85+
}
86+
6887
/// Concrete implementation of the client using the Shell KAHE/VAHE
6988
/// implementations.
7089
pub type ShellClient = WillowV1Client<ShellKahe, ShellVahe>;

willow/src/willow_v1/BUILD

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,27 @@ rust_library(
109109
"//willow/src/traits:verifier_traits",
110110
],
111111
)
112+
113+
rust_test(
114+
name = "willow_v1_verifier_test",
115+
crate = ":willow_v1_verifier",
116+
deps = [
117+
"@crate_index//:googletest",
118+
"//shell_wrapper:status_matchers_rs",
119+
"//willow/src/shell:kahe_shell",
120+
"//willow/src/shell:single_thread_hkdf",
121+
"//willow/src/shell:vahe_shell",
122+
"//willow/src/testing_utils",
123+
"//willow/src/traits:ahe_traits",
124+
"//willow/src/traits:client_traits",
125+
"//willow/src/traits:decryptor_traits",
126+
"//willow/src/traits:kahe_traits",
127+
"//willow/src/traits:prng_traits",
128+
"//willow/src/traits:server_traits",
129+
"//willow/src/traits:vahe_traits",
130+
"//willow/src/willow_v1:willow_v1_client",
131+
"//willow/src/willow_v1:willow_v1_common",
132+
"//willow/src/willow_v1:willow_v1_decryptor",
133+
"//willow/src/willow_v1:willow_v1_server",
134+
],
135+
)

willow/src/willow_v1/common.rs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use ahe_traits::AheBase;
1616
use common_traits::SecureAggregationCommon;
1717
use kahe_traits::KaheBase;
18+
use std::fmt::Debug;
1819
use vahe_traits::VaheBase;
1920

2021
/// Common types for a generic lightweight KAHE/AHE-based implementation of the
@@ -61,25 +62,51 @@ impl<Vahe: VaheBase> Clone for PartialDecryptionRequest<Vahe> {
6162
}
6263
}
6364

65+
impl<Vahe: VaheBase> Debug for PartialDecryptionRequest<Vahe> {
66+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
67+
f.debug_struct("PartialDecryptionRequest")
68+
.field("partial_dec_ciphertext", &"(OMITTED)")
69+
.finish()
70+
}
71+
}
72+
6473
pub struct PartialDecryptionResponse<Vahe: VaheBase> {
6574
pub partial_decryption: Vahe::PartialDecryption,
6675
}
6776

6877
/// The part of the client message that the verifier needn't check
69-
#[derive(Debug, Clone)]
7078
pub struct CiphertextContribution<Kahe: KaheBase, Vahe: VaheBase> {
7179
pub kahe_ciphertext: Kahe::Ciphertext,
7280
pub ahe_recover_ciphertext: Vahe::RecoverCiphertext,
7381
}
7482

83+
impl<Kahe: KaheBase, Vahe: VaheBase> Clone for CiphertextContribution<Kahe, Vahe> {
84+
fn clone(&self) -> CiphertextContribution<Kahe, Vahe> {
85+
CiphertextContribution {
86+
kahe_ciphertext: self.kahe_ciphertext.clone(),
87+
ahe_recover_ciphertext: self.ahe_recover_ciphertext.clone(),
88+
}
89+
}
90+
}
91+
7592
/// The material from the client that the verifier must check.
76-
#[derive(Debug, Clone)]
93+
#[derive(Debug)]
7794
pub struct DecryptionRequestContribution<Vahe: VaheBase> {
7895
pub partial_dec_ciphertext: Vahe::PartialDecCiphertext,
7996
pub proof: Vahe::EncryptionProof,
8097
pub nonce: Vec<u8>,
8198
}
8299

100+
impl<Vahe: VaheBase> Clone for DecryptionRequestContribution<Vahe> {
101+
fn clone(&self) -> DecryptionRequestContribution<Vahe> {
102+
DecryptionRequestContribution {
103+
partial_dec_ciphertext: self.partial_dec_ciphertext.clone(),
104+
proof: self.proof.clone(),
105+
nonce: self.nonce.clone(),
106+
}
107+
}
108+
}
109+
83110
impl<Kahe: KaheBase, Vahe: VaheBase> SecureAggregationCommon for WillowCommon<Kahe, Vahe> {
84111
type DecryptorPublicKeyShare = DecryptorPublicKeyShare<Vahe>;
85112

0 commit comments

Comments
 (0)