From 3b9873982ab16be0e1faa8efdf5d42f690f274e9 Mon Sep 17 00:00:00 2001 From: Danny Willems Date: Thu, 29 Feb 2024 21:30:42 +0100 Subject: [PATCH] MSM: rename var for number of cols Fix https://github.com/o1-labs/proof-systems/issues/1881 --- msm/src/constraint.rs | 6 +++--- msm/src/lib.rs | 2 +- msm/src/main.rs | 9 ++++++--- msm/src/serialization/main.rs | 23 +++++++++++++---------- 4 files changed, 23 insertions(+), 17 deletions(-) diff --git a/msm/src/constraint.rs b/msm/src/constraint.rs index f9cb4f277e..635b6732b9 100644 --- a/msm/src/constraint.rs +++ b/msm/src/constraint.rs @@ -11,7 +11,7 @@ use o1_utils::foreign_field::ForeignElement; use crate::columns::{Column, ColumnIndexer, MSMColumnIndexer}; use crate::proof::ProofInputs; use crate::witness::Witness; -use crate::{BN254G1Affine, Ff1, Fp, LIMBS_NUM, N}; +use crate::{BN254G1Affine, Ff1, Fp, LIMBS_NUM, MSM_FFADD_N_COLUMNS}; /// Used to represent constraints as multi variate polynomials. The variables /// are over the columns. @@ -84,8 +84,8 @@ impl BuilderEnv { /// Each WitnessColumn stands for both one row and multirow. This /// function converts from a vector of one-row instantiation to a /// single multi-row form (which is a `Witness`). - pub fn get_witness(&self) -> ProofInputs { - let mut cols: [Vec; N] = std::array::from_fn(|_| vec![]); + pub fn get_witness(&self) -> ProofInputs { + let mut cols: [Vec; MSM_FFADD_N_COLUMNS] = std::array::from_fn(|_| vec![]); for wc in &self.witness_raw { let WitnessColumnsIndexer { diff --git a/msm/src/lib.rs b/msm/src/lib.rs index cef9272356..35ff75f86f 100644 --- a/msm/src/lib.rs +++ b/msm/src/lib.rs @@ -32,7 +32,7 @@ pub type BN254G2Affine = ::G2Affine; /// Number of columns /// FIXME: we must move it into the subdirectory of the /// foreign field addition circuit -pub const N: usize = 3 * LIMBS_NUM; +pub const MSM_FFADD_N_COLUMNS: usize = 3 * LIMBS_NUM; /// The native field we are working with. pub type Fp = ark_bn254::Fr; diff --git a/msm/src/main.rs b/msm/src/main.rs index ae9f769f1d..a9d02a258d 100644 --- a/msm/src/main.rs +++ b/msm/src/main.rs @@ -10,7 +10,8 @@ use kimchi_msm::precomputed_srs::get_bn254_srs; use kimchi_msm::prover::prove; use kimchi_msm::verifier::verify; use kimchi_msm::{ - BN254G1Affine, BaseSponge, Ff1, Fp, OpeningProof, ScalarSponge, BN254, DOMAIN_SIZE, N, + BN254G1Affine, BaseSponge, Ff1, Fp, OpeningProof, ScalarSponge, BN254, DOMAIN_SIZE, + MSM_FFADD_N_COLUMNS, }; pub fn generate_random_msm_witness() -> BuilderEnv { @@ -43,7 +44,7 @@ pub fn main() { println!("Generating the proof"); let constraints = vec![]; - let proof = prove::<_, OpeningProof, BaseSponge, ScalarSponge, Column, _, N>( + let proof = prove::<_, OpeningProof, BaseSponge, ScalarSponge, Column, _, MSM_FFADD_N_COLUMNS>( domain, &srs, witness, @@ -52,6 +53,8 @@ pub fn main() { ); println!("Verifying the proof"); - let verifies = verify::<_, OpeningProof, BaseSponge, ScalarSponge, N>(domain, &srs, &proof); + let verifies = verify::<_, OpeningProof, BaseSponge, ScalarSponge, MSM_FFADD_N_COLUMNS>( + domain, &srs, &proof, + ); println!("Proof verification result: {verifies}") } diff --git a/msm/src/serialization/main.rs b/msm/src/serialization/main.rs index d8b91eaa5f..4c23bc6fe3 100644 --- a/msm/src/serialization/main.rs +++ b/msm/src/serialization/main.rs @@ -11,7 +11,7 @@ use kimchi_msm::serialization::witness::deserialize_field_element; use kimchi_msm::verifier::verify; use kimchi_msm::{BaseSponge, Fp, OpeningProof, ScalarSponge, BN254, DOMAIN_SIZE, LIMBS_NUM}; -const N: usize = 3 + 19 + LIMBS_NUM; +const SERIALIZATION_N_COLUMNS: usize = 3 + 19 + LIMBS_NUM; pub fn main() { // FIXME: use a proper RNG @@ -23,7 +23,7 @@ pub fn main() { let srs: PairingSRS = get_bn254_srs(domain); let mut env = witness::Env::::create(); - let mut witness: Witness> = Witness { + let mut witness: Witness> = Witness { cols: std::array::from_fn(|_| Vec::with_capacity(DOMAIN_SIZE)), }; @@ -49,15 +49,18 @@ pub fn main() { }; println!("Generating the proof"); - let proof = prove::<_, OpeningProof, BaseSponge, ScalarSponge, Column, _, N>( - domain, - &srs, - proof_inputs, - _constraints, - &mut rng, - ); + let proof = + prove::<_, OpeningProof, BaseSponge, ScalarSponge, Column, _, SERIALIZATION_N_COLUMNS>( + domain, + &srs, + proof_inputs, + _constraints, + &mut rng, + ); println!("Verifying the proof"); - let verifies = verify::<_, OpeningProof, BaseSponge, ScalarSponge, N>(domain, &srs, &proof); + let verifies = verify::<_, OpeningProof, BaseSponge, ScalarSponge, SERIALIZATION_N_COLUMNS>( + domain, &srs, &proof, + ); println!("Proof verification result: {verifies}") }