Skip to content

Commit

Permalink
Update test vector files (#1153)
Browse files Browse the repository at this point in the history
  • Loading branch information
divergentdave authored Dec 13, 2024
1 parent cbb79b2 commit 937e8a6
Show file tree
Hide file tree
Showing 44 changed files with 4,618 additions and 1,293 deletions.
16 changes: 11 additions & 5 deletions src/idpf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1957,6 +1957,8 @@ mod tests {
struct IdpfTestVector {
/// The number of bits in IDPF inputs.
bits: usize,
/// The application context string.
ctx: Vec<u8>,
/// The nonce used when generating and evaluating keys.
nonce: Vec<u8>,
/// The IDPF input provided to the key generation algorithm.
Expand All @@ -1972,9 +1974,9 @@ mod tests {
}

/// Load a test vector for Idpf key generation.
fn load_idpfpoplar_test_vector() -> IdpfTestVector {
fn load_idpfbbcggi21_test_vector() -> IdpfTestVector {
let test_vec: serde_json::Value =
serde_json::from_str(include_str!("vdaf/test_vec/08/IdpfPoplar_0.json")).unwrap();
serde_json::from_str(include_str!("vdaf/test_vec/13/IdpfBBCGGI21_0.json")).unwrap();
let test_vec_obj = test_vec.as_object().unwrap();

let bits = test_vec_obj
Expand Down Expand Up @@ -2038,11 +2040,15 @@ mod tests {
let public_share_hex = test_vec_obj.get("public_share").unwrap();
let public_share = hex::decode(public_share_hex.as_str().unwrap()).unwrap();

let ctx_hex = test_vec_obj.get("ctx").unwrap();
let ctx = hex::decode(ctx_hex.as_str().unwrap()).unwrap();

let nonce_hex = test_vec_obj.get("binder").unwrap();
let nonce = hex::decode(nonce_hex.as_str().unwrap()).unwrap();

IdpfTestVector {
bits,
ctx,
nonce,
alpha,
beta_inner,
Expand All @@ -2054,15 +2060,15 @@ mod tests {

#[ignore]
#[test]
fn idpf_poplar_generate_test_vector() {
let test_vector = load_idpfpoplar_test_vector();
fn idpf_bbcggi21_generate_test_vector() {
let test_vector = load_idpfbbcggi21_test_vector();
let idpf = Idpf::new((), ());
let (public_share, keys) = idpf
.gen_with_random(
&test_vector.alpha,
test_vector.beta_inner,
test_vector.beta_leaf,
b"WRONG CTX, REPLACE ME", // TODO: Update test vectors to ones that provide ctx str
&test_vector.ctx,
&test_vector.nonce,
&test_vector.keys,
)
Expand Down
61 changes: 44 additions & 17 deletions src/vdaf/poplar1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2107,6 +2107,7 @@ mod tests {
bits: usize,
prep: Vec<PreparationTestVector>,
verify_key: HexEncoded,
ctx: HexEncoded,
}

#[derive(Debug, Deserialize)]
Expand All @@ -2122,10 +2123,6 @@ mod tests {
}

fn check_test_vec(input: &str) {
// We need to use an empty context string for these test vectors to pass.
// TODO: update test vectors to ones that use a real context string
const CTX_STR: &[u8] = b"";

let test_vector: PoplarTestVector = serde_json::from_str(input).unwrap();
assert_eq!(test_vector.prep.len(), 1);
let prep = &test_vector.prep[0];
Expand Down Expand Up @@ -2163,14 +2160,20 @@ mod tests {
// Shard measurement.
let poplar = Poplar1::new_turboshake128(test_vector.bits);
let (public_share, input_shares) = poplar
.shard_with_random(CTX_STR, &measurement, &nonce, &idpf_random, &poplar_random)
.shard_with_random(
test_vector.ctx.as_ref(),
&measurement,
&nonce,
&idpf_random,
&poplar_random,
)
.unwrap();

// Run aggregation.
let (init_prep_state_0, init_prep_share_0) = poplar
.prepare_init(
&verify_key,
CTX_STR,
test_vector.ctx.as_ref(),
0,
&agg_param,
&nonce,
Expand All @@ -2181,7 +2184,7 @@ mod tests {
let (init_prep_state_1, init_prep_share_1) = poplar
.prepare_init(
&verify_key,
CTX_STR,
test_vector.ctx.as_ref(),
1,
&agg_param,
&nonce,
Expand All @@ -2192,42 +2195,54 @@ mod tests {

let r1_prep_msg = poplar
.prepare_shares_to_prepare_message(
CTX_STR,
test_vector.ctx.as_ref(),
&agg_param,
[init_prep_share_0.clone(), init_prep_share_1.clone()],
)
.unwrap();

let (r1_prep_state_0, r1_prep_share_0) = assert_matches!(
poplar
.prepare_next(CTX_STR,init_prep_state_0.clone(), r1_prep_msg.clone())
.prepare_next(
test_vector.ctx.as_ref(),
init_prep_state_0.clone(),
r1_prep_msg.clone(),
)
.unwrap(),
PrepareTransition::Continue(state, share) => (state, share)
);
let (r1_prep_state_1, r1_prep_share_1) = assert_matches!(
poplar
.prepare_next(CTX_STR,init_prep_state_1.clone(), r1_prep_msg.clone())
.prepare_next(
test_vector.ctx.as_ref(),
init_prep_state_1.clone(),
r1_prep_msg.clone(),
)
.unwrap(),
PrepareTransition::Continue(state, share) => (state, share)
);

let r2_prep_msg = poplar
.prepare_shares_to_prepare_message(
CTX_STR,
test_vector.ctx.as_ref(),
&agg_param,
[r1_prep_share_0.clone(), r1_prep_share_1.clone()],
)
.unwrap();

let out_share_0 = assert_matches!(
poplar
.prepare_next(CTX_STR, r1_prep_state_0.clone(), r2_prep_msg.clone())
.prepare_next(
test_vector.ctx.as_ref(),
r1_prep_state_0.clone(),
r2_prep_msg.clone(),
)
.unwrap(),
PrepareTransition::Finish(out) => out
);
let out_share_1 = assert_matches!(
poplar
.prepare_next(CTX_STR,r1_prep_state_1, r2_prep_msg.clone())
.prepare_next(test_vector.ctx.as_ref(), r1_prep_state_1, r2_prep_msg.clone())
.unwrap(),
PrepareTransition::Finish(out) => out
);
Expand Down Expand Up @@ -2391,25 +2406,37 @@ mod tests {
#[ignore]
#[test]
fn test_vec_poplar1_0() {
check_test_vec(include_str!("test_vec/08/Poplar1_0.json"));
check_test_vec(include_str!("test_vec/13/Poplar1_0.json"));
}

#[ignore]
#[test]
fn test_vec_poplar1_1() {
check_test_vec(include_str!("test_vec/08/Poplar1_1.json"));
check_test_vec(include_str!("test_vec/13/Poplar1_1.json"));
}

#[ignore]
#[test]
fn test_vec_poplar1_2() {
check_test_vec(include_str!("test_vec/08/Poplar1_2.json"));
check_test_vec(include_str!("test_vec/13/Poplar1_2.json"));
}

#[ignore]
#[test]
fn test_vec_poplar1_3() {
check_test_vec(include_str!("test_vec/08/Poplar1_3.json"));
check_test_vec(include_str!("test_vec/13/Poplar1_3.json"));
}

#[ignore]
#[test]
fn test_vec_poplar1_4() {
check_test_vec(include_str!("test_vec/13/Poplar1_4.json"));
}

#[ignore]
#[test]
fn test_vec_poplar1_5() {
check_test_vec(include_str!("test_vec/13/Poplar1_5.json"));
}

#[test]
Expand Down
40 changes: 30 additions & 10 deletions src/vdaf/prio3_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,9 @@ mod tests {
#[test]
fn test_vec_prio3_count() {
for test_vector_str in [
include_str!("test_vec/08/Prio3Count_0.json"),
include_str!("test_vec/08/Prio3Count_1.json"),
include_str!("test_vec/13/Prio3Count_0.json"),
include_str!("test_vec/13/Prio3Count_1.json"),
include_str!("test_vec/13/Prio3Count_2.json"),
] {
check_test_vec_custom_de::<Prio3CountMeasurement, _, _, _, _, 16>(
test_vector_str,
Expand All @@ -287,8 +288,9 @@ mod tests {
fn test_vec_prio3_sum() {
const FAKE_MAX_MEASUREMENT_UPDATE_ME: u64 = 0;
for test_vector_str in [
include_str!("test_vec/08/Prio3Sum_0.json"),
include_str!("test_vec/08/Prio3Sum_1.json"),
include_str!("test_vec/13/Prio3Sum_0.json"),
include_str!("test_vec/13/Prio3Sum_1.json"),
include_str!("test_vec/13/Prio3Sum_2.json"),
] {
check_test_vec(test_vector_str, |json_params, num_shares| {
let _bits = json_params["bits"].as_u64().unwrap() as usize;
Expand All @@ -301,8 +303,8 @@ mod tests {
#[test]
fn test_vec_prio3_sum_vec() {
for test_vector_str in [
include_str!("test_vec/08/Prio3SumVec_0.json"),
include_str!("test_vec/08/Prio3SumVec_1.json"),
include_str!("test_vec/13/Prio3SumVec_0.json"),
include_str!("test_vec/13/Prio3SumVec_1.json"),
] {
check_test_vec(test_vector_str, |json_params, num_shares| {
let bits = json_params["bits"].as_u64().unwrap() as usize;
Expand All @@ -319,8 +321,8 @@ mod tests {
type Prio3SumVecField64Multiproof =
Prio3<SumVec<Field64, ParallelSum<Field64, Mul<Field64>>>, XofTurboShake128, 16>;
for test_vector_str in [
include_str!("test_vec/08/Prio3SumVecField64Multiproof_0.json"),
include_str!("test_vec/08/Prio3SumVecField64Multiproof_1.json"),
include_str!("test_vec/13/Prio3SumVecWithMultiproof_0.json"),
include_str!("test_vec/13/Prio3SumVecWithMultiproof_1.json"),
] {
check_test_vec(test_vector_str, |json_params, num_shares| {
let bits = json_params["bits"].as_u64().unwrap() as usize;
Expand All @@ -341,8 +343,9 @@ mod tests {
#[test]
fn test_vec_prio3_histogram() {
for test_vector_str in [
include_str!("test_vec/08/Prio3Histogram_0.json"),
include_str!("test_vec/08/Prio3Histogram_1.json"),
include_str!("test_vec/13/Prio3Histogram_0.json"),
include_str!("test_vec/13/Prio3Histogram_1.json"),
include_str!("test_vec/13/Prio3Histogram_2.json"),
] {
check_test_vec(test_vector_str, |json_params, num_shares| {
let length = json_params["length"].as_u64().unwrap() as usize;
Expand All @@ -351,4 +354,21 @@ mod tests {
});
}
}

#[ignore]
#[test]
fn test_vec_prio3_multihot_count_vec() {
for test_vector_str in [
include_str!("test_vec/13/Prio3MultihotCountVec_0.json"),
include_str!("test_vec/13/Prio3MultihotCountVec_1.json"),
include_str!("test_vec/13/Prio3MultihotCountVec_2.json"),
] {
check_test_vec(test_vector_str, |json_params, num_shares| {
let length = json_params["length"].as_u64().unwrap() as usize;
let max_weight = json_params["max_weight"].as_u64().unwrap() as usize;
let chunk_length = json_params["chunk_length"].as_u64().unwrap() as usize;
Prio3::new_multihot_count_vec(num_shares, length, max_weight, chunk_length).unwrap()
});
}
}
}
52 changes: 0 additions & 52 deletions src/vdaf/test_vec/08/IdpfPoplar_0.json

This file was deleted.

56 changes: 0 additions & 56 deletions src/vdaf/test_vec/08/Poplar1_0.json

This file was deleted.

Loading

0 comments on commit 937e8a6

Please sign in to comment.