From 3169faa5354d58e02d5645fc570d31e5157b4fba Mon Sep 17 00:00:00 2001 From: ambrona Date: Wed, 24 Apr 2024 17:33:27 +0200 Subject: [PATCH] Remove redundant [selectors] field from [VerifieringKey] Co-authored-by: alexandroszacharakis8 <107036523+alexandroszacharakis8@users.noreply.github.com> --- halo2_proofs/src/helpers.rs | 12 ------------ halo2_proofs/src/plonk.rs | 30 +++--------------------------- halo2_proofs/src/plonk/keygen.rs | 1 - 3 files changed, 3 insertions(+), 40 deletions(-) diff --git a/halo2_proofs/src/helpers.rs b/halo2_proofs/src/helpers.rs index faf7351a3e..6d9e8bf26e 100644 --- a/halo2_proofs/src/helpers.rs +++ b/halo2_proofs/src/helpers.rs @@ -101,18 +101,6 @@ pub trait SerdePrimeField: PrimeField + SerdeObject { } impl SerdePrimeField for F {} -/// Convert a slice of `bool` into a `u8`. -/// -/// Panics if the slice has length greater than 8. -pub fn pack(bits: &[bool]) -> u8 { - let mut value = 0u8; - assert!(bits.len() <= 8); - for (bit_index, bit) in bits.iter().enumerate() { - value |= (*bit as u8) << bit_index; - } - value -} - /// Writes the first `bits.len()` bits of a `u8` into `bits`. pub fn unpack(byte: u8, bits: &mut [bool]) { for (bit_index, bit) in bits.iter_mut().enumerate() { diff --git a/halo2_proofs/src/plonk.rs b/halo2_proofs/src/plonk.rs index 78bfc21501..3296a117aa 100644 --- a/halo2_proofs/src/plonk.rs +++ b/halo2_proofs/src/plonk.rs @@ -55,7 +55,6 @@ pub struct VerifyingKey { cs_degree: usize, /// The representative of this `VerifyingKey` in transcripts. transcript_repr: C::Scalar, - selectors: Vec>, /// Whether selector compression is turned on or not. compress_selectors: bool, } @@ -89,17 +88,6 @@ where commitment.write(writer, format)?; } self.permutation.write(writer, format)?; - - if !self.compress_selectors { - assert!(self.selectors.is_empty()); - } - // write self.selectors - for selector in &self.selectors { - // since `selector` is filled with `bool`, we pack them 8 at a time into bytes and then write - for bits in selector.chunks(8) { - writer.write_all(&[crate::helpers::pack(bits)])?; - } - } Ok(()) } @@ -164,7 +152,7 @@ where let permutation = permutation::VerifyingKey::read(reader, &cs.permutation, format)?; - let (cs, selectors) = if compress_selectors { + let cs = if compress_selectors { // read selectors let selectors: Vec> = vec![vec![false; 1 << k]; cs.num_selectors] .into_iter() @@ -178,12 +166,9 @@ where }) .collect::>()?; let (cs, _) = cs.compress_selectors(selectors.clone()); - (cs, selectors) + cs } else { - // we still need to replace selectors with fixed Expressions in `cs` - let fake_selectors = vec![vec![]; cs.num_selectors]; - let (cs, _) = cs.directly_convert_selectors_to_fixed(fake_selectors); - (cs, vec![]) + cs }; Ok(Self::from_parts( @@ -191,7 +176,6 @@ where fixed_commitments, permutation, cs, - selectors, compress_selectors, )) } @@ -225,12 +209,6 @@ impl VerifyingKey { { 10 + (self.fixed_commitments.len() * C::byte_length(format)) + self.permutation.bytes_length(format) - + self.selectors.len() - * (self - .selectors - .get(0) - .map(|selector| (selector.len() + 7) / 8) - .unwrap_or(0)) } fn from_parts( @@ -238,7 +216,6 @@ impl VerifyingKey { fixed_commitments: Vec, permutation: permutation::VerifyingKey, cs: ConstraintSystem, - selectors: Vec>, compress_selectors: bool, ) -> Self where @@ -255,7 +232,6 @@ impl VerifyingKey { cs_degree, // Temporary, this is not pinned. transcript_repr: C::Scalar::ZERO, - selectors, compress_selectors, }; diff --git a/halo2_proofs/src/plonk/keygen.rs b/halo2_proofs/src/plonk/keygen.rs index d33a9325b9..80195eee65 100644 --- a/halo2_proofs/src/plonk/keygen.rs +++ b/halo2_proofs/src/plonk/keygen.rs @@ -278,7 +278,6 @@ where fixed_commitments, permutation_vk, cs, - assembly.selectors, compress_selectors, )) }