Skip to content

Commit

Permalink
Merge pull request #7 from scroll-tech/matthias/make-clippy-happy
Browse files Browse the repository at this point in the history
Make clippy happy
  • Loading branch information
matthiasgoergens authored Oct 23, 2024
2 parents 6bc33af + 90068ec commit c6e1140
Show file tree
Hide file tree
Showing 12 changed files with 244 additions and 333 deletions.
6 changes: 3 additions & 3 deletions NOTICE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
This repository includes the following third-party open-source code.

* The code in `src/scalar/ristretto255.rs` is derived from [bls12-381](https://github.com/zkcrypto/bls12_381).
* The code in `src/scalar/ristretto255.rs` is derived from [bls12-381](https://github.com/zkcrypto/bls12_381).
Specifically, from [src/bls12_381/scalar.rs](https://github.com/zkcrypto/bls12_381/blob/master/src/scalar.rs) and [src/bls12_381/util.rs](https://github.com/zkcrypto/bls12_381/blob/master/src/util.rs), which has the following copyright and license.

Permission is hereby granted, free of charge, to any
Expand Down Expand Up @@ -41,7 +41,7 @@ Specifically, from [src/bls12_381/scalar.rs](https://github.com/zkcrypto/bls12_3
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

========================================================================

Expand Down Expand Up @@ -70,4 +70,4 @@ Specifically, from [src/bls12_381/scalar.rs](https://github.com/zkcrypto/bls12_3

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1 change: 1 addition & 0 deletions examples/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ struct CompileTimeKnowledge {
block_num_vir_ops: Vec<usize>,
max_ts_width: usize,

#[allow(clippy::type_complexity)]
args: Vec<
Vec<(
Vec<(usize, [u8; 32])>,
Expand Down
32 changes: 16 additions & 16 deletions src/custom_dense_mlpoly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ pub fn rev_bits(q: usize, max_num_proofs: usize) -> usize {
(0..max_num_proofs.log_2())
.rev()
.map(|i| q / (i.pow2()) % 2 * (max_num_proofs / i.pow2() / 2))
.fold(0, |a, b| a + b)
.sum::<usize>()
}

impl DensePolynomialPqx {
// Assume z_mat is of form (p, q_rev, x), construct DensePoly
pub fn new(
z_mat: &Vec<Vec<Vec<Vec<Scalar>>>>,
z_mat: Vec<Vec<Vec<Vec<Scalar>>>>,
num_proofs: Vec<usize>,
max_num_proofs: usize,
num_inputs: Vec<usize>,
Expand All @@ -58,14 +58,14 @@ impl DensePolynomialPqx {
num_witness_secs,
num_inputs,
max_num_inputs,
Z: z_mat.clone(),
Z: z_mat,
}
}

// Assume z_mat is in its standard form of (p, q, x)
// Reverse q and x and convert it to (p, q_rev, x_rev)
pub fn new_rev(
z_mat: &Vec<Vec<Vec<Vec<Scalar>>>>,
z_mat: Vec<Vec<Vec<Vec<Scalar>>>>,
num_proofs: Vec<usize>,
max_num_proofs: usize,
num_inputs: Vec<usize>,
Expand Down Expand Up @@ -111,7 +111,7 @@ impl DensePolynomialPqx {
}

pub fn len(&self) -> usize {
return self.num_instances * self.max_num_proofs * self.max_num_inputs;
self.num_instances * self.max_num_proofs * self.max_num_inputs
}

// Given (p, q_rev, x_rev) return Z[p][q_rev][x_rev]
Expand All @@ -121,9 +121,9 @@ impl DensePolynomialPqx {
&& w < self.Z[p][q_rev].len()
&& x_rev < self.Z[p][q_rev][w].len()
{
return self.Z[p][q_rev][w][x_rev];
self.Z[p][q_rev][w][x_rev]
} else {
return ZERO;
ZERO
}
}

Expand All @@ -137,31 +137,31 @@ impl DensePolynomialPqx {
match mode {
MODE_P => {
if p + self.num_instances / 2 < self.Z.len() {
return self.Z[p + self.num_instances / 2][q_rev][w][x_rev];
self.Z[p + self.num_instances / 2][q_rev][w][x_rev]
} else {
return ZERO;
ZERO
}
}
MODE_Q => {
return if self.num_proofs[p] == 1 {
if self.num_proofs[p] == 1 {
ZERO
} else {
self.Z[p][q_rev + self.num_proofs[p] / 2][w][x_rev]
};
}
}
MODE_W => {
if w + self.num_witness_secs / 2 < self.Z[p][q_rev].len() {
return self.Z[p][q_rev][w + self.num_witness_secs / 2][x_rev];
self.Z[p][q_rev][w + self.num_witness_secs / 2][x_rev]
} else {
return ZERO;
ZERO
}
}
MODE_X => {
return if self.num_inputs[p] == 1 {
if self.num_inputs[p] == 1 {
ZERO
} else {
self.Z[p][q_rev][w][x_rev + self.num_inputs[p] / 2]
};
}
}
_ => {
panic!(
Expand Down Expand Up @@ -329,7 +329,7 @@ impl DensePolynomialPqx {
cl.bound_poly_vars_rw(r_w);
cl.bound_poly_vars_rq(r_q);
cl.bound_poly_vars_rp(r_p);
return cl.index(0, 0, 0, 0);
cl.index(0, 0, 0, 0)
}

// Convert to a (p, q_rev, x_rev) regular dense poly of form (p, q, x)
Expand Down
66 changes: 33 additions & 33 deletions src/dense_mlpoly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,17 +283,17 @@ impl DensePolynomial {
cons_len: usize,
proof_len: usize,
instance_len: usize,
num_proofs: &Vec<usize>,
num_proofs: &[usize],
) {
let n = self.len() / 2;
assert_eq!(n, cons_len * proof_len * instance_len);

for p in 0..instance_len {
for (p, &num_proof) in num_proofs.iter().enumerate() {
// Certain p, q combinations within the boolean hypercube always evaluate to 0
let max_q = if proof_len != proof_space {
proof_len
} else {
num_proofs[p]
num_proof
};
for q in 0..max_q {
for x in 0..cons_len {
Expand All @@ -311,7 +311,7 @@ impl DensePolynomial {
// Use "num_proofs" to record how many "q"s need to process for each "p"
pub fn bound_poly_var_front_rq(
&mut self,
r_q: &Vec<Scalar>,
r_q: &[Scalar],
mut max_proof_space: usize,
instance_space: usize,
cons_space: usize,
Expand All @@ -324,16 +324,16 @@ impl DensePolynomial {
n /= 2;
max_proof_space /= 2;

for p in 0..instance_space {
if num_proofs[p] == 1 {
for (p, num_proof) in num_proofs.iter_mut().enumerate() {
if *num_proof == 1 {
// q = 0
for x in 0..cons_space {
let i = p * cons_space + x;
self.Z[i] = (Scalar::one() - r) * self.Z[i];
}
} else {
num_proofs[p] /= 2;
let step = max_proof_space / num_proofs[p];
*num_proof /= 2;
let step = max_proof_space / *num_proof;
for q in (0..max_proof_space).step_by(step) {
for x in 0..cons_space {
let i = q * instance_space * cons_space + p * cons_space + x;
Expand Down Expand Up @@ -606,7 +606,7 @@ impl PolyEvalProof {
random_tape,
&LZ,
&LZ_blind,
&R,
R,
&Zc_list[i],
blind_Zr,
);
Expand All @@ -622,7 +622,7 @@ impl PolyEvalProof {
}

pub fn verify_plain_batched_points(
proof_list: &Vec<PolyEvalProof>,
proof_list: &[PolyEvalProof],
gens: &PolyCommitmentGens,
transcript: &mut Transcript,
r_list: Vec<Vec<Scalar>>, // point at which the polynomial is evaluated
Expand Down Expand Up @@ -678,7 +678,7 @@ impl PolyEvalProof {

proof_list[i]
.proof
.verify(R.len(), &gens.gens, transcript, &R, &C_LZ, &C_Zc)?
.verify(R.len(), &gens.gens, transcript, R, &C_LZ, &C_Zc)?
}

Ok(())
Expand All @@ -687,10 +687,10 @@ impl PolyEvalProof {
// Evaluation on multiple instances, each at different point
// Size of each instance might be different, but all are larger than the evaluation point
pub fn prove_batched_instances(
poly_list: &Vec<DensePolynomial>, // list of instances
poly_list: &[DensePolynomial], // list of instances
blinds_opt: Option<&PolyCommitmentBlinds>,
r_list: Vec<&Vec<Scalar>>, // point at which the polynomial is evaluated
Zr_list: &Vec<Scalar>, // evaluation of \widetilde{Z}(r) on each instance
Zr_list: &[Scalar], // evaluation of \widetilde{Z}(r) on each instance
blind_Zr_opt: Option<&Scalar>, // specifies a blind for Zr
gens: &PolyCommitmentGens,
transcript: &mut Transcript,
Expand Down Expand Up @@ -780,13 +780,13 @@ impl PolyEvalProof {
}

pub fn verify_plain_batched_instances(
proof_list: &Vec<PolyEvalProof>,
proof_list: &[PolyEvalProof],
gens: &PolyCommitmentGens,
transcript: &mut Transcript,
r_list: Vec<&Vec<Scalar>>, // point at which the polynomial is evaluated
Zr_list: &Vec<Scalar>, // commitment to \widetilde{Z}(r) of each instance
comm_list: &Vec<PolyCommitment>, // commitment of each instance
num_vars_list: &Vec<usize>, // size of each polynomial
Zr_list: &[Scalar], // commitment to \widetilde{Z}(r) of each instance
comm_list: &[PolyCommitment], // commitment of each instance
num_vars_list: &[usize], // size of each polynomial
) -> Result<(), ProofVerifyError> {
transcript.append_protocol_name(PolyEvalProof::protocol_name());
assert_eq!(comm_list.len(), r_list.len());
Expand Down Expand Up @@ -859,13 +859,13 @@ impl PolyEvalProof {
// Like prove_batched_instances, but r is divided into rq ++ ry
// Each polynomial is supplemented with num_proofs and num_inputs
pub fn prove_batched_instances_disjoint_rounds(
poly_list: &Vec<&DensePolynomial>,
num_proofs_list: &Vec<usize>,
num_inputs_list: &Vec<usize>,
poly_list: &[&DensePolynomial],
num_proofs_list: &[usize],
num_inputs_list: &[usize],
blinds_opt: Option<&PolyCommitmentBlinds>,
rq: &[Scalar],
ry: &[Scalar],
Zr_list: &Vec<Scalar>,
Zr_list: &[Scalar],
blind_Zr_opt: Option<&Scalar>,
gens: &PolyCommitmentGens,
transcript: &mut Transcript,
Expand Down Expand Up @@ -893,7 +893,7 @@ impl PolyEvalProof {
if let Some(index) = index_map.get(&(num_proofs, num_inputs)) {
c *= c_base;
let L = &L_list[*index].to_vec();
let LZ = poly.bound(&L);
let LZ = poly.bound(L);
LZ_list[*index] = (0..LZ.len())
.map(|j| LZ_list[*index][j] + c * LZ[j])
.collect();
Expand Down Expand Up @@ -960,15 +960,15 @@ impl PolyEvalProof {
}

pub fn verify_batched_instances_disjoint_rounds(
proof_list: &Vec<PolyEvalProof>,
num_proofs_list: &Vec<usize>,
num_inputs_list: &Vec<usize>,
proof_list: &[PolyEvalProof],
num_proofs_list: &[usize],
num_inputs_list: &[usize],
gens: &PolyCommitmentGens,
transcript: &mut Transcript,
rq: &[Scalar],
ry: &[Scalar],
Zr_list: &Vec<RistrettoPoint>,
comm_list: &Vec<&PolyCommitment>,
Zr_list: &[RistrettoPoint],
comm_list: &[&PolyCommitment],
) -> Result<(), ProofVerifyError> {
transcript.append_protocol_name(PolyEvalProof::protocol_name());

Expand Down Expand Up @@ -1045,8 +1045,8 @@ impl PolyEvalProof {
// Treat the polynomial(s) as univariate and open on a single point
pub fn prove_uni_batched_instances(
poly_list: &Vec<&DensePolynomial>,
r: &Scalar, // point at which the polynomial is evaluated
Zr: &Vec<Scalar>, // evaluation of \widetilde{Z}(r)
r: &Scalar, // point at which the polynomial is evaluated
Zr: &[Scalar], // evaluation of \widetilde{Z}(r)
gens: &PolyCommitmentGens,
transcript: &mut Transcript,
random_tape: &mut RandomTape,
Expand Down Expand Up @@ -1106,7 +1106,7 @@ impl PolyEvalProof {
L_map.get(&num_vars).unwrap()
};

let LZ = poly.bound(&L);
let LZ = poly.bound(L);
LZ_comb = (0..R_size)
.map(|i| LZ_comb[i] + if i < LZ.len() { c * LZ[i] } else { zero })
.collect();
Expand All @@ -1133,9 +1133,9 @@ impl PolyEvalProof {
&self,
gens: &PolyCommitmentGens,
transcript: &mut Transcript,
r: &Scalar, // point at which the polynomial is evaluated
C_Zr: &Vec<RistrettoPoint>, // commitment to \widetilde{Z}(r)
comm_list: &Vec<&PolyCommitment>,
r: &Scalar, // point at which the polynomial is evaluated
C_Zr: &[RistrettoPoint], // commitment to \widetilde{Z}(r)
comm_list: &[&PolyCommitment],
poly_size: Vec<usize>,
) -> Result<(), ProofVerifyError> {
transcript.append_protocol_name(PolyEvalProof::protocol_name());
Expand Down
Loading

0 comments on commit c6e1140

Please sign in to comment.