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 precompiles: remove MUL #7932

Merged
merged 5 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class BlsG1MulPrecompileTests
[Test]
public void Test()
{
IPrecompile precompile = G1MulPrecompile.Instance;
IPrecompile precompile = G1MSMPrecompile.Instance;

foreach ((byte[] input, ReadOnlyMemory<byte> expectedResult) in Inputs)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public void Test()
{
foreach ((byte[] input, ReadOnlyMemory<byte> expectedResult) in Inputs)
{
IPrecompile precompile = G2MulPrecompile.Instance;
IPrecompile precompile = G2MSMPrecompile.Instance;
(ReadOnlyMemory<byte> output, bool success) = precompile.Run(input, MuirGlacier.Instance);
output.ToArray().Should().BeEquivalentTo(expectedResult.ToArray());
success.Should().BeTrue();
Expand Down
2 changes: 0 additions & 2 deletions src/Nethermind/Nethermind.Evm/CodeInfoRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,8 @@ private static FrozenDictionary<AddressAsKey, CodeInfo> InitializePrecompiledCon
[Blake2FPrecompile.Address] = new(Blake2FPrecompile.Instance),

[G1AddPrecompile.Address] = new(G1AddPrecompile.Instance),
[G1MulPrecompile.Address] = new(G1MulPrecompile.Instance),
[G1MSMPrecompile.Address] = new(G1MSMPrecompile.Instance),
[G2AddPrecompile.Address] = new(G2AddPrecompile.Instance),
[G2MulPrecompile.Address] = new(G2MulPrecompile.Instance),
[G2MSMPrecompile.Address] = new(G2MSMPrecompile.Instance),
[PairingCheckPrecompile.Address] = new(PairingCheckPrecompile.Instance),
[MapFpToG1Precompile.Address] = new(MapFpToG1Precompile.Instance),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ private G1MSMPrecompile()
{
}

public static Address Address { get; } = Address.FromNumber(0x0d);
public static Address Address { get; } = Address.FromNumber(0x0c);

public long BaseGasCost(IReleaseSpec releaseSpec) => 0L;

Expand Down
59 changes: 0 additions & 59 deletions src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MulPrecompile.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ private G2AddPrecompile()
{
}

public static Address Address { get; } = Address.FromNumber(0x0e);
public static Address Address { get; } = Address.FromNumber(0x0d);

public long BaseGasCost(IReleaseSpec releaseSpec) => 600L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ private G2MSMPrecompile()
{
}

public static Address Address { get; } = Address.FromNumber(0x10);
public static Address Address { get; } = Address.FromNumber(0xe);

public long BaseGasCost(IReleaseSpec releaseSpec) => 0L;

Expand Down
61 changes: 0 additions & 61 deletions src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MulPrecompile.cs
Original file line number Diff line number Diff line change
@@ -1,61 +0,0 @@
// SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using System;
using System.Runtime.CompilerServices;
using Nethermind.Core;
using Nethermind.Core.Specs;

using G2 = Nethermind.Crypto.Bls.P2;

namespace Nethermind.Evm.Precompiles.Bls;

/// <summary>
/// https://eips.ethereum.org/EIPS/eip-2537
/// </summary>
public class G2MulPrecompile : IPrecompile<G2MulPrecompile>
{
public static readonly G2MulPrecompile Instance = new();

private G2MulPrecompile()
{
}

public static Address Address { get; } = Address.FromNumber(0x0f);

public long BaseGasCost(IReleaseSpec releaseSpec) => 22500L;

public long DataGasCost(ReadOnlyMemory<byte> inputData, IReleaseSpec releaseSpec) => 0L;

[SkipLocalsInit]
public (ReadOnlyMemory<byte>, bool) Run(ReadOnlyMemory<byte> inputData, IReleaseSpec releaseSpec)
{
Metrics.BlsG2MulPrecompile++;

const int expectedInputLength = BlsConst.LenG2 + BlsConst.LenFr;

if (inputData.Length != expectedInputLength)
{
return IPrecompile.Failure;
}

G2 x = new(stackalloc long[G2.Sz]);
if (!x.TryDecodeRaw(inputData[..BlsConst.LenG2].Span) || !(BlsConst.DisableSubgroupChecks || x.InGroup()))
{
return IPrecompile.Failure;
}

bool scalarIsInfinity = !inputData[BlsConst.LenG2..].Span.ContainsAnyExcept((byte)0);
if (scalarIsInfinity || x.IsInf())
{
return (BlsConst.G2Inf, true);
}

Span<byte> scalar = stackalloc byte[32];
inputData.Span[BlsConst.LenG2..].CopyTo(scalar);
scalar.Reverse();

G2 res = x.Mult(scalar);
return (res.EncodeRaw(), true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ private MapFp2ToG2Precompile()
{
}

public static Address Address { get; } = Address.FromNumber(0x13);
public static Address Address { get; } = Address.FromNumber(0x11);

public long BaseGasCost(IReleaseSpec releaseSpec) => 23800L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ private MapFpToG1Precompile()
{
}

public static Address Address { get; } = Address.FromNumber(0x12);
public static Address Address { get; } = Address.FromNumber(0x10);

public long BaseGasCost(IReleaseSpec releaseSpec) => 5500L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class PairingCheckPrecompile : IPrecompile<PairingCheckPrecompile>

private PairingCheckPrecompile() { }

public static Address Address { get; } = Address.FromNumber(0x11);
public static Address Address { get; } = Address.FromNumber(0xf);

public long BaseGasCost(IReleaseSpec releaseSpec) => 37700L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class BlsG1MulBenchmark : PrecompileBenchmarkBase
{
protected override IEnumerable<IPrecompile> Precompiles => new[]
{
G1MulPrecompile.Instance
G1MSMPrecompile.Instance
};

protected override string InputsDirectory => "blsg1mul";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class BlsG2MulBenchmark : PrecompileBenchmarkBase
{
protected override IEnumerable<IPrecompile> Precompiles => new[]
{
G2MulPrecompile.Instance
G2MSMPrecompile.Instance
};

protected override string InputsDirectory => "blsg2mul";
Expand Down
Loading