lambdaclass/zksync_era_precompiles

Redundant point-at-infinity check in `projectiveAdd()`

Closed this issue · 1 comments

Context: P256VERIFY.yul#L442

Description:

In the projectiveAdd() the check if and(pIsInfinity, qIsInfinity) is redundant. In this case where both $P$ and $Q$ are points at infinity will be properly handled by if pIsInfinity: the $Q$ will be returned which is already the point at infinity.

Recommendation:

Remove the if and(pIsInfinity, qIsInfinity) check.

diff --git a/precompiles/P256VERIFY.yul b/precompiles/P256VERIFY.yul
index c75be80..4baca50 100644
--- a/precompiles/P256VERIFY.yul
+++ b/precompiles/P256VERIFY.yul
@@ -439,13 +439,6 @@ object "P256VERIFY" {
             function projectiveAdd(xp, yp, zp, xq, yq, zq) -> xr, yr, zr {
                 let qIsInfinity := projectivePointIsInfinity(xq, yq, zq)
                 let pIsInfinity := projectivePointIsInfinity(xp, yp, zp)
-                if and(pIsInfinity, qIsInfinity) {
-                    // Infinity + Infinity = Infinity
-                    xr := 0
-                    yr := MONTGOMERY_ONE_P()
-                    zr := 0
-                    leave
-                }
                 if pIsInfinity {
                     // Infinity + Q = Q
                     xr := xq

Resolved in #200