Skip to content

Commit 0a4504d

Browse files
committed
style: pr comments
1 parent df0643e commit 0a4504d

File tree

5 files changed

+26
-39
lines changed

5 files changed

+26
-39
lines changed

jolt-optimizations/src/fq12_poly.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
use ark_bn254::{Fq, Fq12};
33
use ark_ff::{Field, One, Zero};
44

5-
const NINE: u64 = 9;
6-
75
/// Convert Fq12 to polynomial representation using tower basis mapping
86
///
97
/// Maps Fq12 basis elements to powers of w:
@@ -20,7 +18,7 @@ pub fn fq12_to_poly12_coeffs(a: &Fq12) -> [Fq; 12] {
2018
(1, 2, 5), // a.c1.c2 → w^5
2119
];
2220

23-
let nine = Fq::from(NINE);
21+
let nine = Fq::from(9);
2422
let mut coeffs = [Fq::zero(); 12];
2523

2624
for &(outer, inner, w_power) in &MAPPINGS {
@@ -111,7 +109,6 @@ pub fn eval_multilinear(evals: &[Fq], point: &[Fq]) -> Fq {
111109
}
112110

113111
/// Compute equality function weights eq(z, x) for all x ∈ {0,1}^4
114-
/// Helper for testing in arkworks
115112
pub fn eq_weights(z: &[Fq]) -> Vec<Fq> {
116113
assert_eq!(z.len(), 4, "Point z must be 4-dimensional");
117114
let mut w = vec![Fq::zero(); 16];

jolt-optimizations/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ pub use dory_g2::{
5858
pub use batch_addition::{batch_g1_additions, batch_g1_additions_multi};
5959

6060
pub use fq12_poly::{
61-
eval_multilinear, fq12_to_multilinear_evals, fq12_to_poly12_coeffs, g_coeffs, g_eval,
62-
to_multilinear_evals,
61+
eq_weights, eval_multilinear, fq12_to_multilinear_evals, fq12_to_poly12_coeffs, g_coeffs,
62+
g_eval, to_multilinear_evals,
6363
};
6464

65-
pub use witness_gen::ExponentiationSteps;
65+
pub use witness_gen::{get_g_mle, h_tilde_at_point, ExponentiationSteps};

jolt-optimizations/src/witness_gen.rs

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
use crate::fq12_poly::{
2-
eq_weights, eval_multilinear, fq12_to_multilinear_evals, g_coeffs, to_multilinear_evals,
3-
};
1+
use crate::fq12_poly::{eq_weights, eval_multilinear, fq12_to_multilinear_evals, g_coeffs};
42
use ark_bn254::{Fq, Fq12, Fr};
53
use ark_ff::{BigInteger, Field, One, PrimeField, Zero};
64
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
@@ -82,15 +80,13 @@ impl ExponentiationSteps {
8280
}
8381
}
8482

85-
/// Verify that the final result matches base^exponent,
86-
/// Used for testing
83+
/// Verify that the final result matches base^exponent
8784
pub fn verify_result(&self) -> bool {
8885
self.result == self.base.pow(self.exponent.into_bigint())
8986
}
9087

9188
/// Verify constraint at a Boolean cube point
9289
/// Checks that the constraint holds at cube vertices where it was constructed to be zero
93-
/// Used for testing
9490
pub fn verify_constraint_at_cube_point(&self, step: usize, cube_index: usize) -> bool {
9591
if step == 0 || step > self.quotient_mles.len() || cube_index >= 16 {
9692
return false;
@@ -144,23 +140,20 @@ fn compute_step_quotient_msb(rho_prev: Fq12, rho_i: Fq12, base: Fq12, bit: bool)
144140
}
145141

146142
/// Get g as MLE evaluations over the Boolean cube {0,1}^4
147-
/// Used for testing
148143
pub fn get_g_mle() -> Vec<Fq> {
149-
// Use the same encoding as fq12_to_multilinear_evals
150-
// g(X) = X^12 - 18X^6 + 82 as coefficient array
144+
use crate::fq12_poly::eval_poly_vec;
151145
let g_vec = g_coeffs();
152-
let mut g_array = [Fq::zero(); 12];
153-
for i in 0..12 {
154-
if i < g_vec.len() {
155-
g_array[i] = g_vec[i];
156-
}
157-
}
158-
to_multilinear_evals(&g_array)
146+
147+
(0..16)
148+
.map(|i| {
149+
let x = Fq::from(i as u64);
150+
eval_poly_vec(&g_vec[..], &x)
151+
})
152+
.collect()
159153
}
160154

161155
/// Convert a cube index (0..15) to a Boolean point in {0,1}^4
162-
/// Used for testing
163-
pub fn index_to_boolean_point(index: usize) -> Vec<Fq> {
156+
pub(crate) fn index_to_boolean_point(index: usize) -> Vec<Fq> {
164157
vec![
165158
Fq::from((index & 1) as u64), // bit 0
166159
Fq::from(((index >> 1) & 1) as u64), // bit 1
@@ -171,7 +164,6 @@ pub fn index_to_boolean_point(index: usize) -> Vec<Fq> {
171164

172165
/// Evaluate an MLE at a Boolean cube point
173166
/// For Boolean points, this is equivalent to indexing but makes the evaluation explicit
174-
/// Used for testing
175167
fn eval_mle_at_boolean_point(mle: &[Fq], point: &[Fq]) -> Fq {
176168
// For Boolean points, we could just index, but using eval_multilinear
177169
// makes it clear we're doing MLE evaluation
@@ -180,7 +172,6 @@ fn eval_mle_at_boolean_point(mle: &[Fq], point: &[Fq]) -> Fq {
180172

181173
/// H(x) = ρᵢ(x) - ρᵢ₋₁(x)² · A(x)^{bᵢ} - Qᵢ(x) · g(x) for x ∈ {0,1}^4
182174
/// H̃(z) = Σ_{x∈{0,1}^4} eq(z,x) · H(x)
183-
/// Used for testing
184175
pub fn h_tilde_at_point(
185176
rho_prev_mle: &[Fq],
186177
rho_curr_mle: &[Fq],

jolt-optimizations/tests/mle_tests.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
use ark_bn254::Fq;
22
use ark_ff::{Field, One, UniformRand, Zero};
33
use ark_std::test_rng;
4-
use jolt_optimizations::fq12_poly::{eval_multilinear, eval_poly_vec, to_multilinear_evals};
4+
use jolt_optimizations::{
5+
eval_multilinear,
6+
fq12_poly::{eval_poly_vec, to_multilinear_evals},
7+
};
58

69
/// Generate random polynomial coefficients for testing
710
fn random_poly12_coeffs() -> [Fq; 12] {

jolt-optimizations/tests/witness_test.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
use ark_bn254::{Fq, Fq12, Fr};
2-
use ark_ff::{Field, One, UniformRand, Zero};
2+
use ark_ff::{One, UniformRand, Zero};
33
use ark_std::test_rng;
44
use jolt_optimizations::{
5-
eval_multilinear, fq12_to_multilinear_evals, g_coeffs, to_multilinear_evals,
6-
witness_gen::{get_g_mle, h_tilde_at_point},
7-
ExponentiationSteps,
5+
fq12_to_multilinear_evals, get_g_mle, h_tilde_at_point, ExponentiationSteps,
86
};
97

108
#[test]
@@ -90,7 +88,7 @@ fn test_trivial_cases() {
9088
fn test_witness_soundness() {
9189
let mut rng = test_rng();
9290

93-
// Test soundness: tampering with witness should be detected
91+
// Test soundness: tampering with witness
9492
for test_idx in 0..20 {
9593
let base = Fq12::rand(&mut rng);
9694
let exponent = if test_idx == 0 {
@@ -113,7 +111,7 @@ fn test_witness_soundness() {
113111
}
114112
assert!(all_valid, "Original witness should be valid");
115113

116-
// Test 1: Tampering with ρ values breaks soundness
114+
// Test 1: Tampering with ρ values
117115
if witness.rho_mles.len() > 1 {
118116
let tamper_idx = 1 + (test_idx % (witness.rho_mles.len() - 1));
119117
let point_idx = test_idx % 16;
@@ -141,7 +139,7 @@ fn test_witness_soundness() {
141139
witness.rho_mles[tamper_idx][point_idx] = original;
142140
}
143141

144-
// Test 2: Tampering with quotient values breaks soundness
142+
// Test 2: Tampering with quotient
145143
if !witness.quotient_mles.is_empty() {
146144
let q_idx = test_idx % witness.quotient_mles.len();
147145
let point_idx = (test_idx * 7) % 16;
@@ -158,7 +156,7 @@ fn test_witness_soundness() {
158156
witness.quotient_mles[q_idx][point_idx] = original;
159157
}
160158

161-
// Test 3: Flipping bits breaks soundness
159+
// Test 3: Flipping bits
162160
if !witness.bits.is_empty() {
163161
let bit_idx = test_idx % witness.bits.len();
164162
witness.bits[bit_idx] = !witness.bits[bit_idx];
@@ -175,7 +173,7 @@ fn test_witness_soundness() {
175173
witness.bits[bit_idx] = !witness.bits[bit_idx];
176174
}
177175

178-
// Test 4: Tampering with final result breaks verification
176+
// Test 4: Tampering with final result
179177
let original_result = witness.result;
180178
witness.result = witness.result + Fq12::one();
181179
assert!(
@@ -233,8 +231,6 @@ fn test_constraint_at_random_field_element() {
233231
);
234232
}
235233

236-
println!("✓ Verified: H̃(z) = 0 at 20 random field elements (Sumcheck correct)");
237-
238234
for step in 1..=witness.num_steps() {
239235
for cube_idx in 0..16 {
240236
assert!(

0 commit comments

Comments
 (0)