Skip to content

Commit

Permalink
Add test to ensure old share compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
r-n-o committed Nov 13, 2024
1 parent cf8fbaa commit ec7f31f
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/qos_crypto/src/shamir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ mod test {
use rand::prelude::SliceRandom;

use super::*;

#[test]
fn make_and_reconstruct_shares() {
let secret = b"this is a crazy secret";
Expand Down Expand Up @@ -65,4 +66,39 @@ mod test {
assert_eq!(secret.to_vec(), reconstructed);
}
}

#[test]
fn can_reconstruct_from_old_shares() {
// This test if fundamental to ensure updates to the Shamir Secret
// Sharing logic can be made safely. Here we hardcode shares that were
// created with the oldest version of this logic, and ensure that we can
// reconstruct. If this test starts failing please do _not_ ignore it,
// it's telling you the current quorum key shares will become invalid
// when combined!
let shares = [
qos_hex::decode("0116b5873b04714bd159f8ff59613f9e79cbb2e7a526")
.unwrap(),
qos_hex::decode("029bfa75d3977e39d90650792e76d1476722da43fed0")
.unwrap(),
qos_hex::decode("03e036d28be67b172833c1f2037b8bf96d8c0bd63e82")
.unwrap(),
];

// Setting is 2-out-of-3. Let's try 3 ways.
let reconstructed1 =
shares_reconstruct(vec![shares[0].clone(), shares[1].clone()])
.unwrap();
let reconstructed2 =
shares_reconstruct(vec![shares[1].clone(), shares[2].clone()])
.unwrap();
let reconstructed3 =
shares_reconstruct(vec![shares[0].clone(), shares[2].clone()])
.unwrap();

// Regardless of the combination we should get the same secret
let expected_secret = b"my cute little secret";
assert_eq!(reconstructed1, expected_secret);
assert_eq!(reconstructed2, expected_secret);
assert_eq!(reconstructed3, expected_secret);
}
}

0 comments on commit ec7f31f

Please sign in to comment.