halo2 icon indicating copy to clipboard operation
halo2 copied to clipboard

Discussion: Replace instances slice type for proving/verifying for Vec

Open ed255 opened this issue 1 year ago • 0 comments

Currently the API for proving/verifying receives the instances as: https://github.com/privacy-scaling-explorations/halo2/blob/73408a140737d8336490452193b21f5a7a94e7de/halo2_proofs/src/plonk/prover.rs#L49

I think that the only way to have this type is to create a vector of slices, take it as slice, and create another vector of that, and take it as slice. So we end up creating 2 vectors just to get this type. Why not pass a slice of vectors instead? It would simplify the interaction with the proving/verifying API.

Here's an example of the gymnastics that need to be done to create 1 proof:

    let instances = circuit.instances(); // This is `Vec<Vec<F>>`
    let instances_slice: &[&[Fr]] = &(instances
        .iter()
        .map(|instance| instance.as_slice())
        .collect::<Vec<_>>()); // We already had a vector, but we need to create another one to hold slices instead of Vec :(

    create_proof::<KZGCommitmentScheme<Bn256>, ProverSHPLONK<'_, Bn256>, _, _, _, _>(
        &params,
        &pk,
        &[circuit],
        &[instances_slice],
        &mut rng,
        &mut transcript,
    )
    .expect("proof generation should not fail");

I would propose to use change the API to use:

    instances: &[Vec<Vec<Scheme::Scalar>>],

NOTE: If we apply this change on the legacy API, we will have a breaking change, so I suggest keeping the legacy API as it is. But we can do this change on the frontend-backend split API!

ed255 avatar Feb 02 '24 11:02 ed255