Skip to content

Commit

Permalink
use lut sum for interleaved alphabet eval/proximity test
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyfloatersu committed Nov 15, 2024
1 parent 1383b01 commit 4c6451f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 24 deletions.
2 changes: 1 addition & 1 deletion arith/gf2/src/gf2x8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl Field for GF2x8 {

#[inline(always)]
fn as_u32_unchecked(&self) -> u32 {
self.v as u32 % 256
self.v as u32
}

#[inline(always)]
Expand Down
28 changes: 12 additions & 16 deletions pcs/src/orion/pcs_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,25 +228,21 @@ impl OrionPublicParams {
.zip(eval_row.iter_mut())
.for_each(|(p_col, res)| *res = luts.lookup_and_sum(p_col));

luts.zeroize();

// NOTE: draw random linear combination out
// and compose proximity response(s) of tensor code IOP based PCS
let proximity_repetitions =
self.proximity_repetition_num(PCS_SOUNDNESS_BITS, EvalF::FIELD_SIZE);
let mut proximity_rows = vec![vec![EvalF::ZERO; msg_size]; proximity_repetitions];

(0..proximity_repetitions).for_each(|rep_i| {
proximity_rows.iter_mut().for_each(|row_buffer| {
let random_coeffs = transcript.generate_challenge_field_elements(row_num);

luts.build(&random_coeffs);

packed_transposed_evaluations
.chunks(row_num / IPPackF::PACK_SIZE)
.zip(proximity_rows[rep_i].iter_mut())
.zip(row_buffer.iter_mut())
.for_each(|(p_col, res)| *res = luts.lookup_and_sum(p_col));

luts.zeroize();
});

// NOTE: working on evaluation on top of evaluation response
Expand Down Expand Up @@ -358,8 +354,7 @@ impl OrionPublicParams {
// NOTE: encode the proximity/evaluation responses,
// check againts all challenged indices by check alphabets against
// linear combined interleaved alphabet
let mut scratch_pf = vec![IPPackF::ZERO; row_num / IPPackF::PACK_SIZE];
let mut scratch_pef = vec![IPPackEvalF::ZERO; row_num / IPPackEvalF::PACK_SIZE];
let mut luts = LookupTables::<EvalF>::new(IPPackF::PACK_SIZE, row_num / IPPackF::PACK_SIZE);
assert_eq!(row_num % IPPackF::PACK_SIZE, 0);

let eq_linear_combination = EqPolynomial::build_eq_x_r(&point[num_of_vars_in_codeword..]);
Expand All @@ -369,18 +364,19 @@ impl OrionPublicParams {
.chain(iter::once((&eq_linear_combination, &proof.eval_row)))
.all(|(rl, msg)| match self.code_instance.encode(msg) {
Ok(codeword) => {
luts.build(&rl);

query_points
.iter()
.zip(proof.query_openings.iter())
.all(|(&qi, range_path)| {
let interleaved_alphabet =
range_path.unpack_field_elems::<F, ComPackF>();
let alphabet = simd_inner_prod(
&interleaved_alphabet,
rl,
&mut scratch_pf,
&mut scratch_pef,
);
let interleaved_alphabet: Vec<_> = range_path
.unpack_field_elems::<F, ComPackF>()
.chunks(IPPackF::PACK_SIZE)
.map(IPPackF::pack)
.collect();

let alphabet = luts.lookup_and_sum(&interleaved_alphabet);
alphabet == codeword[qi]
})
}
Expand Down
5 changes: 1 addition & 4 deletions pcs/src/orion/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use arith::{ExtensionField, Field, FieldSerde, SimdField};
use ark_std::{log2, test_rng};
use gf2::{GF2x128, GF2x64, GF2x8, GF2};
use gf2_128::{GF2_128x8, GF2_128};
use mersenne31::{M31Ext3, M31Ext3x16, M31x16, M31};
use polynomials::{EqPolynomial, MultiLinearPoly};
use transcript::{BytesHashTranscript, Keccak256hasher, Transcript};

Expand Down Expand Up @@ -53,7 +52,7 @@ where
.chunks_mut(orion_code.msg_len())
.zip(codeword_mat.chunks_mut(orion_code.code_len()))
.try_for_each(|(msg, codeword)| {
msg.iter_mut().for_each(|x| *x = F::random_unsafe(&mut rng));
msg.fill_with(|| F::random_unsafe(&mut rng));
orion_code.encode_in_place(msg, codeword)
})
.unwrap();
Expand Down Expand Up @@ -87,7 +86,6 @@ fn test_orion_code() {

test_orion_code_generic::<GF2_128, GF2_128x8>(msg_len);
test_orion_code_generic::<GF2, GF2x64>(msg_len);
test_orion_code_generic::<M31Ext3, M31Ext3x16>(msg_len);
});
}

Expand Down Expand Up @@ -152,7 +150,6 @@ fn test_orion_commit_consistency() {
test_orion_commit_consistency_generic::<GF2, GF2x64>(num_vars);
test_orion_commit_consistency_generic::<GF2, GF2x128>(num_vars);
});
(9..=15).for_each(test_orion_commit_consistency_generic::<M31, M31x16>)
}

fn test_multilinear_poly_tensor_eval_generic<F, ExtF, IPPackExtF>(num_of_vars: usize)
Expand Down
10 changes: 7 additions & 3 deletions pcs/src/orion/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ pub(crate) fn transpose_in_place<F: Field>(mat: &mut [F], scratch: &mut [F], row
mat.copy_from_slice(scratch);
}

/*********************
* LINEAR OPERATIONS *
*********************/

#[inline]
pub(crate) fn simd_inner_prod<F0, F1, IPPackF0, IPPackF1>(
l: &[F0],
Expand Down Expand Up @@ -101,6 +105,8 @@ impl<F: Field> LookupTables<F> {
assert_eq!(weights.len() % self.table_bits, 0);
assert_eq!(weights.len() / self.table_bits, self.table_num);

self.zeroize();

self.tables
.iter_mut()
.zip(weights.chunks(self.table_bits))
Expand All @@ -118,9 +124,7 @@ impl<F: Field> LookupTables<F> {

#[inline]
pub fn zeroize(&mut self) {
self.tables
.iter_mut()
.for_each(|lut| lut.iter_mut().for_each(|i| *i = F::ZERO));
self.tables.iter_mut().for_each(|lut| lut.fill(F::ZERO));
}

#[inline]
Expand Down

0 comments on commit 4c6451f

Please sign in to comment.