Skip to content

Commit f7555d9

Browse files
refactor: move dedup & mt strategies into whir params
1 parent f3031a1 commit f7555d9

10 files changed

Lines changed: 90 additions & 141 deletions

File tree

src/bin/benchmark.rs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ use whir::{
2626
},
2727
},
2828
parameters::{
29-
default_max_pow, FoldingFactor, MultivariateParameters, ProtocolParameters, SoundnessType,
29+
default_max_pow, DeduplicationStrategy, FoldingFactor, MerkleProofStrategy,
30+
MultivariateParameters, ProtocolParameters, SoundnessType,
3031
},
3132
poly_utils::{coeffs::CoefficientList, multilinear::MultilinearPoint},
3233
whir::{
3334
committer::CommitmentReader,
3435
domainsep::DigestDomainSeparator,
35-
parameters::{DeduplicationStrategy, MerkleProofStrategy},
3636
statement::{Statement, Weights},
3737
utils::{DigestToUnitDeserialize, DigestToUnitSerialize},
3838
},
@@ -258,6 +258,8 @@ fn run_whir<F, MerkleConfig>(
258258
_pow_parameters: Default::default(),
259259
starting_log_inv_rate: starting_rate,
260260
batch_size: 1,
261+
deduplication_strategy: DeduplicationStrategy::Enabled,
262+
merkle_proof_strategy: MerkleProofStrategy::Compressed,
261263
};
262264

263265
let polynomial = CoefficientList::new(
@@ -283,12 +285,7 @@ fn run_whir<F, MerkleConfig>(
283285
initial_statement: false,
284286
..whir_params.clone()
285287
};
286-
let params = WhirConfig::<F, MerkleConfig, PowStrategy>::new(
287-
mv_params,
288-
whir_params,
289-
DeduplicationStrategy::Enabled,
290-
MerkleProofStrategy::Compressed,
291-
);
288+
let params = WhirConfig::<F, MerkleConfig, PowStrategy>::new(mv_params, whir_params);
292289
if !params.check_pow_bits() {
293290
println!("WARN: more PoW bits required than what specified.");
294291
}
@@ -361,12 +358,7 @@ fn run_whir<F, MerkleConfig>(
361358
prover::Prover, verifier::Verifier,
362359
};
363360

364-
let params = WhirConfig::<F, MerkleConfig, PowStrategy>::new(
365-
mv_params,
366-
whir_params,
367-
DeduplicationStrategy::Enabled,
368-
MerkleProofStrategy::Compressed,
369-
);
361+
let params = WhirConfig::<F, MerkleConfig, PowStrategy>::new(mv_params, whir_params);
370362
if !params.check_pow_bits() {
371363
println!("WARN: more PoW bits required than what specified.");
372364
}

src/bin/main.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ use whir::{
2121
},
2222
},
2323
parameters::{
24-
default_max_pow, FoldingFactor, MultivariateParameters, ProtocolParameters, SoundnessType,
24+
default_max_pow, DeduplicationStrategy, FoldingFactor, MerkleProofStrategy,
25+
MultivariateParameters, ProtocolParameters, SoundnessType,
2526
},
2627
poly_utils::{coeffs::CoefficientList, evals::EvaluationsList, multilinear::MultilinearPoint},
2728
whir::{
2829
committer::CommitmentReader,
2930
domainsep::DigestDomainSeparator,
30-
parameters::{DeduplicationStrategy, MerkleProofStrategy},
3131
statement::{Statement, Weights},
3232
utils::{DigestToUnitDeserialize, DigestToUnitSerialize},
3333
},
@@ -261,14 +261,11 @@ fn run_whir_as_ldt<F, MerkleConfig>(
261261
_pow_parameters: Default::default(),
262262
starting_log_inv_rate: starting_rate,
263263
batch_size: 1,
264+
deduplication_strategy: DeduplicationStrategy::Enabled,
265+
merkle_proof_strategy: MerkleProofStrategy::Compressed,
264266
};
265267

266-
let params = WhirConfig::<F, MerkleConfig, PowStrategy>::new(
267-
mv_params,
268-
whir_params,
269-
DeduplicationStrategy::Enabled,
270-
MerkleProofStrategy::Compressed,
271-
);
268+
let params = WhirConfig::<F, MerkleConfig, PowStrategy>::new(mv_params, whir_params);
272269

273270
let domainsep = DomainSeparator::new("🌪️")
274271
.commit_statement(&params)
@@ -380,14 +377,11 @@ fn run_whir_pcs<F, MerkleConfig>(
380377
_pow_parameters: Default::default(),
381378
starting_log_inv_rate: starting_rate,
382379
batch_size: 1,
380+
deduplication_strategy: DeduplicationStrategy::Enabled,
381+
merkle_proof_strategy: MerkleProofStrategy::Compressed,
383382
};
384383

385-
let params = WhirConfig::<F, MerkleConfig, PowStrategy>::new(
386-
mv_params,
387-
whir_params,
388-
DeduplicationStrategy::Enabled,
389-
MerkleProofStrategy::Compressed,
390-
);
384+
let params = WhirConfig::<F, MerkleConfig, PowStrategy>::new(mv_params, whir_params);
391385

392386
let domainsep = DomainSeparator::new("🌪️")
393387
.commit_statement(&params)

src/parameters.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,18 @@ impl FoldingFactor {
206206
}
207207
}
208208

209+
#[derive(Clone, Debug, Serialize, Deserialize)]
210+
pub enum MerkleProofStrategy {
211+
Compressed,
212+
Uncompressed,
213+
}
214+
215+
#[derive(Debug, Clone, Serialize, Deserialize)]
216+
pub enum DeduplicationStrategy {
217+
Enabled, // Sort + dedup indices
218+
Disabled, // Preserve order/multiplicity
219+
}
220+
209221
/// Configuration parameters for WHIR proofs.
210222
#[derive(Clone, Serialize, Deserialize)]
211223
pub struct ProtocolParameters<MerkleConfig, PowStrategy>
@@ -239,6 +251,16 @@ where
239251

240252
/// Number of polynomials committed in the batch.
241253
pub batch_size: usize,
254+
255+
/// Strategy to decide on the deduplication of challenges
256+
/// Standard: Sort + dedup indices
257+
/// Recursive: Preserve order/multiplicity
258+
pub deduplication_strategy: DeduplicationStrategy,
259+
260+
/// Strategy to decide on compression of merkle proofs used in proving.
261+
/// Standard: Compressed proofs.
262+
/// Recursive: Full Proofs.
263+
pub merkle_proof_strategy: MerkleProofStrategy,
242264
}
243265

244266
impl<MerkleConfig, PowStrategy> Debug for ProtocolParameters<MerkleConfig, PowStrategy>

src/whir/batching.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,17 @@ mod batching_tests {
3737
parameters::default_config,
3838
},
3939
},
40-
parameters::{FoldingFactor, MultivariateParameters, ProtocolParameters, SoundnessType},
40+
parameters::{
41+
DeduplicationStrategy, FoldingFactor, MerkleProofStrategy, MultivariateParameters,
42+
ProtocolParameters, SoundnessType,
43+
},
4144
poly_utils::{
4245
coeffs::CoefficientList, evals::EvaluationsList, multilinear::MultilinearPoint,
4346
},
4447
whir::{
4548
committer::{reader::CommitmentReader, CommitmentWriter},
4649
domainsep::WhirDomainSeparator,
47-
parameters::{DeduplicationStrategy, MerkleProofStrategy, WhirConfig},
50+
parameters::WhirConfig,
4851
prover::Prover,
4952
statement::{Statement, Weights},
5053
verifier::Verifier,
@@ -114,15 +117,12 @@ mod batching_tests {
114117
_pow_parameters: Default::default(),
115118
starting_log_inv_rate: 1,
116119
batch_size,
120+
deduplication_strategy: DeduplicationStrategy::Enabled,
121+
merkle_proof_strategy: MerkleProofStrategy::Compressed,
117122
};
118123

119124
// Build global configuration from multivariate + protocol parameters
120-
let params = WhirConfig::new(
121-
mv_params,
122-
whir_params,
123-
DeduplicationStrategy::Enabled,
124-
MerkleProofStrategy::Compressed,
125-
);
125+
let params = WhirConfig::new(mv_params, whir_params);
126126

127127
let mut poly_list = Vec::<CoefficientList<F>>::with_capacity(batch_size);
128128

src/whir/committer/writer.rs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -222,12 +222,12 @@ mod tests {
222222
parameters::default_config,
223223
},
224224
},
225-
parameters::{FoldingFactor, MultivariateParameters, ProtocolParameters, SoundnessType},
226-
poly_utils::multilinear::MultilinearPoint,
227-
whir::{
228-
domainsep::WhirDomainSeparator,
229-
parameters::{DeduplicationStrategy, MerkleProofStrategy},
225+
parameters::{
226+
DeduplicationStrategy, FoldingFactor, MerkleProofStrategy, MultivariateParameters,
227+
ProtocolParameters, SoundnessType,
230228
},
229+
poly_utils::multilinear::MultilinearPoint,
230+
whir::domainsep::WhirDomainSeparator,
231231
};
232232

233233
#[test]
@@ -264,16 +264,13 @@ mod tests {
264264
_pow_parameters: std::marker::PhantomData,
265265
starting_log_inv_rate: starting_rate,
266266
batch_size: 1,
267+
deduplication_strategy: DeduplicationStrategy::Enabled,
268+
merkle_proof_strategy: MerkleProofStrategy::Compressed,
267269
};
268270

269271
// Define multivariate parameters for the polynomial.
270272
let mv_params = MultivariateParameters::<F>::new(num_variables);
271-
let params = WhirConfig::<F, MerkleConfig, Blake3PoW>::new(
272-
mv_params,
273-
whir_params,
274-
DeduplicationStrategy::Enabled,
275-
MerkleProofStrategy::Compressed,
276-
);
273+
let params = WhirConfig::<F, MerkleConfig, Blake3PoW>::new(mv_params, whir_params);
277274

278275
// Generate a random polynomial with 32 coefficients.
279276
let polynomial = CoefficientList::new(vec![F::rand(&mut rng); 32]);
@@ -358,9 +355,9 @@ mod tests {
358355
_pow_parameters: Default::default(),
359356
starting_log_inv_rate: 1,
360357
batch_size: 1,
358+
deduplication_strategy: DeduplicationStrategy::Enabled,
359+
merkle_proof_strategy: MerkleProofStrategy::Compressed,
361360
},
362-
DeduplicationStrategy::Enabled,
363-
MerkleProofStrategy::Compressed,
364361
);
365362

366363
let polynomial = CoefficientList::new(vec![F::rand(&mut rng); 1024]); // Large polynomial
@@ -400,9 +397,9 @@ mod tests {
400397
_pow_parameters: Default::default(),
401398
starting_log_inv_rate: 1,
402399
batch_size: 1,
400+
deduplication_strategy: DeduplicationStrategy::Enabled,
401+
merkle_proof_strategy: MerkleProofStrategy::Compressed,
403402
},
404-
DeduplicationStrategy::Enabled,
405-
MerkleProofStrategy::Compressed,
406403
);
407404

408405
params.committment_ood_samples = 0; // No OOD samples

src/whir/mod.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,18 @@ mod tests {
2121
parameters::default_config,
2222
},
2323
},
24-
parameters::{FoldingFactor, MultivariateParameters, ProtocolParameters, SoundnessType},
24+
parameters::{
25+
DeduplicationStrategy, FoldingFactor, MerkleProofStrategy, MultivariateParameters,
26+
ProtocolParameters, SoundnessType,
27+
},
2528
poly_utils::{
2629
coeffs::CoefficientList, evals::EvaluationsList, multilinear::MultilinearPoint,
2730
},
2831
utils::test_serde,
2932
whir::{
3033
committer::{CommitmentReader, CommitmentWriter},
3134
domainsep::WhirDomainSeparator,
32-
parameters::{DeduplicationStrategy, MerkleProofStrategy, WhirConfig},
35+
parameters::WhirConfig,
3336
prover::Prover,
3437
statement::{Statement, Weights},
3538
verifier::Verifier,
@@ -87,15 +90,12 @@ mod tests {
8790
_pow_parameters: Default::default(),
8891
starting_log_inv_rate: 1,
8992
batch_size: 1,
93+
deduplication_strategy: DeduplicationStrategy::Enabled,
94+
merkle_proof_strategy: MerkleProofStrategy::Compressed,
9095
};
9196

9297
// Build global configuration from multivariate + protocol parameters
93-
let params = WhirConfig::new(
94-
mv_params,
95-
whir_params,
96-
DeduplicationStrategy::Enabled,
97-
MerkleProofStrategy::Compressed,
98-
);
98+
let params = WhirConfig::new(mv_params, whir_params);
9999

100100
// Test that the config is serializable
101101
eprintln!("{params:?}");

0 commit comments

Comments
 (0)