Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more tests for assert_equal_point #726

Merged
merged 2 commits into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Add tests for assert_equal_point method
Resolves #725
  • Loading branch information
moCello committed Jan 24, 2023
commit 8690aa92145764d8ec89302b270512ed41def6ee
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Add tests for `assert_equal_point` [#725]

### Removed

- Remove `bit_iterator` macro [#632]
Expand Down Expand Up @@ -453,6 +457,7 @@ is necessary since `rkyv/validation` was required as a bound.
- Proof system module.

<!-- ISSUES -->
[#725]: https://github.com/dusk-network/plonk/issues/725
[#721]: https://github.com/dusk-network/plonk/issues/721
[#717]: https://github.com/dusk-network/plonk/issues/717
[#709]: https://github.com/dusk-network/plonk/issues/709
Expand Down
106 changes: 90 additions & 16 deletions tests/ecc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ fn mul_point_works() {
}

#[test]
fn assert_equal_point_different_y_fails() {
fn assert_equal_point_works() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest having only one circuit that executes the assertation, and the function is called with two points as arguments. Then, compute each variant in each test and call that circuit.

Copy link
Member Author

@moCello moCello Jan 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'm actually just doing these changes! Was a bit too quick setting the PR as done, sorry!

let rng = &mut StdRng::seed_from_u64(8349u64);

let n = 1 << 4;
Expand All @@ -318,17 +318,17 @@ fn assert_equal_point_different_y_fails() {
p2: JubJubAffine,
}

impl DummyCircuit {
pub fn new(p1: JubJubAffine, p2: JubJubAffine) -> Self {
Self { p1, p2 }
}
}

impl Default for DummyCircuit {
fn default() -> Self {
Self {
p1: JubJubAffine::from_raw_unchecked(
BlsScalar::one(),
BlsScalar::one(),
),
p2: JubJubAffine::from_raw_unchecked(
BlsScalar::one(),
BlsScalar::zero(),
),
p1: dusk_jubjub::GENERATOR,
p2: dusk_jubjub::GENERATOR,
}
}
}
Expand All @@ -338,21 +338,95 @@ fn assert_equal_point_different_y_fails() {
where
C: Composer,
{
// test: p1 != p2
let w_p1 = composer.append_point(self.p1);
let w_p2 = composer.append_point(self.p2);
composer.assert_equal_point(w_p1, w_p2);

Ok(())
}
}

let (prover, _verifier) = Compiler::compile::<DummyCircuit>(&pp, label)
let (prover, verifier) = Compiler::compile::<DummyCircuit>(&pp, label)
.expect("failed to compile circuit");

let proving_result = prover.prove(rng, &Default::default());
// Test default works:
// GENERATOR = GENERATOR
{
let (proof, public_inputs) = prover
.prove(rng, &Default::default())
.expect("prover shouldn't fail");

assert_eq!(public_inputs.len(), 0);

assert!(
proving_result.is_err(),
"proving should fail because the y coordinates don't match"
);
verifier
.verify(&proof, &public_inputs)
.expect("Default circuit verification should pass");
}

// Test sanity:
// 42 * GENERATOR = 42 * GENERATOR
{
let scalar = JubJubScalar::from(42u64);
let p1 = dusk_jubjub::GENERATOR_EXTENDED * &scalar;
let p2 = dusk_jubjub::GENERATOR_EXTENDED * &scalar;
let circuit = DummyCircuit::new(p1.into(), p2.into());

let (proof, public_inputs) =
prover.prove(rng, &circuit).expect("prover shouldn't fail");

assert_eq!(public_inputs.len(), 0);

verifier
.verify(&proof, &public_inputs)
.expect("Circuit verification with equal points should pass");
}

// Test:
// GENERATOR != 42 * GENERATOR
{
let scalar = JubJubScalar::from(42u64);
let p1 = dusk_jubjub::GENERATOR;
let p2 = dusk_jubjub::GENERATOR_EXTENDED * &scalar;
let circuit = DummyCircuit::new(p1, p2.into());

prover
.prove(rng, &circuit)
.expect_err("prover should fail because the points are not equal");
}

// Test:
// assertion of points with different x-coordinates fails
{
let p1 = JubJubAffine::from_raw_unchecked(
BlsScalar::one(),
BlsScalar::one(),
);
let p2 = JubJubAffine::from_raw_unchecked(
BlsScalar::zero(),
BlsScalar::one(),
);
let circuit = DummyCircuit::new(p1, p2);

prover
.prove(rng, &circuit)
.expect_err("prover should fail because the x-coordinates of the points are not equal");
}

// Test:
// assertion of points with different y-coordinates fails
{
let p1 = JubJubAffine::from_raw_unchecked(
BlsScalar::one(),
BlsScalar::one(),
);
let p2 = JubJubAffine::from_raw_unchecked(
BlsScalar::one(),
BlsScalar::zero(),
);
let circuit = DummyCircuit::new(p1, p2);

prover
.prove(rng, &circuit)
.expect_err("prover should fail because the y-coordinates of the points are not equal");
}
}