Skip to content

Commit

Permalink
- made precompile address static (#5920)
Browse files Browse the repository at this point in the history
  • Loading branch information
Demuirgos authored Jul 11, 2023
1 parent 835863b commit 43660b6
Show file tree
Hide file tree
Showing 26 changed files with 58 additions and 58 deletions.
4 changes: 2 additions & 2 deletions src/Nethermind/Nethermind.Evm.Test/Eip1052Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void Non_existing_account_returns_0()
[Test]
public void Non_existing_precompile_returns_0()
{
Address precompileAddress = Sha256Precompile.Instance.Address;
Address precompileAddress = Sha256Precompile.Address;
Assert.True(precompileAddress.IsPrecompile(Spec));

byte[] code = Prepare.EvmCode
Expand All @@ -77,7 +77,7 @@ public void Non_existing_precompile_returns_0()
[Test]
public void Existing_precompile_returns_empty_data_hash()
{
Address precompileAddress = Sha256Precompile.Instance.Address;
Address precompileAddress = Sha256Precompile.Address;
Assert.True(precompileAddress.IsPrecompile(Spec));

TestState.CreateAccount(precompileAddress, 1.Wei());
Expand Down
12 changes: 6 additions & 6 deletions src/Nethermind/Nethermind.Evm.Test/Eip1108Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void Test_add_before_istanbul()
{
_blockNumberAdjustment = -1;
byte[] code = Prepare.EvmCode
.CallWithInput(Bn254AddPrecompile.Instance.Address, 1000L, new byte[128])
.CallWithInput(Bn254AddPrecompile.Address, 1000L, new byte[128])
.Done;
TestAllTracerWithOutput result = Execute(code);
Assert.That(result.StatusCode, Is.EqualTo(StatusCode.Success));
Expand All @@ -35,7 +35,7 @@ public void Test_add_before_istanbul()
public void Test_add_after_istanbul()
{
byte[] code = Prepare.EvmCode
.CallWithInput(Bn254AddPrecompile.Instance.Address, 1000L, new byte[128])
.CallWithInput(Bn254AddPrecompile.Address, 1000L, new byte[128])
.Done;
TestAllTracerWithOutput result = Execute(code);
Assert.That(result.StatusCode, Is.EqualTo(StatusCode.Success));
Expand All @@ -47,7 +47,7 @@ public void Test_mul_before_istanbul()
{
_blockNumberAdjustment = -1;
byte[] code = Prepare.EvmCode
.CallWithInput(Bn254MulPrecompile.Instance.Address, 50000L, new byte[128])
.CallWithInput(Bn254MulPrecompile.Address, 50000L, new byte[128])
.Done;
TestAllTracerWithOutput result = Execute(code);
Assert.That(result.StatusCode, Is.EqualTo(StatusCode.Success));
Expand All @@ -58,7 +58,7 @@ public void Test_mul_before_istanbul()
public void Test_mul_after_istanbul()
{
byte[] code = Prepare.EvmCode
.CallWithInput(Bn254MulPrecompile.Instance.Address, 10000L, new byte[128])
.CallWithInput(Bn254MulPrecompile.Address, 10000L, new byte[128])
.Done;
TestAllTracerWithOutput result = Execute(code);
Assert.That(result.StatusCode, Is.EqualTo(StatusCode.Success));
Expand All @@ -70,7 +70,7 @@ public void Test_pairing_before_istanbul()
{
_blockNumberAdjustment = -1;
byte[] code = Prepare.EvmCode
.CallWithInput(Bn254PairingPrecompile.Instance.Address, 200000L, new byte[192])
.CallWithInput(Bn254PairingPrecompile.Address, 200000L, new byte[192])
.Done;
TestAllTracerWithOutput result = Execute(BlockNumber, 1000000L, code);
Assert.That(result.StatusCode, Is.EqualTo(StatusCode.Success));
Expand All @@ -81,7 +81,7 @@ public void Test_pairing_before_istanbul()
public void Test_pairing_after_istanbul()
{
byte[] code = Prepare.EvmCode
.CallWithInput(Bn254PairingPrecompile.Instance.Address, 200000L, new byte[192])
.CallWithInput(Bn254PairingPrecompile.Address, 200000L, new byte[192])
.Done;
TestAllTracerWithOutput result = Execute(BlockNumber, 1000000L, code);
Assert.That(result.StatusCode, Is.EqualTo(StatusCode.Success));
Expand Down
4 changes: 2 additions & 2 deletions src/Nethermind/Nethermind.Evm.Test/Eip152Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ public void TearDown()
public void before_istanbul()
{
_blockNumberAdjustment = -1;
Address precompileAddress = Blake2FPrecompile.Instance.Address;
Address precompileAddress = Blake2FPrecompile.Address;
Assert.False(precompileAddress.IsPrecompile(Spec));
}

[Test]
public void after_istanbul()
{
byte[] code = Prepare.EvmCode
.CallWithInput(Blake2FPrecompile.Instance.Address, 1000L, new byte[InputLength])
.CallWithInput(Blake2FPrecompile.Address, 1000L, new byte[InputLength])
.Done;
TestAllTracerWithOutput result = Execute(code);
Assert.That(result.StatusCode, Is.EqualTo(StatusCode.Success));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ public void Can_trace_static_calls()
public void Can_trace_precompile_calls()
{
byte[] code = Prepare.EvmCode
.Call(IdentityPrecompile.Instance.Address, 50000)
.Call(IdentityPrecompile.Address, 50000)
.Op(Instruction.STOP)
.Done;

Expand All @@ -590,16 +590,16 @@ public void Can_trace_precompile_calls()
public void Can_ignore_precompile_calls_in_contract()
{
byte[] deployedCode = Prepare.EvmCode
.Call(IdentityPrecompile.Instance.Address, 50000)
.CallWithValue(IdentityPrecompile.Instance.Address, 50000, 1.Ether())
.Call(IdentityPrecompile.Address, 50000)
.CallWithValue(IdentityPrecompile.Address, 50000, 1.Ether())
.Op(Instruction.STOP)
.Done;

TestState.CreateAccount(TestItem.AddressC, 1.Ether());
TestState.InsertCode(TestItem.AddressC, deployedCode, Spec);

byte[] code = Prepare.EvmCode
.Call(IdentityPrecompile.Instance.Address, 50000)
.Call(IdentityPrecompile.Address, 50000)
.Call(TestItem.AddressC, 40000)
.Op(Instruction.STOP)
.Done;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class Blake2FPrecompile : IPrecompile

public static readonly IPrecompile Instance = new Blake2FPrecompile();

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

public long BaseGasCost(IReleaseSpec releaseSpec) => 0;

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

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

public long BaseGasCost(IReleaseSpec releaseSpec)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ private G1MulPrecompile()
{
}

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

public long BaseGasCost(IReleaseSpec releaseSpec)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ private G1MultiExpPrecompile()
{
}

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

public long BaseGasCost(IReleaseSpec releaseSpec)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ private G2AddPrecompile()
{
}

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

public long BaseGasCost(IReleaseSpec releaseSpec)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ private G2MulPrecompile()
{
}

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

public long BaseGasCost(IReleaseSpec releaseSpec)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ private G2MultiExpPrecompile()
{
}

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

public long BaseGasCost(IReleaseSpec releaseSpec)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ private MapToG1Precompile()
{
}

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

public long BaseGasCost(IReleaseSpec releaseSpec)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ private MapToG2Precompile()
{
}

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

public long BaseGasCost(IReleaseSpec releaseSpec)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class PairingPrecompile : IPrecompile

private PairingPrecompile() { }

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

public static IPrecompile Instance = new PairingPrecompile();

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

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

public long DataGasCost(in ReadOnlyMemory<byte> inputData, IReleaseSpec releaseSpec)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Nethermind/Nethermind.Evm/Precompiles/IPrecompile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Nethermind.Evm.Precompiles
{
public interface IPrecompile
{
Address Address { get; }
static Address Address { get; }

long BaseGasCost(IReleaseSpec releaseSpec);

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

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

public long BaseGasCost(IReleaseSpec releaseSpec)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ private ModExpPrecompile()
{
}

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

public long BaseGasCost(IReleaseSpec releaseSpec)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ private ModExpPrecompilePreEip2565()
{
}

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

public long BaseGasCost(IReleaseSpec releaseSpec)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class PointEvaluationPrecompile : IPrecompile
.Concat(KzgPolynomialCommitments.BlsModulus.ToBigEndian())
.ToArray();

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ private Ripemd160Precompile()
// _ripemd.Initialize();
}

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

public long BaseGasCost(IReleaseSpec releaseSpec)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ private static void InitIfNeeded()
}
}

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

public long BaseGasCost(IReleaseSpec releaseSpec)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class Bn254AddPrecompile : IPrecompile
{
public static IPrecompile Instance = new Bn254AddPrecompile();

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

public long BaseGasCost(IReleaseSpec releaseSpec)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class Bn254MulPrecompile : IPrecompile
{
public static IPrecompile Instance = new Bn254MulPrecompile();

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

public long BaseGasCost(IReleaseSpec releaseSpec)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class Bn254PairingPrecompile : IPrecompile

public static IPrecompile Instance = new Bn254PairingPrecompile();

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

public long BaseGasCost(IReleaseSpec releaseSpec)
{
Expand Down
46 changes: 23 additions & 23 deletions src/Nethermind/Nethermind.Evm/VirtualMachine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -519,29 +519,29 @@ private void InitializePrecompiledContracts()
{
_precompiles = new Dictionary<Address, CodeInfo>
{
[EcRecoverPrecompile.Instance.Address] = new(EcRecoverPrecompile.Instance),
[Sha256Precompile.Instance.Address] = new(Sha256Precompile.Instance),
[Ripemd160Precompile.Instance.Address] = new(Ripemd160Precompile.Instance),
[IdentityPrecompile.Instance.Address] = new(IdentityPrecompile.Instance),

[Bn254AddPrecompile.Instance.Address] = new(Bn254AddPrecompile.Instance),
[Bn254MulPrecompile.Instance.Address] = new(Bn254MulPrecompile.Instance),
[Bn254PairingPrecompile.Instance.Address] = new(Bn254PairingPrecompile.Instance),
[ModExpPrecompile.Instance.Address] = new(ModExpPrecompile.Instance),

[Blake2FPrecompile.Instance.Address] = new(Blake2FPrecompile.Instance),

[G1AddPrecompile.Instance.Address] = new(G1AddPrecompile.Instance),
[G1MulPrecompile.Instance.Address] = new(G1MulPrecompile.Instance),
[G1MultiExpPrecompile.Instance.Address] = new(G1MultiExpPrecompile.Instance),
[G2AddPrecompile.Instance.Address] = new(G2AddPrecompile.Instance),
[G2MulPrecompile.Instance.Address] = new(G2MulPrecompile.Instance),
[G2MultiExpPrecompile.Instance.Address] = new(G2MultiExpPrecompile.Instance),
[PairingPrecompile.Instance.Address] = new(PairingPrecompile.Instance),
[MapToG1Precompile.Instance.Address] = new(MapToG1Precompile.Instance),
[MapToG2Precompile.Instance.Address] = new(MapToG2Precompile.Instance),

[PointEvaluationPrecompile.Instance.Address] = new(PointEvaluationPrecompile.Instance),
[EcRecoverPrecompile.Address] = new(EcRecoverPrecompile.Instance),
[Sha256Precompile.Address] = new(Sha256Precompile.Instance),
[Ripemd160Precompile.Address] = new(Ripemd160Precompile.Instance),
[IdentityPrecompile.Address] = new(IdentityPrecompile.Instance),

[Bn254AddPrecompile.Address] = new(Bn254AddPrecompile.Instance),
[Bn254MulPrecompile.Address] = new(Bn254MulPrecompile.Instance),
[Bn254PairingPrecompile.Address] = new(Bn254PairingPrecompile.Instance),
[ModExpPrecompile.Address] = new(ModExpPrecompile.Instance),

[Blake2FPrecompile.Address] = new(Blake2FPrecompile.Instance),

[G1AddPrecompile.Address] = new(G1AddPrecompile.Instance),
[G1MulPrecompile.Address] = new(G1MulPrecompile.Instance),
[G1MultiExpPrecompile.Address] = new(G1MultiExpPrecompile.Instance),
[G2AddPrecompile.Address] = new(G2AddPrecompile.Instance),
[G2MulPrecompile.Address] = new(G2MulPrecompile.Instance),
[G2MultiExpPrecompile.Address] = new(G2MultiExpPrecompile.Instance),
[PairingPrecompile.Address] = new(PairingPrecompile.Instance),
[MapToG1Precompile.Address] = new(MapToG1Precompile.Instance),
[MapToG2Precompile.Address] = new(MapToG2Precompile.Instance),

[PointEvaluationPrecompile.Address] = new(PointEvaluationPrecompile.Instance),
};
}

Expand Down

0 comments on commit 43660b6

Please sign in to comment.