/// Verifies a single complaint against a dealing.
///
/// # Arguments
/// `dkg_id` - identifier for the key generation
/// `dealing` - the dealing that is being complained about
/// `receiver_index` - the index of the receiver making the complaint
/// `dealer_public_key_bytes` - the ephemeral public key of the dealer, not a
/// threshold key `receiver_public_key_bytes` - the ephemeral public key of the
/// receiver, not a threshold key `complaint` - the complaint being verified
/// # Panics
/// This method is not expected to panic
/// # Errors
/// This method SHALL return an error if:
/// * any of the fields is malformed.  Note that the caller MUST verify the
///   format of the dealing and public keys before calling this method, so this
///   SHOULD occur only if the complaint is malformed.
/// * the `receiver_index` is out of range for the dealing.
/// * the dealing has no share for the receiver.
/// * the complaint proof does not validate.
Verifies a single complaint against a dealing.
Verifies a single complaint against a dealing .
pub(super) fn verify_complaint(
    dkg_id: IDkgId,
    dealing: &CLibDealingBytes,
    receiver_index: NodeIndex,
    dealer_public_key_bytes: &EphemeralPublicKeyBytes,
    receiver_public_key_bytes: &EphemeralPublicKeyBytes,
    complaint_bytes: &CLibComplaintBytes,
) -> Result<(), DkgVerifyResponseError> {
    //  Parse:
    let complaint: CLibComplaint = complaint_bytes
        .try_into()
        .map_err(DkgVerifyResponseError::MalformedResponseError)?;
    let dealer_public_key = EphemeralPublicKey::try_from(dealer_public_key_bytes)
        .map_err(|e| DkgVerifyResponseError::MalformedResponseError(e.into()))?;
    let receiver_public_key = EphemeralPublicKey::try_from(receiver_public_key_bytes)
        .map_err(|e| DkgVerifyResponseError::MalformedResponseError(e.into()))?;
    let CLibDealingBytes {
        receiver_data,
        public_coefficients,
    } = dealing;
    let public_coefficients =
        PublicCoefficients::try_from(public_coefficients).map_err(|_: CryptoError| {
            DkgVerifyResponseError::MalformedResponseError(MalformedDataError {
                algorithm: AlgorithmId::Secp256k1,
                internal_error: "Cannot parse public coefficients".to_string(),
                data: None,
            })
        })?; // Note: The AlgorithmId returned is that in the API, although the data is
             // actually used in Bls12_381 threshold signatures.
    let dealt_share: EncryptedShare = receiver_data
        .get(usize::try_from(receiver_index).map_err(|_| DkgVerifyResponseError::SizeError( SizeError {
            message: format!("Receiver index {} is too large for this machine", receiver_index),
        }))?)
        .ok_or_else(||DkgVerifyResponseError::InvalidReceiverIndexError(InvalidArgumentError {
            message: format!("Receiver index {} is out of bounds", receiver_index),
        }))?
        .ok_or(DkgVerifyResponseError::MalformedDealingError( MalformedDataError {
            algorithm: AlgorithmId::Secp256k1,
            internal_error: "Receiver has no dealing.  verified_dealing() implies that the receiver is not eligible.".to_string(),
            data: None,
        }))?
        .try_into().map_err(DkgVerifyResponseError::MalformedResponseError)?;
    // Verify:
    verify_pok(
        dkg_id,
        &complaint,
        complaint_bytes,
        &receiver_public_key,
        receiver_public_key_bytes,
        &dealer_public_key,
        dealer_public_key_bytes,
    )?;
    verify_share_is_bad(
        dkg_id,
        &complaint,
        &receiver_public_key,
        receiver_index,
        &dealer_public_key,
        &public_coefficients,
        dealt_share,
    )
}
pub ( super ) fn verify_complaint ( dkg_id : IDkgId , dealing : & CLibDealingBytes , receiver_index : NodeIndex , dealer_public_key_bytes : & EphemeralPublicKeyBytes , receiver_public_key_bytes : & EphemeralPublicKeyBytes , complaint_bytes : & CLibComplaintBytes , ) -> Result < ( ) , DkgVerifyResponseError > { //  Parse: let complaint : CLibComplaint = complaint_bytes . try_into ( ) . map_err ( DkgVerifyResponseError :: MalformedResponseError ) ? ; let dealer_public_key = EphemeralPublicKey :: try_from ( dealer_public_key_bytes ) . map_err ( | e | DkgVerifyResponseError :: MalformedResponseError ( e . into ( ) ) ) ? ; let receiver_public_key = EphemeralPublicKey :: try_from ( receiver_public_key_bytes ) . map_err ( | e | DkgVerifyResponseError :: MalformedResponseError ( e . into ( ) ) ) ? ; let CLibDealingBytes { receiver_data , public_coefficients , } = dealing ; let public_coefficients = PublicCoefficients :: try_from ( public_coefficients ) . map_err ( | _ : CryptoError | { DkgVerifyResponseError :: MalformedResponseError ( MalformedDataError { algorithm : AlgorithmId :: Secp256k1 , internal_error : " " . to_string ( ) , data : None , } ) } ) ? ; // Note: The AlgorithmId returned is that in the API, although the data is // actually used in Bls12_381 threshold signatures. let dealt_share : EncryptedShare = receiver_data . get ( usize :: try_from ( receiver_index ) . map_err ( | _ | DkgVerifyResponseError :: SizeError ( SizeError { message : format ! ( " " receiver_index ) , } ) ) ? ) . ok_or_else ( | | DkgVerifyResponseError :: InvalidReceiverIndexError ( InvalidArgumentError { message : format ! ( " " receiver_index ) , } ) ) ? . ok_or ( DkgVerifyResponseError :: MalformedDealingError ( MalformedDataError { algorithm : AlgorithmId :: Secp256k1 , internal_error : " " . to_string ( ) , data : None , } ) ) ? . try_into ( ) . map_err ( DkgVerifyResponseError :: MalformedResponseError ) ? ; // Verify: verify_pok ( dkg_id , & complaint , complaint_bytes , & receiver_public_key , receiver_public_key_bytes , & dealer_public_key , dealer_public_key_bytes , ) ? ; verify_share_is_bad ( dkg_id , & complaint , & receiver_public_key , receiver_index , & dealer_public_key , & public_coefficients , dealt_share , ) }
Verifies a single complaint against a dealing.
Verifies a single complaint against a dealing .
dkg_id
IDkgId
dealing
&CLibDealingBytes
receiver_index
NodeIndex
dealer_public_key_bytes
&EphemeralPublicKeyBytes
receiver_public_key_bytes
&EphemeralPublicKeyBytes
complaint_bytes
&CLibComplaintBytes
panics
This method is not expected to panic
This method is not expected to panic
errors
This method SHALL return an error if:
any of the fields is malformed.  Note that the caller MUST verify the
format of the dealing and public keys before calling this method, so this
SHOULD occur only if the complaint is malformed.
the `receiver_index` is out of range for the dealing.
the dealing has no share for the receiver.
the complaint proof does not validate.
This method SHALL return an error if : any of the fields is malformed . Note that the caller MUST verify the format of the dealing and public keys before calling this method so this SHOULD occur only if the complaint is malformed . the ` receiver_index ` is out of range for the dealing . the dealing has no share for the receiver . the complaint proof does not validate .