From aaffbea1ed4e79957363b2bc8fcb25fc2e64a078 Mon Sep 17 00:00:00 2001 From: th4s Date: Fri, 6 Jan 2023 15:50:33 +0100 Subject: [PATCH] Fix rng seed for kos15 unit tests Encountered a failed kos15 unit test, because of some very special rng seed. The test which failed was `test_ot_splitting_mix_pairs`, which is expected to panic because it uses a wrong pair of split senders and receivers. I believe that it failed (did not panic, like expected) because the rng seed incidentally produced some blocks, where the first half does not differ from the second half. This probably happened because the number of blocks produced is a random number between (1..1024) and I expect that the number chosen by the rng seed was very small, so that there was a high probability that this could happen. We agreed to seed unit tests with a fixed seed, so I took this opportunity to just do that for the kos15 unit tests. --- mpc-core/src/ot/extension/kos15/mod.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mpc-core/src/ot/extension/kos15/mod.rs b/mpc-core/src/ot/extension/kos15/mod.rs index 7e4612eba..a8a224a88 100644 --- a/mpc-core/src/ot/extension/kos15/mod.rs +++ b/mpc-core/src/ot/extension/kos15/mod.rs @@ -49,7 +49,7 @@ pub mod tests { #[fixture] fn input_setup() -> (Vec, Vec<[Block; 2]>) { - let mut rng = ChaCha12Rng::from_entropy(); + let mut rng = ChaCha12Rng::from_seed([0; 32]); let choice_len: usize = rng.gen_range(1..1024); let mut choices = vec![false; choice_len]; @@ -153,7 +153,7 @@ pub mod tests { assert!(receiver.is_complete()); // Trying to send more OTs should return an error - let mut rng = ChaCha12Rng::from_entropy(); + let mut rng = ChaCha12Rng::from_seed([0; 32]); let sender = sender .send(&[[Block::random(&mut rng), Block::random(&mut rng)]]) .expect_err("Sending more OTs should be a state error"); @@ -235,7 +235,7 @@ pub mod tests { assert!(sender.is_complete()); assert!(receiver.is_complete()); - let mut rng = ChaCha12Rng::from_entropy(); + let mut rng = ChaCha12Rng::from_seed([0; 32]); // Trying to send more OTs should return an error let add_derand = msgs::ExtDerandomize { flip: vec![true] }; @@ -277,7 +277,7 @@ pub mod tests { let (_, mut receiver_setup) = receiver.extension_setup(&choices).unwrap(); // sender must not accept more or less columns - let mut rng = ChaCha12Rng::from_entropy(); + let mut rng = ChaCha12Rng::from_seed([0; 32]); let coinflip: bool = rng.gen(); if coinflip { @@ -302,7 +302,7 @@ pub mod tests { ) { let (sender, receiver) = pair_base_setup; let (choices, inputs) = input_setup; - let mut rng = ChaCha12Rng::from_entropy(); + let mut rng = ChaCha12Rng::from_seed([0; 32]); let split_at: usize = rng.gen_range(0..inputs.len()); let (mut receiver, receiver_setup) = receiver.extension_setup(&choices).unwrap();