Skip to content

Commit 36e657e

Browse files
committed
doublePointUnchecked() tests
1 parent d471e77 commit 36e657e

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

test/Secp256k1.t.sol

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,36 @@ contract Secp256k1Test is Test {
309309
Secp256k1.doublePoint(x, y);
310310
}
311311

312+
// ! -----------------------------------------------------------------------------------------------------------------------
313+
// ! doublePointUnchecked() TESTS
314+
// ! -----------------------------------------------------------------------------------------------------------------------
315+
function doublePointUnchecked() public pure {
316+
(uint256 x, uint256 y) = Secp256k1.doublePointUnchecked(Gx, Gy);
317+
assertEq(x, G2x);
318+
assertEq(y, G2y);
319+
320+
// Just checking that this wont fail
321+
(uint256 G3x, uint256 G3y) = Secp256k1.doublePointUnchecked(G2x, G2y);
322+
Secp256k1.doublePointUnchecked(G3x, G3y);
323+
}
324+
325+
function test_doublePointUnchecked_Infinity() public pure {
326+
(uint256 x, uint256 y) = Secp256k1.doublePointUnchecked(0, 0);
327+
assertEq(x, 0);
328+
assertEq(y, 0);
329+
}
330+
331+
// ! Expecting revert with internal function calls -> https://book.getfoundry.sh/cheatcodes/expect-revert?highlight=expectRevert#error
332+
/// forge-config: default.allow_internal_expect_revert = true
333+
function testFuzz_doublePointUnchecked_RevertIf_OutOfBounds(uint256 x, uint256 y) public {
334+
x = bound(x, Secp256k1.p + 1, UINT256_MAX);
335+
y = bound(y, Secp256k1.p + 1, UINT256_MAX);
336+
console.log(x, y);
337+
// underflow or overflow
338+
vm.expectRevert(0x11);
339+
Secp256k1.doublePointUnchecked(x, y);
340+
}
341+
312342
// ! -----------------------------------------------------------------------------------------------------------------------
313343
// ! modInverse() TESTS
314344
// ! -----------------------------------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)