Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bls pairing check optimisation: precompute lines #7884

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
precompute lines for pairing
Marchhill committed Dec 10, 2024
commit 62e66cbdf43095a478ef9addd1421b3c350d1d44
2 changes: 1 addition & 1 deletion src/Nethermind/Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -45,7 +45,7 @@
<PackageVersion Include="Microsoft.IO.RecyclableMemoryStream" Version="3.0.1" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageVersion Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.21.0" />
<PackageVersion Include="Nethermind.Crypto.Bls" Version="1.0.4" />
<PackageVersion Include="Nethermind.Crypto.Bls" Version="1.0.4-preview.25" />
<PackageVersion Include="Nethermind.Crypto.Pairings" Version="1.1.1" />
<PackageVersion Include="Nethermind.Crypto.SecP256k1" Version="1.4.0" />
<PackageVersion Include="Nethermind.DotNetty.Buffers" Version="1.0.1" />
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@ namespace Nethermind.Evm.Precompiles.Bls;
public class PairingCheckPrecompile : IPrecompile<PairingCheckPrecompile>
{
private const int PairSize = 384;
private const int PrecomputeLinesSize = 6 * 6 * 68;
public static readonly PairingCheckPrecompile Instance = new();

private PairingCheckPrecompile() { }
@@ -42,9 +43,10 @@ private PairingCheckPrecompile() { }
G1 x = new(stackalloc long[G1.Sz]);
G2 y = new(stackalloc long[G2.Sz]);

using ArrayPoolList<long> buf = new(GT.Sz * 2, GT.Sz * 2);
using ArrayPoolList<long> buf = new(GT.Sz * 2 + PrecomputeLinesSize, GT.Sz * 2 + PrecomputeLinesSize);
var acc = GT.One(buf.AsSpan());
GT p = new(buf.AsSpan()[GT.Sz..]);
GT p = new(buf.AsSpan()[GT.Sz..(GT.Sz * 2)]);
Span<long> lines = buf.AsSpan()[(GT.Sz * 2)..];

for (int i = 0; i < inputData.Length / PairSize; i++)
{
@@ -64,7 +66,8 @@ private PairingCheckPrecompile() { }
continue;
}

p.MillerLoop(y, x);
y.ToAffine().PrecomputeLines(lines);
p.MillerLoopLines(lines, x.ToAffine());
acc.Mul(p);
}