Skip to content

Commit 319f7df

Browse files
committed
feat: add tests
1 parent f5096be commit 319f7df

File tree

2 files changed

+62
-1
lines changed

2 files changed

+62
-1
lines changed

contracts/foundry.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ test = "test"
5959
allow_internal_expect_revert = true
6060

6161
[fuzz]
62-
runs = 1_000
62+
runs = 1_00000
6363

6464
[profile.ci]
6565
fuzz = { runs = 1_000 }

contracts/test/proofs/DeltaProof.t.sol

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity ^0.8.30;
33

4+
import {EllipticCurve} from "@elliptic-curve-solidity/contracts/EllipticCurve.sol";
45
import {Test} from "forge-std/Test.sol";
56

67
import {Delta} from "../../src/libs/proving/Delta.sol";
@@ -302,6 +303,66 @@ contract DeltaProofTest is Test {
302303
DeltaFuzzing.verify({proof: proof, instance: deltaAcc, verifyingKey: verifyingKey});
303304
}
304305

306+
function test_add_reverts_if_the_second_point_is_not_on_the_curve(uint8 k) public {
307+
// Generate a random point on the curve.
308+
Delta.Point memory p1 = _mul({p: Delta.Point({x: Delta._GX, y: Delta._GY}), k: k});
309+
assertTrue(
310+
EllipticCurve.isOnCurve({_x: p1.x, _y: p1.y, _aa: Delta._AA, _bb: Delta._BB, _pp: Delta._PP}),
311+
"Point 1 must be on the curve."
312+
);
313+
314+
Delta.Point memory p2 = Delta.zero();
315+
316+
// Attempt to add a point being not on the curve
317+
vm.expectRevert(abi.encodeWithSelector(Delta.PointNotOnCurve.selector, p2), address(this));
318+
p1.add(p2);
319+
}
320+
321+
function test_add_adding_two_curve_points_produces_a_point_on_the_curve(uint8 k1, uint8 k2) public pure {
322+
// Generate two random points on the curve.
323+
Delta.Point memory p1 = _mul({p: Delta.Point({x: Delta._GX, y: Delta._GY}), k: k1});
324+
assertTrue(
325+
EllipticCurve.isOnCurve({_x: p1.x, _y: p1.y, _aa: Delta._AA, _bb: Delta._BB, _pp: Delta._PP}),
326+
"Point 1 must be on the curve."
327+
);
328+
329+
Delta.Point memory p2 = _mul({p: Delta.Point({x: Delta._GX, y: Delta._GY}), k: k2});
330+
assertTrue(
331+
EllipticCurve.isOnCurve({_x: p2.x, _y: p2.y, _aa: Delta._AA, _bb: Delta._BB, _pp: Delta._PP}),
332+
"Point 2 must be on the curve."
333+
);
334+
335+
// Add the two points.
336+
Delta.Point memory sum = Delta.add(p1, p2);
337+
assertTrue(
338+
EllipticCurve.isOnCurve({_x: sum.x, _y: sum.y, _aa: Delta._AA, _bb: Delta._BB, _pp: Delta._PP}),
339+
"Sum must be on the curve."
340+
);
341+
}
342+
343+
function test_add_adding_a_curve_point_to_zero_produces_a_point_on_the_curve(uint8 k) public pure {
344+
Delta.Point memory zero = Delta.zero();
345+
346+
// Generate a random point on the curve.
347+
Delta.Point memory p = _mul({p: Delta.Point({x: Delta._GX, y: Delta._GY}), k: k});
348+
assertTrue(
349+
EllipticCurve.isOnCurve({_x: p.x, _y: p.y, _aa: Delta._AA, _bb: Delta._BB, _pp: Delta._PP}),
350+
"The point must be on the curve."
351+
);
352+
353+
// Add the two points.
354+
Delta.Point memory sum = zero.add(p);
355+
assertTrue(
356+
EllipticCurve.isOnCurve({_x: sum.x, _y: sum.y, _aa: Delta._AA, _bb: Delta._BB, _pp: Delta._PP}),
357+
"Sum must be on the curve."
358+
);
359+
}
360+
361+
function test_zero_is_not_on_the_curve() public pure {
362+
Delta.Point memory p2 = Delta.zero();
363+
assertFalse(EllipticCurve.isOnCurve({_x: p2.x, _y: p2.y, _aa: Delta._AA, _bb: Delta._BB, _pp: Delta._PP}));
364+
}
365+
305366
function test_verify_example_delta_proof() public pure {
306367
Transaction memory txn = TransactionExample.transaction();
307368

0 commit comments

Comments
 (0)