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

Method validate

proof_system/src/proof_spec.rs:138–223  ·  view source on GitHub ↗

Sanity check to ensure the proof spec is valid. This should never error as these are used by same entity creating them.

(&self)

Source from the content-addressed store, hash-verified

136 /// Sanity check to ensure the proof spec is valid. This should never error as these are used
137 /// by same entity creating them.
138 pub fn validate(&self) -> Result<(), ProofSystemError> {
139 // Ensure that messages(s) being revealed are not used in a witness equality.
140 let mut revealed_wit_refs = BTreeSet::new();
141
142 if (self.aggregate_groth16.is_some() || self.aggregate_legogroth16.is_some())
143 && self.snark_aggregation_srs.is_none()
144 {
145 return Err(ProofSystemError::SnarckpackSrsNotProvided);
146 }
147
148 // Check that the same statement id does not occur in self.aggregate_groth16 and self.aggregate_legogroth16
149 fn check_disjoint_in_same_list(
150 st_ids: &Vec<BTreeSet<usize>>,
151 ) -> Result<(), ProofSystemError> {
152 let len_st_ids = st_ids.len();
153 for (i, s_ids) in st_ids.iter().enumerate() {
154 if i < (len_st_ids - 1) {
155 for j in (i + 1)..len_st_ids {
156 if !s_ids.is_disjoint(&st_ids[j]) {
157 return Err(
158 ProofSystemError::SameStatementIdsFoundInMultipleAggregations(
159 s_ids.intersection(&st_ids[j]).cloned().collect(),
160 ),
161 );
162 }
163 }
164 }
165 }
166 Ok(())
167 }
168
169 if let Some(g16) = &self.aggregate_groth16 {
170 check_disjoint_in_same_list(g16)?
171 }
172 if let Some(lg16) = &self.aggregate_legogroth16 {
173 check_disjoint_in_same_list(lg16)?
174 }
175 if let (Some(g16), Some(lg16)) = (&self.aggregate_groth16, &self.aggregate_legogroth16) {
176 let len_lg16 = lg16.len();
177 for s_ids in g16 {
178 for j in 0..len_lg16 {
179 if !s_ids.is_disjoint(&lg16[j]) {
180 return Err(
181 ProofSystemError::SameStatementIdsFoundInMultipleAggregations(
182 s_ids.intersection(&lg16[j]).cloned().collect(),
183 ),
184 );
185 }
186 }
187 }
188 }
189
190 // Check that a message signed with BBS+ being revealed does not occur as a witness in any zero
191 // knowledge proof
192 for (i, st) in self.statements.0.iter().enumerate() {
193 match st {
194 Statement::PoKBBSSignatureG1Prover(s) => {
195 for k in s.revealed_messages.keys() {

Calls 3

lenMethod · 0.45
iterMethod · 0.45
is_validMethod · 0.45

Tested by

no test coverage detected