Skip to content

Commit 2d539d1

Browse files
committed
isInfinity() and isOnCurve() methods
1 parent e1fae41 commit 2d539d1

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/Secp256Lib.sol

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,20 @@ library Secp256k1 {
88
// p = 2^256 - 2^32 - 977
99
uint256 constant p = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F;
1010

11-
function isOnCurve() internal {}
12-
function isInfinity() internal {}
11+
// Check if the point is infinity
12+
function isInfinity(uint256 x, uint256 y) internal pure returns (bool) {
13+
return x == 0 && y == 0;
14+
}
15+
16+
// y^2 ≡ x^3 + 7 (mod p)
17+
// Check if the point is on curve
18+
function isOnCurve(uint256 x, uint256 y) internal pure returns (bool) {
19+
uint256 leftHandSide = mulmod(y, y, p); // y^2 mod p
20+
uint256 xCubed = mulmod(x, mulmod(x, x, p), p); // x^3 mod p
21+
uint256 rightHandSide = addmod(xCubed, 7, p); // (x*3 + 8) mod p
22+
return leftHandSide == rightHandSide;
23+
}
24+
1325
function addPoint() internal {}
1426
function negatePoint() internal {}
1527
function orderOfPoint() internal {}

0 commit comments

Comments
 (0)