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

Made precompile address property static #5920

Merged
merged 2 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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 @@ -584,23 +584,23 @@ public void Can_trace_precompile_calls()
};

Assert.That(trace.Action.Subtraces[0].CallType, Is.EqualTo("call"), "[0] type");
Assert.That(trace.Action.Subtraces[0].To, Is.EqualTo(IdentityPrecompile.Instance.Address), "[0] to");
Assert.That(trace.Action.Subtraces[0].To, Is.EqualTo(IdentityPrecompile.Address), "[0] to");
}

[Test]
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 All @@ -614,7 +614,7 @@ public void Can_ignore_precompile_calls_in_contract()
// Precompile call
Assert.That(trace.Action.Subtraces[0].Subtraces.Count, Is.EqualTo(0), "[0] subtraces");
Assert.That(trace.Action.Subtraces[0].CallType, Is.EqualTo("call"), "[0] type");
Assert.That(trace.Action.Subtraces[0].To, Is.EqualTo(IdentityPrecompile.Instance.Address), "[0] to");
Assert.That(trace.Action.Subtraces[0].To, Is.EqualTo(IdentityPrecompile.Address), "[0] to");

// AddressC call - only one call
Assert.That(trace.Action.Subtraces[1].Subtraces.Count, Is.EqualTo(2), "[1] subtraces");
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; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love that you can have statics in interfaces now


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