diff --git a/src/Nethermind/Nethermind.Evm.Test/BlsMulG1PrecompileTests.cs b/src/Nethermind/Nethermind.Evm.Test/BlsMulG1PrecompileTests.cs index 26efd4d3724..c1089b16060 100644 --- a/src/Nethermind/Nethermind.Evm.Test/BlsMulG1PrecompileTests.cs +++ b/src/Nethermind/Nethermind.Evm.Test/BlsMulG1PrecompileTests.cs @@ -17,7 +17,7 @@ public class BlsG1MulPrecompileTests [Test] public void Test() { - IPrecompile precompile = G1MulPrecompile.Instance; + IPrecompile precompile = G1MSMPrecompile.Instance; foreach ((byte[] input, ReadOnlyMemory expectedResult) in Inputs) { diff --git a/src/Nethermind/Nethermind.Evm.Test/BlsMulG2PrecompileTests.cs b/src/Nethermind/Nethermind.Evm.Test/BlsMulG2PrecompileTests.cs index 625dd89e7df..3ab9a85a5d8 100644 --- a/src/Nethermind/Nethermind.Evm.Test/BlsMulG2PrecompileTests.cs +++ b/src/Nethermind/Nethermind.Evm.Test/BlsMulG2PrecompileTests.cs @@ -19,7 +19,7 @@ public void Test() { foreach ((byte[] input, ReadOnlyMemory expectedResult) in Inputs) { - IPrecompile precompile = G2MulPrecompile.Instance; + IPrecompile precompile = G2MSMPrecompile.Instance; (ReadOnlyMemory output, bool success) = precompile.Run(input, MuirGlacier.Instance); output.ToArray().Should().BeEquivalentTo(expectedResult.ToArray()); success.Should().BeTrue(); diff --git a/src/Nethermind/Nethermind.Evm/CodeInfoRepository.cs b/src/Nethermind/Nethermind.Evm/CodeInfoRepository.cs index 6103e2df810..499758f8c38 100644 --- a/src/Nethermind/Nethermind.Evm/CodeInfoRepository.cs +++ b/src/Nethermind/Nethermind.Evm/CodeInfoRepository.cs @@ -42,10 +42,8 @@ private static FrozenDictionary 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), diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MSMPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MSMPrecompile.cs index 4c6a12618c0..70f5c2d0d5c 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MSMPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MSMPrecompile.cs @@ -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; diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MulPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MulPrecompile.cs deleted file mode 100644 index 18eb5889913..00000000000 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MulPrecompile.cs +++ /dev/null @@ -1,59 +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 G1 = Nethermind.Crypto.Bls.P1; - -namespace Nethermind.Evm.Precompiles.Bls; - -/// -/// https://eips.ethereum.org/EIPS/eip-2537 -/// -public class G1MulPrecompile : IPrecompile -{ - public static readonly G1MulPrecompile Instance = new(); - - private G1MulPrecompile() - { - } - - public static Address Address { get; } = Address.FromNumber(0x0c); - - public long BaseGasCost(IReleaseSpec releaseSpec) => 12000L; - - public long DataGasCost(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) => 0L; - - [SkipLocalsInit] - public (ReadOnlyMemory, bool) Run(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) - { - Metrics.BlsG1MulPrecompile++; - - const int expectedInputLength = BlsConst.LenG1 + BlsConst.LenFr; - if (inputData.Length != expectedInputLength) - { - return IPrecompile.Failure; - } - - G1 x = new(stackalloc long[G1.Sz]); - if (!x.TryDecodeRaw(inputData[..BlsConst.LenG1].Span) || !(BlsConst.DisableSubgroupChecks || x.InGroup())) - { - return IPrecompile.Failure; - } - - bool scalarIsInfinity = !inputData.Span[BlsConst.LenG1..].ContainsAnyExcept((byte)0); - if (scalarIsInfinity || x.IsInf()) - { - return (BlsConst.G1Inf, true); - } - - Span scalar = stackalloc byte[32]; - inputData.Span[BlsConst.LenG1..].CopyTo(scalar); - scalar.Reverse(); - - G1 res = x.Mult(scalar); - return (res.EncodeRaw(), true); - } -} diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2AddPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2AddPrecompile.cs index 4cafcb61634..8d387733516 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2AddPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2AddPrecompile.cs @@ -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; diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MSMPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MSMPrecompile.cs index c8ea845b994..2208dbb6d7a 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MSMPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MSMPrecompile.cs @@ -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; diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MulPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MulPrecompile.cs index bf849287a5d..e69de29bb2d 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MulPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MulPrecompile.cs @@ -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; - -/// -/// https://eips.ethereum.org/EIPS/eip-2537 -/// -public class G2MulPrecompile : IPrecompile -{ - 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 inputData, IReleaseSpec releaseSpec) => 0L; - - [SkipLocalsInit] - public (ReadOnlyMemory, bool) Run(ReadOnlyMemory 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 scalar = stackalloc byte[32]; - inputData.Span[BlsConst.LenG2..].CopyTo(scalar); - scalar.Reverse(); - - G2 res = x.Mult(scalar); - return (res.EncodeRaw(), true); - } -} diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapFp2ToG2Precompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapFp2ToG2Precompile.cs index 04827c9e46d..0256db63c6f 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapFp2ToG2Precompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapFp2ToG2Precompile.cs @@ -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; diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapFpToG1Precompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapFpToG1Precompile.cs index eb1032ea1f5..f0bbd633509 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapFpToG1Precompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapFpToG1Precompile.cs @@ -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; diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/PairingCheckPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/PairingCheckPrecompile.cs index e398ba1c781..4b2572e248c 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/PairingCheckPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/PairingCheckPrecompile.cs @@ -23,7 +23,7 @@ public class PairingCheckPrecompile : IPrecompile private PairingCheckPrecompile() { } - public static Address Address { get; } = Address.FromNumber(0x11); + public static Address Address { get; } = Address.FromNumber(0xf); public long BaseGasCost(IReleaseSpec releaseSpec) => 37700L; diff --git a/src/Nethermind/Nethermind.Precompiles.Benchmark/BlsG1MulBenchmark.cs b/src/Nethermind/Nethermind.Precompiles.Benchmark/BlsG1MulBenchmark.cs index 7d1adc95338..b32430d5b9d 100644 --- a/src/Nethermind/Nethermind.Precompiles.Benchmark/BlsG1MulBenchmark.cs +++ b/src/Nethermind/Nethermind.Precompiles.Benchmark/BlsG1MulBenchmark.cs @@ -11,7 +11,7 @@ public class BlsG1MulBenchmark : PrecompileBenchmarkBase { protected override IEnumerable Precompiles => new[] { - G1MulPrecompile.Instance + G1MSMPrecompile.Instance }; protected override string InputsDirectory => "blsg1mul"; diff --git a/src/Nethermind/Nethermind.Precompiles.Benchmark/BlsG2MulBenchmark.cs b/src/Nethermind/Nethermind.Precompiles.Benchmark/BlsG2MulBenchmark.cs index 6df853a9778..6eb529ed24f 100644 --- a/src/Nethermind/Nethermind.Precompiles.Benchmark/BlsG2MulBenchmark.cs +++ b/src/Nethermind/Nethermind.Precompiles.Benchmark/BlsG2MulBenchmark.cs @@ -11,7 +11,7 @@ public class BlsG2MulBenchmark : PrecompileBenchmarkBase { protected override IEnumerable Precompiles => new[] { - G2MulPrecompile.Instance + G2MSMPrecompile.Instance }; protected override string InputsDirectory => "blsg2mul";