Skip to content
Open
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
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions mpcs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ clap.workspace = true
ctr = "0.9"
ff_ext = { path = "../ff_ext" }
generic-array = { version = "0.14", features = ["serde"] }
hex = "0.4"
itertools.workspace = true
multilinear_extensions = { path = "../multilinear_extensions" }
num-bigint = "0.4"
Expand Down Expand Up @@ -45,6 +46,10 @@ parallel = ["dep:rayon"]
print-trace = ["whir/print-trace"]
sanity-check = []

[[bin]]
name = "generate_test_vector"
path = "bin/generate_test_vector.rs"

[[bench]]
harness = false
name = "basefold"
Expand Down
96 changes: 96 additions & 0 deletions mpcs/bin/generate_test_vector.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
use ff_ext::{BabyBearExt4, ExtensionField, GoldilocksExt2};
use mpcs::{
Basefold, BasefoldRSParams, PolynomialCommitmentScheme, Whir, WhirDefaultSpec,
test_util::{get_point_from_challenge, setup_pcs},
};
use multilinear_extensions::virtual_poly::ArcMultilinearExtension;
use rand::{distributions::Standard, prelude::Distribution, thread_rng};
use std::collections::BTreeMap;
use transcript::{BasicTranscript, Transcript};
use witness::RowMajorMatrix;

type PcsWhirGoldilocks = Whir<GoldilocksExt2, WhirDefaultSpec>;
type PcsWhirBabyBear = Whir<BabyBearExt4, WhirDefaultSpec>;
type PcsBasefoldGoldilocks = Basefold<GoldilocksExt2, BasefoldRSParams>;
type PcsBasefoldBabyBear = Basefold<BabyBearExt4, BasefoldRSParams>;

use clap::Parser;

#[derive(Parser)]
struct Args {
#[arg(short = 'f', long, default_value = "goldilocks")]
field: String,
#[arg(short = 'p', long, default_value = "basefold")]
pcs: String,
#[arg(short = 'n', long, default_value = "5")]
num_var: u32,
}

fn main() {
// pass the parameters to determine which field to use, using the clap::Parser
let args = Args::parse();
let num_var = args.num_var;
let (vp, comm, eval, proof) = match (args.field.as_str(), args.pcs.as_str()) {
("goldilocks", "whir") => {
generate_test_vector::<GoldilocksExt2, PcsWhirGoldilocks>(num_var as usize)
}
("goldilocks", "basefold") => {
generate_test_vector::<GoldilocksExt2, PcsBasefoldGoldilocks>(num_var as usize)
}
("babybear", "whir") => {
generate_test_vector::<BabyBearExt4, PcsWhirBabyBear>(num_var as usize)
}
("babybear", "basefold") => {
generate_test_vector::<BabyBearExt4, PcsBasefoldBabyBear>(num_var as usize)
}
_ => panic!("Invalid combination of field and PCS"),
};
println!("num_vars: {}", num_var);
println!("vp: {}", vp);
println!("comm: {}", comm);
println!("eval: {}", eval);
println!("proof: {}", proof);
}

pub fn generate_test_vector<E: ExtensionField, Pcs>(
num_vars: usize,
) -> (String, String, String, String)
where
Pcs: PolynomialCommitmentScheme<E>,
Standard: Distribution<E::BaseField>,
{
let (pp, vp) = setup_pcs::<E, Pcs>(num_vars);
let mut test_rng = thread_rng();

// Commit and open
let (comm, eval, proof) = {
let mut transcript = BasicTranscript::new(b"BaseFold");
let rmm = RowMajorMatrix::<E::BaseField>::rand(&mut test_rng, 1 << num_vars, 1);
let poly: ArcMultilinearExtension<E> = rmm.to_mles().remove(0).into();
let comm =
Pcs::batch_commit_and_write(&pp, BTreeMap::from([(0, rmm)]), &mut transcript).unwrap();

let point = get_point_from_challenge(num_vars, &mut transcript);
let eval = poly.evaluate(point.as_slice());
transcript.append_field_element_ext(&eval);

(
Pcs::get_pure_commitment(&comm),
eval,
Pcs::open(&pp, &poly, &comm, &point, &eval, &mut transcript).unwrap(),
)
};
// Serialize vp, comm, eval, proof using bincode
let vp_bin = bincode::serialize(&vp).unwrap();
let comm_bin = bincode::serialize(&comm).unwrap();
let eval_bin = bincode::serialize(&eval).unwrap();
let proof_bin = bincode::serialize(&proof).unwrap();

// Encode them as hex strings
let vp_hex = hex::encode(vp_bin);
let comm_hex = hex::encode(comm_bin);
let eval_hex = hex::encode(eval_bin);
let proof_hex = hex::encode(proof_bin);

(vp_hex, comm_hex, eval_hex, proof_hex)
}
1 change: 1 addition & 0 deletions mpcs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ pub mod test_util {
) -> Vec<E> {
transcript.sample_and_append_vec(b"Point", num_vars)
}

pub fn get_points_from_challenge<E: ExtensionField>(
num_vars: impl Fn(usize) -> usize,
num_points: usize,
Expand Down