Skip to content

Commit

Permalink
(Over)optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
flcl42 committed Jun 23, 2023
1 parent 39c8868 commit cb47b98
Showing 1 changed file with 28 additions and 36 deletions.
64 changes: 28 additions & 36 deletions src/Nethermind/Nethermind.Evm/Precompiles/AddressExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,39 @@
// 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)
Span<int> data = MemoryMarshal.Cast<byte, int>(address.Bytes.AsSpan());
return data[0] == 0 && data[1] == 0 && data[2] == 0 && data[3] == 0 && data[4] switch
{
if (!Bytes.AreEqual(address.Bytes.AsSpan(0, 19), _nineteenZeros))
{
return false;
}

int precompileCode = address[19];
return precompileCode switch
{
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
};
}
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
};
}
}

0 comments on commit cb47b98

Please sign in to comment.