From 4796ecf40a5fa18d4a2463a5bcc689bd62a718f5 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 | 48 ++++++-------------------------- halo2_proofs/src/plonk/keygen.rs | 1 - 3 files changed, 9 insertions(+), 52 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..ba7ac58100 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,26 +152,17 @@ where let permutation = permutation::VerifyingKey::read(reader, &cs.permutation, format)?; - let (cs, selectors) = if compress_selectors { - // read selectors - let selectors: Vec> = vec![vec![false; 1 << k]; cs.num_selectors] - .into_iter() - .map(|mut selector| { - let mut selector_bytes = vec![0u8; (selector.len() + 7) / 8]; - reader.read_exact(&mut selector_bytes)?; - for (bits, byte) in selector.chunks_mut(8).zip(selector_bytes) { - crate::helpers::unpack(byte, bits); - } - Ok(selector) - }) - .collect::>()?; + let cs = if compress_selectors { + // We need to combine the selectors into fixed columns, we do this + // with dummy values, but this should not be a problem for the + // verifier, who does not care about the actual values (since the + // verifier will work with the fixed_commitments), but cares about + // the structure. + let selectors: Vec> = vec![vec![false; 1 << k]; cs.num_selectors]; 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 +170,6 @@ where fixed_commitments, permutation, cs, - selectors, compress_selectors, )) } @@ -225,12 +203,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 +210,6 @@ impl VerifyingKey { fixed_commitments: Vec, permutation: permutation::VerifyingKey, cs: ConstraintSystem, - selectors: Vec>, compress_selectors: bool, ) -> Self where @@ -255,7 +226,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, )) }