@@ -135,7 +135,7 @@ contract Secp256k1Test is Test {
135
135
136
136
// ! Expecting revert with internal function calls -> https://book.getfoundry.sh/cheatcodes/expect-revert?highlight=expectRevert#error
137
137
/// forge-config: default.allow_internal_expect_revert = true
138
- function testFuzz_negatePointUnchecked_OutOfBounds (uint256 x , uint256 y ) public {
138
+ function testFuzz_negatePointUnchecked_RevertIf_OutOfBounds (uint256 x , uint256 y ) public {
139
139
x = bound (x, Secp256k1.p + 1 , UINT256_MAX);
140
140
y = bound (y, Secp256k1.p + 1 , UINT256_MAX);
141
141
console.log (x, y);
@@ -259,6 +259,30 @@ contract Secp256k1Test is Test {
259
259
vm.expectRevert (abi.encodeWithSelector (Secp256k1.Secp256k1__InvalidPoint.selector , x, y));
260
260
Secp256k1.addPoints (x, y, Gx, Gy);
261
261
}
262
-
263
262
// TODO -> add gas tests for unchecked
263
+ // TODO -> add tests for doubling point
264
+
265
+ // ! -----------------------------------------------------------------------------------------------------------------------
266
+ // ! modInverse() TESTS
267
+ // ! -----------------------------------------------------------------------------------------------------------------------
268
+ function testFuzz_modInverse (uint256 number ) public pure {
269
+ number = bound (number, 1 , Secp256k1.p - 1 );
270
+ uint256 inverse = Secp256k1.modInverse (number);
271
+ assertEq (mulmod (number, inverse, Secp256k1.p), 1 );
272
+ }
273
+
274
+ // ! -----------------------------------------------------------------------------------------------------------------------
275
+ // ! modPow() TESTS
276
+ // ! -----------------------------------------------------------------------------------------------------------------------
277
+ function testFuzz_ModPow (uint256 base , uint256 exponent ) public pure {
278
+ // To avoid high gas cost in the fuzz test, restricted the exponent to a reasonable range.
279
+ vm.assume (exponent < 1_000_000 );
280
+
281
+ uint256 result = Secp256k1.modPow (base, exponent);
282
+ uint256 expected = 1 ;
283
+ for (uint256 i = 0 ; i < exponent; i++ ) {
284
+ expected = mulmod (expected, base, Secp256k1.p);
285
+ }
286
+ assertEq (result, expected);
287
+ }
264
288
}
0 commit comments