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

Method open_subset_unchecked

delegatable_credentials/src/set_commitment.rs:321–355  ·  view source on GitHub ↗

Returns witness for the given subset of a set which is committed in this commitment

(
        &self,
        opening: &SetCommitmentOpening<E>,
        subset: BTreeSet<E::ScalarField>,
        set: BTreeSet<E::ScalarField>,
        srs: &SetCommitmentSRS<E>,
    )

Source from the content-addressed store, hash-verified

319
320 /// Returns witness for the given subset of a set which is committed in this commitment
321 pub fn open_subset_unchecked(
322 &self,
323 opening: &SetCommitmentOpening<E>,
324 subset: BTreeSet<E::ScalarField>,
325 set: BTreeSet<E::ScalarField>,
326 srs: &SetCommitmentSRS<E>,
327 ) -> Result<SubsetWitness<E>, DelegationError> {
328 let subset_size = subset.len();
329 if subset_size == 0 {
330 return Ok(SubsetWitness(self.0));
331 }
332 match opening {
333 SetCommitmentOpening::SetWithTrapdoor(_, s) => {
334 if subset.contains(s) {
335 Err(DelegationError::ShouldNotContainTrapdoor)
336 } else {
337 let poly = poly_from_roots(&subset.into_iter().collect::<Vec<_>>());
338 let mut e = poly.evaluate(s);
339 e.inverse_in_place().unwrap();
340 Ok(SubsetWitness(self.0.mul(e).into()))
341 }
342 }
343 SetCommitmentOpening::SetWithoutTrapdoor(r) => {
344 let diff = set.difference(&subset).cloned().collect::<BTreeSet<_>>();
345 let witness = if diff.is_empty() {
346 // Subset is same as the set
347 srs.get_P1().mul_bigint(r.into_bigint()).into_affine()
348 } else {
349 // Commit to remaining elements
350 Self::commit_in_P1(r.into_bigint(), diff, srs)
351 };
352 Ok(SubsetWitness(witness))
353 }
354 }
355 }
356
357 /// Randomize the set commitment and the corresponding opening
358 pub fn randomize(

Callers 4

open_subsetMethod · 0.80
checkFunction · 0.80
initMethod · 0.80
_initMethod · 0.80

Calls 7

SubsetWitnessClass · 0.85
poly_from_rootsFunction · 0.85
evaluateMethod · 0.80
mulMethod · 0.80
lenMethod · 0.45
into_iterMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected