From 590a4644e2eaef5414cdfa6c60508ebf5638c0af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogdan-=C8=98tefan=20Neac=C5=9Fu?= Date: Wed, 8 Feb 2023 11:54:12 +0200 Subject: [PATCH] Skip errors on blind sign within threshold (#2976) --- clients/credential/src/commands.rs | 6 ++++++ clients/credential/src/error.rs | 3 +++ common/credentials/src/coconut/utils.rs | 14 ++++++++++---- common/credentials/src/error.rs | 3 +++ 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/clients/credential/src/commands.rs b/clients/credential/src/commands.rs index a007dbf766..31ab1e225c 100644 --- a/clients/credential/src/commands.rs +++ b/clients/credential/src/commands.rs @@ -82,6 +82,11 @@ pub(crate) async fn get_credential(state: &State, shared_storage: PersistentStor let config = Config::try_from_nym_network_details(&network_details)?; let client = validator_client::Client::new_query(config)?; let epoch_id = client.nyxd.get_current_epoch().await?.epoch_id; + let threshold = client + .nyxd + .get_current_epoch_threshold() + .await? + .ok_or(CredentialClientError::NoThreshold)?; let coconut_api_clients = CoconutApiClient::all_coconut_api_clients(&client, epoch_id).await?; let params = Parameters::new(TOTAL_ATTRIBUTES).unwrap(); @@ -98,6 +103,7 @@ pub(crate) async fn get_credential(state: &State, shared_storage: PersistentStor ¶ms, &bandwidth_credential_attributes, &coconut_api_clients, + threshold, ) .await?; println!("Signature: {:?}", signature.to_bs58()); diff --git a/clients/credential/src/error.rs b/clients/credential/src/error.rs index f793957e2f..360db2cf23 100644 --- a/clients/credential/src/error.rs +++ b/clients/credential/src/error.rs @@ -34,4 +34,7 @@ pub enum CredentialClientError { #[error("Could not use shared storage")] SharedStorageError(#[from] StorageError), + + #[error("Threshold not set yet")] + NoThreshold, } diff --git a/common/credentials/src/coconut/utils.rs b/common/credentials/src/coconut/utils.rs index 12edebc3df..aca55abe0b 100644 --- a/common/credentials/src/coconut/utils.rs +++ b/common/credentials/src/coconut/utils.rs @@ -92,6 +92,7 @@ pub async fn obtain_aggregate_signature( params: &Parameters, attributes: &BandwidthVoucher, coconut_api_clients: &[CoconutApiClient], + threshold: u64, ) -> Result { if coconut_api_clients.is_empty() { return Err(Error::NoValidatorsAvailable); @@ -110,15 +111,20 @@ pub async fn obtain_aggregate_signature( .collect(); for coconut_api_client in coconut_api_clients.iter() { - let signature = obtain_partial_credential( + if let Ok(signature) = obtain_partial_credential( params, attributes, &coconut_api_client.api_client, &coconut_api_client.verification_key, ) - .await?; - let share = SignatureShare::new(signature, coconut_api_client.node_id); - shares.push(share) + .await + { + let share = SignatureShare::new(signature, coconut_api_client.node_id); + shares.push(share) + } + } + if shares.len() < threshold as usize { + return Err(Error::NotEnoughShares); } let mut attributes = Vec::with_capacity(private_attributes.len() + public_attributes.len()); diff --git a/common/credentials/src/error.rs b/common/credentials/src/error.rs index f1daaa6142..7f909e79b5 100644 --- a/common/credentials/src/error.rs +++ b/common/credentials/src/error.rs @@ -29,4 +29,7 @@ pub enum Error { #[error("Could not parse the key - {0}")] ParsePublicKey(#[from] KeyRecoveryError), + + #[error("Could not gather enough signature shares")] + NotEnoughShares, }