filecoin-project / bellperson

zk-SNARK library
Other
186 stars 118 forks source link

I have a question about MappedParameters #131

Closed Xib1uvXi closed 1 year ago

Xib1uvXi commented 3 years ago

git log: 33e5d2ad27c0967fcccea5ffd59ae4970e346518

src/groth16/prover.rs line 380

    // snip
   //  line 380
    let h_s = a_s
        .into_iter()
        .map(|a| {
            let h = multiexp(
                &worker,
                params.get_h(a.len())?,            //   I found that a.len() is not really used here
                FullDensity,
                a,
                &mut multiexp_kern,
            );
            Ok(h)
        })
        .collect::<Result<Vec<_>, SynthesisError>>()?;

src/groth16/mapped_params.rs line 59


    fn get_h(&self, _num_h: usize) -> Result<Self::G1Builder, SynthesisError> {
        let builder = self
            .h
            .iter()
            .cloned()
            .map(|h| read_g1::<E>(&self.params, h, self.checked))
            .collect::<Result<_, _>>()?;

        Ok((Arc::new(builder), 0))
    }

Does this mean that the logic of get_h can be optimized, without having to create a new builder every time

vmx commented 1 year ago

This looks correct. Though the code has changed since then, and now we call get_h() only once outside the loop. So it's kind of the optimization you proposed.