Skip to content

Commit c0cf76a

Browse files
committed
test: doublecheck shifted dlog works with distributive property.
1 parent 87c20d4 commit c0cf76a

File tree

1 file changed

+6
-26
lines changed

1 file changed

+6
-26
lines changed

src/tests/test_relations.rs

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub fn discrete_logarithm<G: PrimeGroup, R: rand::RngCore>(
4040

4141
/// LinearMap for knowledge of a shifted discrete logarithm relative to a fixed basepoint.
4242
#[allow(non_snake_case)]
43-
pub fn shifted_discrete_logarithm<G: PrimeGroup, R: RngCore>(
43+
pub fn shifted_dlog<G: PrimeGroup, R: RngCore>(
4444
rng: &mut R,
4545
) -> (CanonicalLinearRelation<G>, Vec<G::Scalar>) {
4646
let x = G::Scalar::random(rng);
@@ -49,14 +49,14 @@ pub fn shifted_discrete_logarithm<G: PrimeGroup, R: RngCore>(
4949
let var_x = relation.allocate_scalar();
5050
let var_G = relation.allocate_element();
5151

52-
let var_X = relation.allocate_eq((var_x + <G::Scalar as Field>::ONE) * var_G);
52+
let var_X = relation.allocate_eq(var_G * var_x + var_G * <G::Scalar as Field>::ONE);
53+
// another way of writing this is:
54+
relation.append_equation(var_X, (var_x + <G::Scalar as Field>::ONE) * var_G);
55+
5356

5457
relation.set_element(var_G, G::generator());
5558
relation.compute_image(&[x]).unwrap();
5659

57-
let X = relation.linear_map.group_elements.get(var_X).unwrap();
58-
59-
assert!(vec![X] == relation.linear_map.evaluate(&[x]).unwrap());
6060
let witness = vec![x];
6161
let instance = (&relation).try_into().unwrap();
6262
(instance, witness)
@@ -305,26 +305,6 @@ fn subtractions_with_shift<G: PrimeGroup, R: RngCore>(
305305
(instance, witness)
306306
}
307307

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-
328308
/// Generic helper function to test both relation correctness and NIZK functionality
329309
#[test]
330310
fn test_common_relations() {
@@ -337,7 +317,7 @@ fn test_common_relations() {
337317
>::new();
338318

339319
instance_generators.insert("dlog", Box::new(discrete_logarithm));
340-
instance_generators.insert("shifted_dlog", Box::new(shifted_discrete_logarithm));
320+
instance_generators.insert("shifted_dlog", Box::new(shifted_dlog));
341321
instance_generators.insert("dleq", Box::new(dleq));
342322
instance_generators.insert("shifted_dleq", Box::new(shifted_dleq));
343323
instance_generators.insert("pedersen_commitment", Box::new(pedersen_commitment));

0 commit comments

Comments
 (0)