diff --git a/src/Nethermind/Nethermind.Blockchain/Find/ResourceNotFoundException.cs b/src/Nethermind/Nethermind.Blockchain/Find/ResourceNotFoundException.cs index 24c4c3f81a7..8334e06e52a 100644 --- a/src/Nethermind/Nethermind.Blockchain/Find/ResourceNotFoundException.cs +++ b/src/Nethermind/Nethermind.Blockchain/Find/ResourceNotFoundException.cs @@ -2,7 +2,6 @@ // SPDX-License-Identifier: LGPL-3.0-only using System; -using System.Transactions; namespace Nethermind.Blockchain.Find; diff --git a/src/Nethermind/Nethermind.Core.Test/AddressTests.cs b/src/Nethermind/Nethermind.Core.Test/AddressTests.cs index 1e8304289e3..4c61eee2ef4 100644 --- a/src/Nethermind/Nethermind.Core.Test/AddressTests.cs +++ b/src/Nethermind/Nethermind.Core.Test/AddressTests.cs @@ -179,7 +179,7 @@ public void Of_contract(long nonce, string expectedAddress) [TestCaseSource(nameof(PointEvaluationPrecompileTestCases))] public bool Is_PointEvaluationPrecompile_properly_activated(IReleaseSpec spec) => - Address.FromNumber(0x14).IsPrecompile(spec); + Address.FromNumber(0x0a).IsPrecompile(spec); public static IEnumerable PointEvaluationPrecompileTestCases { diff --git a/src/Nethermind/Nethermind.Core.Test/TransactionTests.cs b/src/Nethermind/Nethermind.Core.Test/TransactionTests.cs index 11edde35601..9d371f038cd 100644 --- a/src/Nethermind/Nethermind.Core.Test/TransactionTests.cs +++ b/src/Nethermind/Nethermind.Core.Test/TransactionTests.cs @@ -48,7 +48,7 @@ public static void EqualToTransaction(this Transaction subject, Transaction expe subject.Should().BeEquivalentTo( expectation, o => o - .ComparingByMembers() + .ComparingByMembers() .Using>(ctx => ctx.Subject.AsArray().Should().BeEquivalentTo(ctx.Expectation.AsArray())) .WhenTypeIs>() ); diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/AddressExtensions.cs b/src/Nethermind/Nethermind.Evm/Precompiles/AddressExtensions.cs index 2bb5272518b..560ef8ca8e7 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/AddressExtensions.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/AddressExtensions.cs @@ -2,47 +2,41 @@ // SPDX-License-Identifier: LGPL-3.0-only using System; +using System.Runtime.InteropServices; using Nethermind.Core; -using Nethermind.Core.Extensions; using Nethermind.Core.Specs; -namespace Nethermind.Evm.Precompiles +namespace Nethermind.Evm.Precompiles; + +public static class AddressExtensions { - public static class AddressExtensions + public static bool IsPrecompile(this Address address, IReleaseSpec releaseSpec) { - private static byte[] _nineteenZeros = new byte[19]; - - public static bool IsPrecompile(this Address address, IReleaseSpec releaseSpec) - { - if (!Bytes.AreEqual(address.Bytes.AsSpan(0, 19), _nineteenZeros)) - { - return false; - } - - int precompileCode = address[19]; - return precompileCode switch + Span data = MemoryMarshal.Cast(address.Bytes.AsSpan()); + return (data[4] & 0x00ffffff) == 0 + && data[3] == 0 && data[2] == 0 && data[1] == 0 && data[0] == 0 + && (data[4] >>> 24) switch { - 1 => true, - 2 => true, - 3 => true, - 4 => true, - 5 => releaseSpec.ModExpEnabled, - 6 => releaseSpec.Bn128Enabled, - 7 => releaseSpec.Bn128Enabled, - 8 => releaseSpec.Bn128Enabled, - 9 => releaseSpec.BlakeEnabled, - 10 => releaseSpec.Bls381Enabled, - 11 => releaseSpec.Bls381Enabled, - 12 => releaseSpec.Bls381Enabled, - 13 => releaseSpec.Bls381Enabled, - 14 => releaseSpec.Bls381Enabled, - 15 => releaseSpec.Bls381Enabled, - 16 => releaseSpec.Bls381Enabled, - 17 => releaseSpec.Bls381Enabled, - 18 => releaseSpec.Bls381Enabled, - 20 => releaseSpec.IsEip4844Enabled, + 0x01 => true, + 0x02 => true, + 0x03 => true, + 0x04 => true, + 0x05 => releaseSpec.ModExpEnabled, + 0x06 => releaseSpec.Bn128Enabled, + 0x07 => releaseSpec.Bn128Enabled, + 0x08 => releaseSpec.Bn128Enabled, + 0x09 => releaseSpec.BlakeEnabled, + 0x0a => releaseSpec.IsEip4844Enabled, + 0x0c => releaseSpec.Bls381Enabled, + 0x0d => releaseSpec.Bls381Enabled, + 0x0e => releaseSpec.Bls381Enabled, + 0x0f => releaseSpec.Bls381Enabled, + 0x10 => releaseSpec.Bls381Enabled, + 0x11 => releaseSpec.Bls381Enabled, + 0x12 => releaseSpec.Bls381Enabled, + 0x13 => releaseSpec.Bls381Enabled, + 0x14 => releaseSpec.Bls381Enabled, _ => false }; - } } } diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1AddPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1AddPrecompile.cs index 53f01b9d8d9..dfbc6a8ab6d 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1AddPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1AddPrecompile.cs @@ -19,7 +19,7 @@ private G1AddPrecompile() { } - public Address Address { get; } = Address.FromNumber(10); + public Address Address { get; } = Address.FromNumber(0x0c); public long BaseGasCost(IReleaseSpec releaseSpec) { diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MulPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MulPrecompile.cs index c01d96586dc..c0ca03db733 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MulPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MulPrecompile.cs @@ -19,7 +19,7 @@ private G1MulPrecompile() { } - public Address Address { get; } = Address.FromNumber(11); + public Address Address { get; } = Address.FromNumber(0x0d); public long BaseGasCost(IReleaseSpec releaseSpec) { diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MultiExpPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MultiExpPrecompile.cs index 6a6eadb0c28..ebfed64983d 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MultiExpPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MultiExpPrecompile.cs @@ -19,7 +19,7 @@ private G1MultiExpPrecompile() { } - public Address Address { get; } = Address.FromNumber(12); + public Address Address { get; } = Address.FromNumber(0x0e); public long BaseGasCost(IReleaseSpec releaseSpec) { diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2AddPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2AddPrecompile.cs index 6cff52b269d..4e12989fcf6 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2AddPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2AddPrecompile.cs @@ -19,7 +19,7 @@ private G2AddPrecompile() { } - public Address Address { get; } = Address.FromNumber(13); + public Address Address { get; } = Address.FromNumber(0x0f); public long BaseGasCost(IReleaseSpec releaseSpec) { diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MulPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MulPrecompile.cs index 1f5145ba4a0..9e8334659be 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MulPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MulPrecompile.cs @@ -19,7 +19,7 @@ private G2MulPrecompile() { } - public Address Address { get; } = Address.FromNumber(14); + public Address Address { get; } = Address.FromNumber(0x10); public long BaseGasCost(IReleaseSpec releaseSpec) { diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MultiExpPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MultiExpPrecompile.cs index b4118cd13f1..1fc34ff4b7a 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MultiExpPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MultiExpPrecompile.cs @@ -19,7 +19,7 @@ private G2MultiExpPrecompile() { } - public Address Address { get; } = Address.FromNumber(15); + public Address Address { get; } = Address.FromNumber(0x11); public long BaseGasCost(IReleaseSpec releaseSpec) { diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapToG1Precompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapToG1Precompile.cs index ca8ce9fd93e..ad3c05001e6 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapToG1Precompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapToG1Precompile.cs @@ -19,7 +19,7 @@ private MapToG1Precompile() { } - public Address Address { get; } = Address.FromNumber(17); + public Address Address { get; } = Address.FromNumber(0x13); public long BaseGasCost(IReleaseSpec releaseSpec) { diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapToG2Precompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapToG2Precompile.cs index e79aafeb536..790ce8bdc37 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapToG2Precompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapToG2Precompile.cs @@ -19,7 +19,7 @@ private MapToG2Precompile() { } - public Address Address { get; } = Address.FromNumber(18); + public Address Address { get; } = Address.FromNumber(0x14); public long BaseGasCost(IReleaseSpec releaseSpec) { diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/PairingPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/PairingPrecompile.cs index 660df65af64..ee3d83588a0 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/PairingPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/PairingPrecompile.cs @@ -17,7 +17,7 @@ public class PairingPrecompile : IPrecompile private PairingPrecompile() { } - public Address Address { get; } = Address.FromNumber(16); + public Address Address { get; } = Address.FromNumber(0x12); public static IPrecompile Instance = new PairingPrecompile(); diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/PointEvaluationPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/PointEvaluationPrecompile.cs index d46e4c69d4c..7a25a6c47cf 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/PointEvaluationPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/PointEvaluationPrecompile.cs @@ -20,7 +20,7 @@ public class PointEvaluationPrecompile : IPrecompile .Concat(KzgPolynomialCommitments.BlsModulus.ToBigEndian()) .ToArray(); - public Address Address { get; } = Address.FromNumber(0x14); + public Address Address { get; } = Address.FromNumber(0x0a); public long BaseGasCost(IReleaseSpec releaseSpec) => 50000L;