Skip to content

Commit 15d67b7

Browse files
committed
negate point
1 parent 2d539d1 commit 15d67b7

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/Secp256Lib.sol

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
pragma solidity ^0.8.13;
33

44
library Secp256k1 {
5+
error Secp256k1__InvalidPoint(uint256 x, uint256 y);
6+
57
// Curve parameters for secp256k1
68
uint256 constant a = 0;
79
uint256 constant b = 7;
@@ -22,8 +24,13 @@ library Secp256k1 {
2224
return leftHandSide == rightHandSide;
2325
}
2426

27+
function negatePoint(uint256 x, uint256 y) internal pure returns (uint256, uint256) {
28+
if (!isOnCurve(x, y)) revert Secp256k1__InvalidPoint(x, y);
29+
if (isInfinity(x, y)) return (x, y);
30+
return (x, p - y);
31+
}
32+
2533
function addPoint() internal {}
26-
function negatePoint() internal {}
2734
function orderOfPoint() internal {}
2835
function scalarMultiply() internal {}
2936
}

0 commit comments

Comments
 (0)