Skip to content

Commit

Permalink
Remove redundant [selectors] field from [VerifieringKey]
Browse files Browse the repository at this point in the history
Co-authored-by: alexandroszacharakis8 <[email protected]>
  • Loading branch information
miguel-ambrona and alexandroszacharakis8 committed Apr 24, 2024
1 parent b410501 commit 3169faa
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 40 deletions.
12 changes: 0 additions & 12 deletions halo2_proofs/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,6 @@ pub trait SerdePrimeField: PrimeField + SerdeObject {
}
impl<F: PrimeField + SerdeObject> 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() {
Expand Down
30 changes: 3 additions & 27 deletions halo2_proofs/src/plonk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ pub struct VerifyingKey<C: CurveAffine> {
cs_degree: usize,
/// The representative of this `VerifyingKey` in transcripts.
transcript_repr: C::Scalar,
selectors: Vec<Vec<bool>>,
/// Whether selector compression is turned on or not.
compress_selectors: bool,
}
Expand Down Expand Up @@ -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(())
}

Expand Down Expand Up @@ -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<bool>> = vec![vec![false; 1 << k]; cs.num_selectors]
.into_iter()
Expand All @@ -178,20 +166,16 @@ where
})
.collect::<io::Result<_>>()?;
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(
domain,
fixed_commitments,
permutation,
cs,
selectors,
compress_selectors,
))
}
Expand Down Expand Up @@ -225,20 +209,13 @@ impl<C: CurveAffine> VerifyingKey<C> {
{
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(
domain: EvaluationDomain<C::Scalar>,
fixed_commitments: Vec<C>,
permutation: permutation::VerifyingKey<C>,
cs: ConstraintSystem<C::Scalar>,
selectors: Vec<Vec<bool>>,
compress_selectors: bool,
) -> Self
where
Expand All @@ -255,7 +232,6 @@ impl<C: CurveAffine> VerifyingKey<C> {
cs_degree,
// Temporary, this is not pinned.
transcript_repr: C::Scalar::ZERO,
selectors,
compress_selectors,
};

Expand Down
1 change: 0 additions & 1 deletion halo2_proofs/src/plonk/keygen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,6 @@ where
fixed_commitments,
permutation_vk,
cs,
assembly.selectors,
compress_selectors,
))
}
Expand Down

0 comments on commit 3169faa

Please sign in to comment.