Skip to content

Commit

Permalink
grumpkin point contract
Browse files Browse the repository at this point in the history
  • Loading branch information
kitounliu committed Feb 28, 2024
1 parent cb66d77 commit 5e5e701
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions contracts/libs/Grumpkin.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// This file is MIT Licensed.
pragma solidity ^0.8.0;

library Grumpkin {
struct Point {
uint X;
uint Y;
}

/// Check if point is valid.
function isOnCurve(
Point memory a
) internal view returns (bool) {
uint r = 21888242871839275222246405745257275088548364400416034343698204186575808495617;

// Y^2 = X^3 - 17
uint y2 = mulmod(a.Y, a.Y, r);
uint z = addmod(y2, 17, r);
uint x2 = mulmod(a.X, a.X, r);
uint x3 = mulmod(a.X, x2, r);

return z == x3;
}
}

0 comments on commit 5e5e701

Please sign in to comment.