Skip to content

Commit ee0ab94

Browse files
committed
fix: tests for OR composition.
1 parent 78c6d97 commit ee0ab94

File tree

1 file changed

+20
-24
lines changed

1 file changed

+20
-24
lines changed

src/tests/test_validation_criteria.rs

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,6 @@ mod proof_validation {
399399
let eq1 = lr1.allocate_eq(x_var * A_var);
400400
lr1.set_element(A_var, A);
401401
lr1.set_element(eq1, C);
402-
403402
// Create the second branch: C = y*B
404403
let mut lr2 = LinearRelation::new();
405404
let y_var = lr2.allocate_scalar();
@@ -413,45 +412,42 @@ mod proof_validation {
413412
ComposedRelation::from(lr1),
414413
ComposedRelation::from(lr2),
415414
]);
416-
417-
let nizk =or_relation.into_nizk(b"test_or_bug");
415+
let nizk = or_relation.into_nizk(b"test_or_relation");
418416

419417
// Create a correct witness for branch 1 (C = y*B)
418+
// Note: x is NOT a valid witness for branch 0 because C ≠ x*A
420419
let witness_correct = ComposedWitness::Or(vec![
421420
ComposedWitness::Simple(vec![x]),
422421
ComposedWitness::Simple(vec![y]),
423422
]);
424-
425-
// This should succeed since branch 1 is correct
426423
let proof = nizk.prove_batchable(&witness_correct, &mut rng).unwrap();
427424
assert!(
428425
nizk.verify_batchable(&proof).is_ok(),
429426
"Valid proof should verify"
430427
);
431428

432-
// Now test with wrong witness: using branch 0 when it's not satisfied
433-
// Branch 0 requires C = x*A, but C = y*B and A ≠ B, so x would need to be y/42
429+
// Now test with ONLY invalid witnesses (neither branch satisfied)
430+
// Branch 0 requires C = x*A, but we use random x
431+
// Branch 1 requires C = y*B, but we use a different random value
432+
let wrong_y = Scalar::random(&mut rng);
434433
let witness_wrong = ComposedWitness::Or(vec![
435434
ComposedWitness::Simple(vec![x]),
436-
ComposedWitness::Simple(vec![y]),
435+
ComposedWitness::Simple(vec![wrong_y]),
437436
]);
438437
let proof_result = nizk.prove_batchable(&witness_wrong, &mut rng);
438+
assert!(proof_result.is_err(), "Proof should fail with invalid witnesses");
439+
440+
441+
// Create a correct witness for both branches
442+
let witness_correct = ComposedWitness::Or(vec![
443+
ComposedWitness::Simple(vec![y]),
444+
ComposedWitness::Simple(vec![y]),
445+
]);
446+
let proof = nizk.prove_batchable(&witness_correct, &mut rng).unwrap();
447+
assert!(
448+
nizk.verify_batchable(&proof).is_ok(),
449+
"Prover fails when all witnesses in an OR proof are valid"
450+
);
439451

440-
match proof_result {
441-
Ok(proof) => {
442-
let verify_result = nizk.verify_batchable(&proof);
443-
println!(
444-
"Proof with wrong branch verified: {:?}",
445-
verify_result.is_ok()
446-
);
447-
assert!(
448-
verify_result.is_err(),
449-
"Proof should fail when using wrong branch in OR relation, but it passed!"
450-
);
451-
}
452-
Err(e) => {
453-
println!("Proof generation failed as expected: {e:?}");
454-
}
455-
}
456452
}
457453
}

0 commit comments

Comments
 (0)