fn trim(
        pp: &Self::UniversalParams,
        supported_degree: usize,
        enforced_degree_bounds: Option<&[usize]>,
    ) -> Result<(Self::CommitterKey, Self::VerifierKey), Self::Error> {
        let max_degree = pp.max_degree();
        if supported_degree > max_degree {
            return Err(Error::TrimmingDegreeTooLarge);
        }

        // Construct the KZG10 committer key for committing to unshifted polynomials.
        let ck_time =
            start_timer!(|| format!("Constructing `powers` of size {} for unshifted polys", supported_degree));
        let powers = pp.powers_of_g[..=supported_degree].to_vec();
        // We want to support making up to supported_degree queries to committed
        // polynomials.
        let powers_of_gamma_g = pp.powers_of_gamma_g[..=(supported_degree + 1)].to_vec();
        end_timer!(ck_time);

        // Construct the core KZG10 verifier key.
        let vk = kzg10::VerifierKey {
            g: pp.powers_of_g[0],
            gamma_g: pp.powers_of_gamma_g[0],
            h: pp.h,
            beta_h: pp.beta_h,
            prepared_h: pp.prepared_h.clone(),
            prepared_beta_h: pp.prepared_beta_h.clone(),
        };

        let enforced_degree_bounds = enforced_degree_bounds.map(|v| {
            let mut v = v.to_vec();
            v.sort();
            v.dedup();
            v
        });

        // Check whether we have some degree bounds to enforce
        let (shifted_powers, degree_bounds_and_shift_powers) =
            if let Some(enforced_degree_bounds) = enforced_degree_bounds.as_ref() {
                if enforced_degree_bounds.is_empty() {
                    (None, None)
                } else {
                    let lowest_shifted_power =
                        max_degree - enforced_degree_bounds.last().ok_or(Error::EmptyDegreeBounds)?;

                    let shifted_ck_time = start_timer!(|| format!(
                        "Constructing `shifted_powers` of size {}",
                        max_degree - lowest_shifted_power + 1
                    ));

                    let shifted_powers = pp.powers_of_g[lowest_shifted_power..].to_vec();
                    end_timer!(shifted_ck_time);

                    let degree_bounds_and_shift_powers = enforced_degree_bounds
                        .iter()
                        .map(|d| (*d, pp.powers_of_g[max_degree - d]))
                        .collect();
                    (Some(shifted_powers), Some(degree_bounds_and_shift_powers))
                }
            } else {
                (None, None)
            };

        let ck = CommitterKey {
            powers,
            shifted_powers,
            powers_of_gamma_g,
            enforced_degree_bounds,
            max_degree,
        };

        let vk = VerifierKey {
            vk,
            degree_bounds_and_shift_powers,
            supported_degree,
            max_degree,
        };
        Ok((ck, vk))
    }
// TODO: should trim also take in the hiding_bounds? That way we don't
// have to store many powers of gamma_g.
// TODO: add an optional hiding_bound.
should trim also take in the hiding_bounds. That way we don't
have to store many powers of gamma_g.
TODO: add an optional hiding_bound.
should trim also take in the hiding_bounds . That way we don ' t have to store many powers of gamma_g . TODO : add an optional hiding_bound .
fn trim(
        pp: &Self::UniversalParams,
        supported_degree: usize,
        enforced_degree_bounds: Option<&[usize]>,
    ) -> Result<(Self::CommitterKey, Self::VerifierKey), Self::Error> {
        let max_degree = pp.max_degree();
        if supported_degree > max_degree {
            return Err(Error::TrimmingDegreeTooLarge);
        }
        // Construct the KZG10 committer key for committing to unshifted polynomials.
        let ck_time =
            start_timer!(|| format!("Constructing `powers` of size {} for unshifted polys", supported_degree));
        let powers = pp.powers_of_g[..=supported_degree].to_vec();
        // We want to support making up to supported_degree queries to committed
        // polynomials.
        let powers_of_gamma_g = pp.powers_of_gamma_g[..=(supported_degree + 1)].to_vec();
        end_timer!(ck_time);
        // Construct the core KZG10 verifier key.
        let vk = kzg10::VerifierKey {
            g: pp.powers_of_g[0],
            gamma_g: pp.powers_of_gamma_g[0],
            h: pp.h,
            beta_h: pp.beta_h,
            prepared_h: pp.prepared_h.clone(),
            prepared_beta_h: pp.prepared_beta_h.clone(),
        };
        let enforced_degree_bounds = enforced_degree_bounds.map(|v| {
            let mut v = v.to_vec();
            v.sort();
            v.dedup();
            v
        });
        // Check whether we have some degree bounds to enforce
        let (shifted_powers, degree_bounds_and_shift_powers) =
            if let Some(enforced_degree_bounds) = enforced_degree_bounds.as_ref() {
                if enforced_degree_bounds.is_empty() {
                    (None, None)
                } else {
                    let lowest_shifted_power =
                        max_degree - enforced_degree_bounds.last().ok_or(Error::EmptyDegreeBounds)?;
                    let shifted_ck_time = start_timer!(|| format!(
                        "Constructing `shifted_powers` of size {}",
                        max_degree - lowest_shifted_power + 1
                    ));
                    let shifted_powers = pp.powers_of_g[lowest_shifted_power..].to_vec();
                    end_timer!(shifted_ck_time);
                    let degree_bounds_and_shift_powers = enforced_degree_bounds
                        .iter()
                        .map(|d| (*d, pp.powers_of_g[max_degree - d]))
                        .collect();
                    (Some(shifted_powers), Some(degree_bounds_and_shift_powers))
                }
            } else {
                (None, None)
            };
        let ck = CommitterKey {
            powers,
            shifted_powers,
            powers_of_gamma_g,
            enforced_degree_bounds,
            max_degree,
        };
        let vk = VerifierKey {
            vk,
            degree_bounds_and_shift_powers,
            supported_degree,
            max_degree,
        };
        Ok((ck, vk))
    }
fn trim ( pp : & Self :: UniversalParams , supported_degree : usize , enforced_degree_bounds : Option < & [ usize ] > , ) -> Result < ( Self :: CommitterKey , Self :: VerifierKey ) , Self :: Error > { let max_degree = pp . max_degree ( ) ; if supported_degree > max_degree { return Err ( Error :: TrimmingDegreeTooLarge ) ; } // Construct the KZG10 committer key for committing to unshifted polynomials. let ck_time = start_timer ! ( format ( " " supported_degree ) ) ; let powers = pp . powers_of_g [ .. = supported_degree ] . to_vec ( ) ; // We want to support making up to supported_degree queries to committed // polynomials. let powers_of_gamma_g = pp . powers_of_gamma_g [ .. = ( supported_degree + 1 ) ] . to_vec ( ) ; end_timer ! ( ck_time ) ; // Construct the core KZG10 verifier key. let vk = kzg10 :: VerifierKey { g : pp . powers_of_g [ 0 ] , gamma_g : pp . powers_of_gamma_g [ 0 ] , h : pp . h , beta_h : pp . beta_h , prepared_h : pp . prepared_h . clone ( ) , prepared_beta_h : pp . prepared_beta_h . clone ( ) , } ; let enforced_degree_bounds = enforced_degree_bounds . map ( | v | { let mut v = v . to_vec ( ) ; v . sort ( ) ; v . dedup ( ) ; v } ) ; // Check whether we have some degree bounds to enforce let ( shifted_powers , degree_bounds_and_shift_powers ) = if let Some ( enforced_degree_bounds ) = enforced_degree_bounds . as_ref ( ) { if enforced_degree_bounds . is_empty ( ) { ( None , None ) } else { let lowest_shifted_power = max_degree - enforced_degree_bounds . last ( ) . ok_or ( Error :: EmptyDegreeBounds ) ? ; let shifted_ck_time = start_timer ! ( format ( " " max_degree lowest_shifted_power 1 ) ) ; let shifted_powers = pp . powers_of_g [ lowest_shifted_power .. ] . to_vec ( ) ; end_timer ! ( shifted_ck_time ) ; let degree_bounds_and_shift_powers = enforced_degree_bounds . iter ( ) . map ( | d | ( * d , pp . powers_of_g [ max_degree - d ] ) ) . collect ( ) ; ( Some ( shifted_powers ) , Some ( degree_bounds_and_shift_powers ) ) } } else { ( None , None ) } ; let ck = CommitterKey { powers , shifted_powers , powers_of_gamma_g , enforced_degree_bounds , max_degree , } ; let vk = VerifierKey { vk , degree_bounds_and_shift_powers , supported_degree , max_degree , } ; Ok ( ( ck , vk ) ) }
TODO: should trim also take in the hiding_bounds?
TODO : should trim also take in the hiding_bounds?
pp
&Self::UniversalParams
supported_degree
usize
enforced_degree_bounds
Option<&[usize]>
pp
&Self::UniversalParams
supported_degree
usize
enforced_degree_bounds
Option<&[usize]>