Skip to content

Commit 1f4108a

Browse files
committed
Code improvement
1 parent 19b03e9 commit 1f4108a

File tree

9 files changed

+64
-99
lines changed

9 files changed

+64
-99
lines changed

spartan_parallel/src/dense_mlpoly.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1000,7 +1000,7 @@ impl<S: SpartanExtensionField> PolyEvalProof<S> {
10001000

10011001
for i in 0..poly_size.len() {
10021002
let num_vars = poly_size[i].next_power_of_two().log_2();
1003-
let L = if let Some(L) = L_map.get(&num_vars) {
1003+
let _L = if let Some(L) = L_map.get(&num_vars) {
10041004
L
10051005
} else {
10061006
let (left_num_vars, right_num_vars) = EqPolynomial::<S>::compute_factored_lens(num_vars);

spartan_parallel/src/nizk/mod.rs

Lines changed: 56 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::scalar::SpartanExtensionField;
44
use super::errors::ProofVerifyError;
55
use super::math::Math;
66
use super::random::RandomTape;
7-
use super::transcript::{AppendToTranscript, ProofTranscript};
7+
use super::transcript::ProofTranscript;
88
use merlin::Transcript;
99
use serde::{Deserialize, Serialize};
1010
mod bullet;
@@ -45,12 +45,15 @@ impl<S: SpartanExtensionField> KnowledgeProof<S> {
4545
}
4646

4747
pub fn verify(&self, transcript: &mut Transcript) -> Result<(), ProofVerifyError> {
48-
<Transcript as ProofTranscript<S>>::append_protocol_name(
49-
transcript,
50-
KnowledgeProof::<S>::protocol_name(),
51-
);
52-
53-
let c: S = transcript.challenge_scalar(b"c");
48+
// Transcript operations to preserve consistency for the verify function
49+
{
50+
<Transcript as ProofTranscript<S>>::append_protocol_name(
51+
transcript,
52+
KnowledgeProof::<S>::protocol_name(),
53+
);
54+
55+
let _c: S = transcript.challenge_scalar(b"c");
56+
}
5457

5558
// TODO: Alternative PCS Verification
5659
Ok(())
@@ -89,12 +92,15 @@ impl<S: SpartanExtensionField> EqualityProof<S> {
8992
}
9093

9194
pub fn verify(&self, transcript: &mut Transcript) -> Result<(), ProofVerifyError> {
92-
<Transcript as ProofTranscript<S>>::append_protocol_name(
93-
transcript,
94-
EqualityProof::<S>::protocol_name(),
95-
);
96-
97-
let c: S = transcript.challenge_scalar(b"c");
95+
// Transcript operations to preserve consistency for the verify function
96+
{
97+
<Transcript as ProofTranscript<S>>::append_protocol_name(
98+
transcript,
99+
EqualityProof::<S>::protocol_name(),
100+
);
101+
102+
let _c: S = transcript.challenge_scalar(b"c");
103+
}
98104

99105
// TODO: Alternative PCS Verification
100106
Ok(())
@@ -145,18 +151,21 @@ impl<S: SpartanExtensionField> ProductProof<S> {
145151
ProductProof { z }
146152
}
147153

148-
fn check_equality(_c: &S, _z1: &S, _z2: &S) -> bool {
154+
fn _check_equality(_c: &S, _z1: &S, _z2: &S) -> bool {
149155
// TODO: Alternative PCS Verification
150156
true
151157
}
152158

153159
pub fn verify(&self, transcript: &mut Transcript) -> Result<(), ProofVerifyError> {
154-
<Transcript as ProofTranscript<S>>::append_protocol_name(
155-
transcript,
156-
ProductProof::<S>::protocol_name(),
157-
);
158-
159-
let c: S = transcript.challenge_scalar(b"c");
160+
// Transcript operations to preserve consistency for the verify function
161+
{
162+
<Transcript as ProofTranscript<S>>::append_protocol_name(
163+
transcript,
164+
ProductProof::<S>::protocol_name(),
165+
);
166+
167+
let _c: S = transcript.challenge_scalar(b"c");
168+
}
160169

161170
// TODO: Alternative PCS Verification
162171
Ok(())
@@ -218,12 +227,15 @@ impl<S: SpartanExtensionField> DotProductProof<S> {
218227
}
219228

220229
pub fn verify(&self, transcript: &mut Transcript, a: &[S]) -> Result<(), ProofVerifyError> {
221-
<Transcript as ProofTranscript<S>>::append_protocol_name(
222-
transcript,
223-
DotProductProof::<S>::protocol_name(),
224-
);
225-
S::append_field_vector_to_transcript(b"a", transcript, a);
226-
let c: S = transcript.challenge_scalar(b"c");
230+
// Transcript operations to preserve consistency for the verify function
231+
{
232+
<Transcript as ProofTranscript<S>>::append_protocol_name(
233+
transcript,
234+
DotProductProof::<S>::protocol_name(),
235+
);
236+
S::append_field_vector_to_transcript(b"a", transcript, a);
237+
let _c: S = transcript.challenge_scalar(b"c");
238+
}
227239

228240
let _dotproduct_z_a = DotProductProof::compute_dotproduct(&self.z, a);
229241

@@ -304,26 +316,29 @@ impl<S: SpartanExtensionField> DotProductProofLog<S> {
304316
) -> Result<(), ProofVerifyError> {
305317
assert_eq!(a.len(), n);
306318

307-
<Transcript as ProofTranscript<S>>::append_protocol_name(
308-
transcript,
309-
DotProductProofLog::<S>::protocol_name(),
310-
);
319+
// Transcript operations to preserve consistency for the verify function
320+
{
321+
<Transcript as ProofTranscript<S>>::append_protocol_name(
322+
transcript,
323+
DotProductProofLog::<S>::protocol_name(),
324+
);
311325

312-
S::append_field_vector_to_transcript(b"a", transcript, a);
326+
S::append_field_vector_to_transcript(b"a", transcript, a);
313327

314-
// sample a random base and scale the generator used for
315-
// the output of the inner product
316-
let r: S = transcript.challenge_scalar(b"r");
328+
// sample a random base and scale the generator used for
329+
// the output of the inner product
330+
let _r: S = transcript.challenge_scalar(b"r");
317331

318-
// BulletReductionProof - verification_scalars
319-
let mut m = a.len();
320-
while m != 1 {
321-
m /= 2;
332+
// BulletReductionProof - verification_scalars
333+
let mut m = a.len();
334+
while m != 1 {
335+
m /= 2;
322336

323-
let u: S = transcript.challenge_scalar(b"u");
324-
}
337+
let _u: S = transcript.challenge_scalar(b"u");
338+
}
325339

326-
let c: S = transcript.challenge_scalar(b"c");
340+
let _c: S = transcript.challenge_scalar(b"c");
341+
}
327342

328343
// TODO: Alternative PCS Verification
329344
Ok(())

spartan_parallel/src/product_tree.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use crate::scalar::SpartanExtensionField;
44
use super::dense_mlpoly::DensePolynomial;
55
use super::dense_mlpoly::EqPolynomial;
66
use super::math::Math;
7-
use super::scalar::Scalar;
87
use super::sumcheck::SumcheckInstanceProof;
98
use super::transcript::ProofTranscript;
109
use merlin::Transcript;

spartan_parallel/src/r1csproof.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ impl<S: SpartanExtensionField> R1CSProof<S> {
485485
// So we need to multiply each entry by (1 - rq0)(1 - rq1)
486486
let mut eval_vars_comb_list = Vec::new();
487487
for p in 0..num_instances {
488-
let wit_sec_p = |i: usize| {
488+
let _wit_sec_p = |i: usize| {
489489
if witness_secs[i].w_mat.len() == 1 {
490490
0
491491
} else {

spartan_parallel/src/scalar/fp.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use super::SpartanExtensionField;
2-
use crate::{AppendToTranscript, ProofTranscript, Transcript};
2+
use crate::{ProofTranscript, Transcript};
33
use ceno_goldilocks::Goldilocks;
44
use core::borrow::Borrow;
55
use core::iter::{Product, Sum};

spartan_parallel/src/scalar/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use ceno_goldilocks::ExtensionField;
55
use ff::Field;
66
pub use fp::Scalar;
77
pub use fp2::ScalarExt2;
8+
use merlin::Transcript;
89
use rand::{CryptoRng, RngCore};
910
use serde::Serialize;
1011
use std::fmt;
@@ -17,9 +18,6 @@ use std::{
1718
use subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption};
1819
use zeroize::Zeroize;
1920

20-
use crate::transcript::AppendToTranscript;
21-
use merlin::Transcript;
22-
2321
/// Trait describing the field element
2422
/// Wraps around Goldilocks field towers from ceno-goldilocks
2523
/// See: https://github.com/scroll-tech/ceno-Goldilocks

spartan_parallel/src/sparse_mlpoly.rs

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ impl<S: SpartanExtensionField> SparseMatPolynomial<S> {
390390
.collect::<Vec<S>>()
391391
}
392392

393-
pub fn multiply_vec(&self, num_rows: usize, num_cols: usize, z: &[S]) -> Vec<S> {
393+
pub fn _multiply_vec(&self, num_rows: usize, num_cols: usize, z: &[S]) -> Vec<S> {
394394
assert_eq!(z.len(), num_cols);
395395

396396
(0..self.M.len())
@@ -1472,53 +1472,6 @@ impl<S: SpartanExtensionField> SparseMatPolyEvalProof<S> {
14721472
}
14731473
}
14741474

1475-
pub struct SparsePolyEntry<S: SpartanExtensionField> {
1476-
pub idx: usize,
1477-
pub val: S,
1478-
}
1479-
1480-
impl<S: SpartanExtensionField> SparsePolyEntry<S> {
1481-
pub fn new(idx: usize, val: S) -> Self {
1482-
SparsePolyEntry { idx, val }
1483-
}
1484-
}
1485-
1486-
pub struct SparsePolynomial<S: SpartanExtensionField> {
1487-
num_vars: usize,
1488-
Z: Vec<SparsePolyEntry<S>>,
1489-
}
1490-
1491-
impl<S: SpartanExtensionField> SparsePolynomial<S> {
1492-
pub fn new(num_vars: usize, Z: Vec<SparsePolyEntry<S>>) -> Self {
1493-
SparsePolynomial { num_vars, Z }
1494-
}
1495-
1496-
fn compute_chi(a: &[bool], r: &[S]) -> S {
1497-
assert_eq!(a.len(), r.len());
1498-
let mut chi_i = S::field_one();
1499-
for j in 0..r.len() {
1500-
if a[j] {
1501-
chi_i = chi_i * r[j];
1502-
} else {
1503-
chi_i = chi_i * (S::field_one() - r[j]);
1504-
}
1505-
}
1506-
chi_i
1507-
}
1508-
1509-
// Takes O(n log n). TODO: do this in O(n) where n is the number of entries in Z
1510-
pub fn evaluate(&self, r: &[S]) -> S {
1511-
assert_eq!(self.num_vars, r.len());
1512-
1513-
(0..self.Z.len())
1514-
.map(|i| {
1515-
let bits = self.Z[i].idx.get_bits(r.len());
1516-
SparsePolynomial::compute_chi(&bits, r) * self.Z[i].val
1517-
})
1518-
.sum()
1519-
}
1520-
}
1521-
15221475
#[cfg(test)]
15231476
mod tests {
15241477
use super::*;

spartan_parallel/src/sumcheck.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ impl<S: SpartanExtensionField> ZKSumcheckInstanceProof<S> {
9393
let r_i = transcript.challenge_scalar(b"challenge_nextround");
9494

9595
// verify the proof of sum-check and evals
96-
let res = {
96+
let _res = {
9797
// produce two weights
9898
let w: Vec<S> = transcript.challenge_vector(b"combine_two_claims_to_one", 2);
9999

spartan_parallel/src/unipoly.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::scalar::{Scalar, SpartanExtensionField};
1+
use super::scalar::SpartanExtensionField;
22
use super::transcript::{AppendToTranscript, ProofTranscript};
33
use merlin::Transcript;
44
use serde::{Deserialize, Serialize};
@@ -115,8 +115,8 @@ impl<S: SpartanExtensionField> AppendToTranscript for UniPoly<S> {
115115

116116
#[cfg(test)]
117117
mod tests {
118-
119118
use super::*;
119+
use crate::scalar::Scalar;
120120

121121
#[test]
122122
fn test_from_evals_quad() {

0 commit comments

Comments
 (0)