MCPcopy Create free account
hub / github.com/docknetwork/crypto / verify_schnorr_proofs

Method verify_schnorr_proofs

bbs_plus/src/proof.rs:544–611  ·  view source on GitHub ↗
(
        &self,
        revealed_msgs: &BTreeMap<usize, E::ScalarField>,
        challenge: &E::ScalarField,
        g1: E::G1Affine,
        h_0: E::G1Affine,
        h: Vec<E::G1Affine>,
        mi

Source from the content-addressed store, hash-verified

542 }
543
544 pub fn verify_schnorr_proofs(
545 &self,
546 revealed_msgs: &BTreeMap<usize, E::ScalarField>,
547 challenge: &E::ScalarField,
548 g1: E::G1Affine,
549 h_0: E::G1Affine,
550 h: Vec<E::G1Affine>,
551 missing_responses: Option<BTreeMap<usize, E::ScalarField>>,
552 ) -> Result<(), BBSPlusError> {
553 // Verify the 1st Schnorr proof
554 // A_bar - d
555 let A_bar_minus_d = (self.A_bar.into_group() - self.d.into_group()).into_affine();
556 if !self
557 .sc_resp_1
558 .verify(&A_bar_minus_d, &self.A_prime, &h_0, challenge)
559 {
560 return Err(BBSPlusError::FirstSchnorrVerificationFailed);
561 }
562
563 // Verify the 2nd Schnorr proof
564 let mut bases_2 = Vec::with_capacity(2 + h.len() - revealed_msgs.len());
565
566 let mut bases_revealed = Vec::with_capacity(revealed_msgs.len());
567 let mut exponents = Vec::with_capacity(revealed_msgs.len());
568 for i in 0..h.len() {
569 if revealed_msgs.contains_key(&i) {
570 let message = revealed_msgs.get(&i).unwrap();
571 bases_revealed.push(h[i]);
572 exponents.push(*message);
573 } else {
574 bases_2.push(h[i]);
575 }
576 }
577 bases_2.push(self.d);
578 bases_2.push(h_0);
579 // pr = -g1 + \sum_{i in D}(h_i*{-m_i}) = -(g1 + \sum_{i in D}(h_i*{m_i}))
580 let pr = -E::G1::msm_unchecked(&bases_revealed, &exponents) - g1;
581 let pr = pr.into_affine();
582 if let Some(resp) = &self.sc_resp_2 {
583 if missing_responses.is_some() {
584 return Err(BBSPlusError::MissingResponsesProvidedForFullSchnorrProofVerification);
585 }
586 return match resp.is_valid(&bases_2, &pr, &self.T2, challenge) {
587 Ok(()) => Ok(()),
588 Err(SchnorrError::InvalidResponse) => {
589 Err(BBSPlusError::SecondSchnorrVerificationFailed)
590 }
591 Err(other) => Err(BBSPlusError::SchnorrError(other)),
592 };
593 } else if let Some(resp) = &self.sc_partial_resp_2 {
594 if missing_responses.is_none() {
595 return Err(BBSPlusError::MissingResponsesNeededForPartialSchnorrProofVerification);
596 }
597 let adjusted_missing = msg_index_map_to_schnorr_response_map(
598 missing_responses.unwrap(),
599 revealed_msgs.keys(),
600 );
601 return match resp.is_valid(&bases_2, &pr, &self.T2, challenge, adjusted_missing) {

Callers 1

Calls 6

SchnorrErrorEnum · 0.85
getMethod · 0.80
verifyMethod · 0.45
lenMethod · 0.45
is_validMethod · 0.45

Tested by

no test coverage detected