Skip to content

Commit f113185

Browse files
committed
Add test failing for unsupported relation
1 parent 0d35d47 commit f113185

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

src/tests/test_relations.rs

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ use group::prime::PrimeGroup;
55
use rand::rngs::OsRng;
66
use rand::RngCore;
77

8-
use ff::PrimeField;
98
use crate::fiat_shamir::Nizk;
109
use crate::{
1110
codec::Shake128DuplexSponge, linear_relation::CanonicalLinearRelation,
1211
schnorr_protocol::SchnorrProof,
1312
};
13+
use ff::PrimeField;
1414

1515
use crate::linear_relation::{msm_pr, LinearRelation};
1616

@@ -235,7 +235,6 @@ pub fn bbs_blind_commitment<G: PrimeGroup, R: RngCore>(
235235
(instance, witness)
236236
}
237237

238-
239238
/// LinearMap for the user's specific relation: A * 1 + gen__disj1_x_r * B
240239
#[allow(non_snake_case)]
241240
pub fn weird_linear_combination<G: PrimeGroup, R: RngCore>(
@@ -267,7 +266,6 @@ pub fn weird_linear_combination<G: PrimeGroup, R: RngCore>(
267266
(instance, witness)
268267
}
269268

270-
271269
fn simple_subtractions<G: PrimeGroup, R: RngCore>(
272270
mut rng: &mut R,
273271
) -> (CanonicalLinearRelation<G>, Vec<G::Scalar>) {
@@ -278,8 +276,7 @@ fn simple_subtractions<G: PrimeGroup, R: RngCore>(
278276
let mut linear_relation = LinearRelation::<G>::new();
279277
let x_var = linear_relation.allocate_scalar();
280278
let B_var = linear_relation.allocate_element();
281-
let X_var = linear_relation
282-
.allocate_eq((x_var + (-G::Scalar::from_u128(1u128))) * B_var);
279+
let X_var = linear_relation.allocate_eq((x_var + (-G::Scalar::from_u128(1u128))) * B_var);
283280
linear_relation.set_element(B_var, B);
284281
linear_relation.set_element(X_var, X);
285282

@@ -291,16 +288,15 @@ fn simple_subtractions<G: PrimeGroup, R: RngCore>(
291288
fn subtractions_with_shift<G: PrimeGroup, R: RngCore>(
292289
mut rng: &mut R,
293290
) -> (CanonicalLinearRelation<G>, Vec<G::Scalar>) {
294-
295291
let B = G::generator();
296292
let x = G::Scalar::random(&mut rng);
297293
let X = B * (x - G::Scalar::from(2));
298294

299295
let mut linear_relation = LinearRelation::<G>::new();
300296
let x_var = linear_relation.allocate_scalar();
301297
let B_var = linear_relation.allocate_element();
302-
let X_var = linear_relation
303-
.allocate_eq((x_var + (-G::Scalar::from_u128(1u128))) * B_var + (-B_var));
298+
let X_var =
299+
linear_relation.allocate_eq((x_var + (-G::Scalar::from_u128(1u128))) * B_var + (-B_var));
304300

305301
linear_relation.set_element(B_var, B);
306302
linear_relation.set_element(X_var, X);
@@ -309,6 +305,26 @@ fn subtractions_with_shift<G: PrimeGroup, R: RngCore>(
309305
(instance, witness)
310306
}
311307

308+
#[allow(dead_code)]
309+
fn without_witness<G: PrimeGroup, R: RngCore>(
310+
mut rng: &mut R,
311+
) -> (CanonicalLinearRelation<G>, Vec<G::Scalar>) {
312+
let B = G::generator();
313+
let x = G::Scalar::random(&mut rng);
314+
// let X = B * (x + G::Scalar::from(3));
315+
316+
let mut linear_relation = LinearRelation::<G>::new();
317+
let B_var = linear_relation.allocate_element();
318+
// let X_var =
319+
// linear_relation.allocate_eq(B * x + B * G::Scalar::from_u128(3u128));
320+
321+
linear_relation.set_element(B_var, B);
322+
// linear_relation.set_element(X_var, X);
323+
let instance = (&linear_relation).try_into().unwrap();
324+
let witness = vec![x];
325+
(instance, witness)
326+
}
327+
312328
/// Generic helper function to test both relation correctness and NIZK functionality
313329
#[test]
314330
fn test_common_relations() {

0 commit comments

Comments
 (0)