@@ -40,28 +40,29 @@ contract P256Verifier {
4040 return abi.encodePacked (ret);
4141 }
4242
43- // Parameters for the sec256r1 (P256) elliptic curve
44- // Curve prime field modulus
43+ // Parameters for the secp256r1 (P256) elliptic curve
44+ /// P256 curve prime field modulus
4545 uint256 private constant p =
4646 0xFFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF ;
47- // Short weierstrass first coefficient
47+ /// Short weierstrass first coefficient
4848 uint256 private constant a = // The assumption a == -3 (mod p) is used throughout the codebase
4949 0xFFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFC ;
50- // Short weierstrass second coefficient
50+ /// Short weierstrass second coefficient
5151 uint256 private constant b =
5252 0x5AC635D8AA3A93E7B3EBBD55769886BC651D06B0CC53B0F63BCE3C3E27D2604B ;
53- // Generating point affine coordinates
53+ /// Generating point affine x-coordinate
5454 uint256 private constant GX =
5555 0x6B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C296 ;
56+ /// Generating point affine y-coordinate
5657 uint256 private constant GY =
5758 0x4FE342E2FE1A7F9B8EE7EB4A7C0F9E162BCE33576B315ECECBB6406837BF51F5 ;
58- // Curve order (number of points)
59+ /// Curve order (number of points)
5960 uint256 private constant n =
6061 0xFFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9CAC2FC632551 ;
61- // -2 mod p constant, used to speed up inversion and doubling (avoid negation)
62+ /// -2 mod p constant, used to speed up inversion and doubling (avoid negation)
6263 uint256 private constant minus_2modp =
6364 0xFFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFD ;
64- // -2 mod n constant, used to speed up inversion
65+ /// -2 mod n constant, used to speed up inversion
6566 uint256 private constant minus_2modn =
6667 0xFFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9CAC2FC63254F ;
6768
@@ -98,8 +99,8 @@ contract P256Verifier {
9899 }
99100
100101 /**
101- * @dev Check if a point in affine coordinates is on the curve
102- * Reject 0 point at infinity.
102+ * @dev Check if a point in affine coordinates is on the curve.
103+ * Reject the 0 point at infinity.
103104 */
104105 function ecAff_isValidPubkey (
105106 uint256 x ,
@@ -109,13 +110,6 @@ contract P256Verifier {
109110 return false ;
110111 }
111112
112- return ecAff_satisfiesCurveEqn (x, y);
113- }
114-
115- function ecAff_satisfiesCurveEqn (
116- uint256 x ,
117- uint256 y
118- ) internal pure returns (bool ) {
119113 uint256 LHS = mulmod (y, y, p); // y^2
120114 uint256 RHS = addmod (mulmod (mulmod (x, x, p), x, p), mulmod (a, x, p), p); // x^3 + a x
121115 RHS = addmod (RHS, b, p); // x^3 + a*x + b
@@ -124,9 +118,10 @@ contract P256Verifier {
124118 }
125119
126120 /**
127- * @dev Computation of uG + vQ using Strauss-Shamir's trick, G basepoint, Q public key
128- * returns tuple of (x coordinate of uG + vQ, boolean that is false if internal precompile staticcall fail)
129- * Strauss-Shamir is described well in https://stackoverflow.com/a/50994362
121+ * @dev Computation of uG + vQ using Strauss-Shamir's trick, G basepoint,
122+ * Q public key. Strauss-Shamir is described well in the following post:
123+ * https://stackoverflow.com/a/50994362
124+ * @return X The x-coordinate of uG + vQ
130125 */
131126 function ecZZ_mulmuladd (
132127 uint256 QX ,
@@ -243,16 +238,15 @@ contract P256Verifier {
243238 }
244239
245240 /**
246- * @dev Check if a point is the infinity point in ZZ rep.
247- * Assumes point is on the EC or is the point at infinity.
241+ * @dev Checks if a point is the infinity point in ZZ rep, using only the zz
242+ * and zzz coordinates. Assumes the point is on the curve or at infinity.
248243 */
249244 function ecZZ_IsInf (
250245 uint256 zz ,
251246 uint256 zzz
252247 ) internal pure returns (bool flag ) {
253248 // invariant((zz == 0 && zzz == 0) || ecAff_isOnCurve(x, y) for affine
254249 // form of the point)
255-
256250 return (zz == 0 && zzz == 0 );
257251 }
258252
0 commit comments