poly_commitment/
pbt_srs.rs

1//! This module defines Property-based tests for the SRS trait.
2//! It includes tests regarding methods the SRS trait should implement.
3//! It aims to verify the implementation respects the properties described in
4//! the documentation of the methods.
5
6use ark_ff::Zero;
7use ark_poly::{univariate::DensePolynomial, DenseUVPolynomial};
8use rand::Rng;
9
10use crate::{commitment::CommitmentCurve, SRS};
11
12// Testing how many chunks are generated with different polynomial sizes and
13// different number of chunks requested.
14pub fn test_regression_commit_non_hiding_expected_number_of_chunks<
15    G: CommitmentCurve,
16    Srs: SRS<G>,
17>() {
18    let mut rng = &mut o1_utils::tests::make_test_rng(None);
19    // maximum random srs size is 64
20    let log2_srs_size = rng.gen_range(1..6);
21    let srs_size = 1 << log2_srs_size;
22    let srs = Srs::create(srs_size);
23
24    // If we have a polynomial of the size of the SRS (i.e. of degree `srs_size -
25    // 1`), and we request 1 chunk, we should get 1 chunk.
26    {
27        // srs_size is the number of evaluation degree
28        let poly_degree = srs_size - 1;
29        let poly = DensePolynomial::<G::ScalarField>::rand(poly_degree, &mut rng);
30        let commitment = srs.commit_non_hiding(&poly, 1);
31        assert_eq!(commitment.len(), 1);
32    }
33
34    // If we have a polynomial of the size of the SRS (i.e. of degree `srs_size -
35    // 1`), and we request k chunks (k > 1), we should get k chunk.
36    {
37        // srs_size is the number of evaluation degree
38        let poly_degree = srs_size - 1;
39        // maximum 10 chunks for the test
40        let k = rng.gen_range(2..10);
41        let poly = DensePolynomial::<G::ScalarField>::rand(poly_degree, &mut rng);
42        let commitment = srs.commit_non_hiding(&poly, k);
43        assert_eq!(commitment.len(), k);
44    }
45
46    // Same than the two previous cases, but with the special polynomial equals to zero.
47    {
48        let k = rng.gen_range(1..10);
49        let poly = DensePolynomial::<G::ScalarField>::zero();
50        let commitment = srs.commit_non_hiding(&poly, k);
51        assert_eq!(commitment.len(), k);
52    }
53
54    // Polynomial of exactly a multiple of the SRS size, i.e degree is k *
55    // srs_size - 1.
56    {
57        let k = rng.gen_range(2..5);
58        let poly_degree = k * srs_size - 1;
59        let poly = DensePolynomial::<G::ScalarField>::rand(poly_degree, &mut rng);
60        // if we request a number of chunks smaller than the multiple, we will
61        // still get a number of chunks equals to the multiple.
62        let requested_num_chunks = rng.gen_range(1..k);
63        let commitment = srs.commit_non_hiding(&poly, requested_num_chunks);
64        assert_eq!(commitment.len(), k);
65
66        // if we request a number of chunks equals to the multiple, we will get
67        // the exact number of chunks.
68        let commitment = srs.commit_non_hiding(&poly, k);
69        assert_eq!(commitment.len(), k);
70
71        // if we request a number of chunks greater than the multiple, we will
72        // get the exact number of chunks requested.
73        let requested_num_chunks = rng.gen_range(k + 1..10);
74        let commitment = srs.commit_non_hiding(&poly, requested_num_chunks);
75        assert_eq!(commitment.len(), requested_num_chunks);
76    }
77}