Missing tests

As public inputs for proofs verified by the universal batch verifier are padded with zero, Finding ref would have been caught by a test case where a proof in the batch has no public inputs. However, the code-sampling test cases did not cover this edge case (extract from circuits/src/batch_verify/universal/types.rs):

/// Samples a [`UniversalBatchVerifierInput`] for `config`.
pub fn sample<R>(config: &UniversalBatchVerifierConfig, rng: &mut R) -> Self
where
    R: RngCore + ?Sized,
{
    let num_public_inputs = config.max_num_public_inputs as usize;
    let length = rng.gen_range(1..=num_public_inputs);
    let (proofs_and_inputs, vk) = sample_proofs_inputs_vk(length, 1, rng);
    let (proof, inputs) = proofs_and_inputs[0].clone();

    assert!(length > 0);
    assert!(length + 1 == vk.s.len());
    assert!(length == inputs.0.len());

    Self { vk, proof, inputs }
}

As can be seen here, only cases with at least one public input are tested. We recommend to change rng.gen_range(1..=num_public_inputs); to rng.gen_range(0..=num_public_inputs); to also cover the case of no public inputs.

Testing only with randomly generated inputs generated as above may miss special edge-case values with low density such as a public input being zero (a random field element is extremely unlikely to be zero) or parameters occurring more than once. We thus recommend to also include test cases with such human-defined edge cases.

Testing for all public inputs being zero was added in commits , , and .

Zellic © 2024Back to top ↑