Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MSM: rename var for number of cols #1882

Merged
merged 1 commit into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions msm/src/constraint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -84,8 +84,8 @@ impl BuilderEnv<BN254G1Affine> {
/// 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<N, BN254G1Affine> {
let mut cols: [Vec<Fp>; N] = std::array::from_fn(|_| vec![]);
pub fn get_witness(&self) -> ProofInputs<MSM_FFADD_N_COLUMNS, BN254G1Affine> {
let mut cols: [Vec<Fp>; MSM_FFADD_N_COLUMNS] = std::array::from_fn(|_| vec![]);

for wc in &self.witness_raw {
let WitnessColumnsIndexer {
Expand Down
2 changes: 1 addition & 1 deletion msm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub type BN254G2Affine = <BN254 as ark_ec::PairingEngine>::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;
Expand Down
9 changes: 6 additions & 3 deletions msm/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<BN254G1Affine> {
Expand Down Expand Up @@ -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,
Expand All @@ -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}")
}
23 changes: 13 additions & 10 deletions msm/src/serialization/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -23,7 +23,7 @@ pub fn main() {
let srs: PairingSRS<BN254> = get_bn254_srs(domain);

let mut env = witness::Env::<Fp>::create();
let mut witness: Witness<N, Vec<Fp>> = Witness {
let mut witness: Witness<SERIALIZATION_N_COLUMNS, Vec<Fp>> = Witness {
cols: std::array::from_fn(|_| Vec::with_capacity(DOMAIN_SIZE)),
};

Expand All @@ -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}")
}