Only write k in Params; calculate n when reading

Co-authored-by: Jack Grigg <jack@electriccoin.co>
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
This commit is contained in:
therealyingtong 2021-01-22 12:31:27 +08:00
parent e0f9fe1dcf
commit ffdd739f85
4 changed files with 8 additions and 11 deletions

View file

@ -56,7 +56,7 @@ where
} }
/// Assembly to be used in circuit synthesis. /// Assembly to be used in circuit synthesis.
#[derive(Clone, Debug)] #[derive(Debug)]
pub struct Assembly<F: Field> { pub struct Assembly<F: Field> {
fixed: Vec<Polynomial<F, LagrangeCoeff>>, fixed: Vec<Polynomial<F, LagrangeCoeff>>,
permutations: Vec<permutation::keygen::Assembly>, permutations: Vec<permutation::keygen::Assembly>,
@ -127,7 +127,7 @@ where
_marker: std::marker::PhantomData, _marker: std::marker::PhantomData,
}; };
// Synthesize the circuit to obtain SRS // Synthesize the circuit to obtain URS
circuit.synthesize(&mut assembly, config)?; circuit.synthesize(&mut assembly, config)?;
let permutation_helper = permutation::keygen::Assembly::build_helper(params, &cs, &domain); let permutation_helper = permutation::keygen::Assembly::build_helper(params, &cs, &domain);
@ -177,7 +177,7 @@ where
_marker: std::marker::PhantomData, _marker: std::marker::PhantomData,
}; };
// Synthesize the circuit to obtain SRS // Synthesize the circuit to obtain URS
circuit.synthesize(&mut assembly, config)?; circuit.synthesize(&mut assembly, config)?;
let fixed_polys: Vec<_> = assembly let fixed_polys: Vec<_> = assembly

View file

@ -14,7 +14,7 @@ pub(crate) struct AssemblyHelper<C: CurveAffine> {
deltaomega: Vec<Vec<C::Scalar>>, deltaomega: Vec<Vec<C::Scalar>>,
} }
#[derive(Clone, Debug)] #[derive(Debug)]
pub(crate) struct Assembly { pub(crate) struct Assembly {
pub(crate) mapping: Vec<Vec<(usize, usize)>>, pub(crate) mapping: Vec<Vec<(usize, usize)>>,
aux: Vec<Vec<(usize, usize)>>, aux: Vec<Vec<(usize, usize)>>,
@ -139,7 +139,7 @@ impl Assembly {
helper: &AssemblyHelper<C>, helper: &AssemblyHelper<C>,
p: &Argument, p: &Argument,
) -> VerifyingKey<C> { ) -> VerifyingKey<C> {
// Pre-compute commitments for the SRS. // Pre-compute commitments for the URS.
let mut commitments = vec![]; let mut commitments = vec![];
for i in 0..p.columns.len() { for i in 0..p.columns.len() {
// Computes the permutation polynomial based on the permutation // Computes the permutation polynomial based on the permutation

View file

@ -194,7 +194,6 @@ impl<C: CurveAffine> Params<C> {
/// Writes params to a buffer. /// Writes params to a buffer.
pub fn write<W: io::Write>(&self, writer: &mut W) -> io::Result<()> { pub fn write<W: io::Write>(&self, writer: &mut W) -> io::Result<()> {
writer.write_all(&self.k.to_le_bytes())?; writer.write_all(&self.k.to_le_bytes())?;
writer.write_all(&self.n.to_le_bytes())?;
for g_element in &self.g { for g_element in &self.g {
writer.write_all(&g_element.to_bytes())?; writer.write_all(&g_element.to_bytes())?;
} }
@ -213,9 +212,7 @@ impl<C: CurveAffine> Params<C> {
reader.read_exact(&mut k[..])?; reader.read_exact(&mut k[..])?;
let k = u32::from_le_bytes(k); let k = u32::from_le_bytes(k);
let mut n = [0u8; 8]; let n: u64 = 1 << k;
reader.read_exact(&mut n[..])?;
let n = u64::from_le_bytes(n);
let g: Vec<_> = (0..n).map(|_| C::read(reader)).collect::<Result<_, _>>()?; let g: Vec<_> = (0..n).map(|_| C::read(reader)).collect::<Result<_, _>>()?;
let g_lagrange: Vec<_> = (0..n).map(|_| C::read(reader)).collect::<Result<_, _>>()?; let g_lagrange: Vec<_> = (0..n).map(|_| C::read(reader)).collect::<Result<_, _>>()?;

View file

@ -20,7 +20,7 @@ use std::io;
/// **Important:** This function assumes that the provided `transcript` has /// **Important:** This function assumes that the provided `transcript` has
/// already seen the common inputs: the polynomial commitment P, the claimed /// already seen the common inputs: the polynomial commitment P, the claimed
/// opening v, and the point x. It's probably also nice for the transcript /// opening v, and the point x. It's probably also nice for the transcript
/// to have seen the elliptic curve description and the SRS, if you want to /// to have seen the elliptic curve description and the URS, if you want to
/// be rigorous. /// be rigorous.
pub fn create_proof<C: CurveAffine, T: TranscriptWrite<C>>( pub fn create_proof<C: CurveAffine, T: TranscriptWrite<C>>(
params: &Params<C>, params: &Params<C>,
@ -82,7 +82,7 @@ pub fn create_proof<C: CurveAffine, T: TranscriptWrite<C>>(
} }
} }
// Initialize the vector `G` from the SRS. We'll be progressively collapsing // Initialize the vector `G` from the URS. We'll be progressively collapsing
// this vector into smaller and smaller vectors until it is of length 1. // this vector into smaller and smaller vectors until it is of length 1.
let mut g = params.g.clone(); let mut g = params.g.clone();