You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description: The implementation of the montgomerySub(a, b) fallbacks to montgomeryAdd(a, P-b). This however can be implemented more efficiently as:
compute difference a - b,
add back P if the difference overflows.
The change gives 4% gas cost reduction.
Recommendation: Change the implementation of montgomerySub() to:
diff --git a/precompiles/EcPairing.yul b/precompiles/EcPairing.yul
index f70813e..4e0c526 100644
--- a/precompiles/EcPairing.yul+++ b/precompiles/EcPairing.yul@@ -319,7 +319,10 @@ object "EcPairing" {
/// @param subtrahend The subtrahend in Montgomery form.
/// @return ret The result of the Montgomery addition.
function montgomerySub(minuend, subtrahend) -ret {
- ret := montgomeryAdd(minuend, sub(P(), subtrahend))+ ret := sub(minuend, subtrahend)+ if lt(minuend, subtrahend) {+ ret := add(ret, P())+ }
}
/// @notice Computes the Montgomery multiplication using the Montgomery reduction algorithm (REDC).
zkSync:
Spearbit:
The text was updated successfully, but these errors were encountered:
Context: EcPairing.yul#L314
Description: The implementation of the
montgomerySub(a, b)
fallbacks tomontgomeryAdd(a, P-b)
. This however can be implemented more efficiently as:a - b
,P
if the difference overflows.The change gives 4% gas cost reduction.
Recommendation: Change the implementation of
montgomerySub()
to:zkSync:
Spearbit:
The text was updated successfully, but these errors were encountered: