Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only store verified encrypted private shares within Signer #86

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/state_machine/signer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -734,24 +734,24 @@ impl<SignerType: SignerTrait> Signer<SignerType> {
) -> Result<Vec<Message>, Error> {
// go ahead and decrypt here, since we know the signer_id and hence the pubkey of the sender
let src_signer_id = dkg_private_shares.signer_id;
self.dkg_private_shares
.insert(src_signer_id, dkg_private_shares.clone());

// make a HashSet of our key_ids so we can quickly query them
let key_ids: HashSet<u32> = self.signer.get_key_ids().into_iter().collect();
let compressed = Compressed::from(self.public_keys.signers[&src_signer_id].to_bytes());
let public_key = Point::try_from(&compressed).unwrap();
let shared_key = self.network_private_key * public_key;
let shared_secret = make_shared_secret(&self.network_private_key, &public_key);

let mut verified_shares = Vec::with_capacity(dkg_private_shares.shares.len());
for (src_id, shares) in &dkg_private_shares.shares {
let mut decrypted_shares = HashMap::new();
let mut encrypted_shares = HashMap::new();
for (dst_key_id, bytes) in shares {
if key_ids.contains(dst_key_id) {
match decrypt(&shared_secret, bytes) {
Ok(plain) => match Scalar::try_from(&plain[..]) {
Ok(s) => {
decrypted_shares.insert(*dst_key_id, s);
encrypted_shares.insert(*dst_key_id, bytes.clone());
}
Err(e) => {
warn!("Failed to parse Scalar for dkg private share from src_id {} to dst_id {}: {:?}", src_id, dst_key_id, e);
Expand All @@ -772,7 +772,16 @@ impl<SignerType: SignerTrait> Signer<SignerType> {
self.decrypted_shares.insert(*src_id, decrypted_shares);
self.decryption_keys
.insert(*src_id, (dkg_private_shares.signer_id, shared_key));
verified_shares.push((*src_id, encrypted_shares));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could result in empty encrypted shares hashmap per src_id. I assumed this was okay. but just confirming?

}
self.dkg_private_shares.insert(
src_signer_id,
DkgPrivateShares {
dkg_id: dkg_private_shares.dkg_id,
signer_id: dkg_private_shares.signer_id,
shares: verified_shares,
},
);
debug!(
"received DkgPrivateShares from signer {} {}/{}",
dkg_private_shares.signer_id,
Expand Down
Loading