From 3afdc81744da99f7ac955574eaf471079402962d Mon Sep 17 00:00:00 2001 From: Marc Date: Wed, 11 Dec 2024 23:11:32 +0000 Subject: [PATCH] Bls Pairing check optimisation: skip exp for infinity (#7883) --- .../Nethermind.Evm/Precompiles/Bls/PairingCheckPrecompile.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/PairingCheckPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/PairingCheckPrecompile.cs index 6be90e9054a..75cd9167364 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/PairingCheckPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/PairingCheckPrecompile.cs @@ -46,6 +46,7 @@ private PairingCheckPrecompile() { } var acc = GT.One(buf.AsSpan()); GT p = new(buf.AsSpan()[GT.Sz..]); + bool hasInf = false; for (int i = 0; i < inputData.Length / PairSize; i++) { int offset = i * PairSize; @@ -61,6 +62,7 @@ private PairingCheckPrecompile() { } // x == inf || y == inf -> e(x, y) = 1 if (x.IsInf() || y.IsInf()) { + hasInf = true; continue; } @@ -68,7 +70,7 @@ private PairingCheckPrecompile() { } acc.Mul(p); } - bool verified = acc.FinalExp().IsOne(); + bool verified = hasInf || acc.FinalExp().IsOne(); byte[] res = new byte[32]; if (verified) {