Skip to content

Commit

Permalink
Merge branch 'master' into fix/mechanism-for-eip-dependent-params
Browse files Browse the repository at this point in the history
  • Loading branch information
LukaszRozmej authored Feb 25, 2025
2 parents c9e207a + a152d24 commit 523247b
Show file tree
Hide file tree
Showing 24 changed files with 5,744 additions and 269 deletions.
1 change: 1 addition & 0 deletions src/Nethermind/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
<PackageVersion Include="Nethermind.Crypto.Bls" Version="1.0.4" />
<PackageVersion Include="Nethermind.Crypto.Pairings" Version="1.1.1" />
<PackageVersion Include="Nethermind.Crypto.SecP256k1" Version="1.4.0" />
<PackageVersion Include="Nethermind.Crypto.SecP256r1" Version="1.0.0-preview.1" />
<PackageVersion Include="Nethermind.DotNetty.Buffers" Version="1.0.1" />
<PackageVersion Include="Nethermind.DotNetty.Handlers" Version="1.0.1" />
<PackageVersion Include="Nethermind.DotNetty.Transport" Version="1.0.1" />
Expand Down
4 changes: 1 addition & 3 deletions src/Nethermind/Nethermind.Api/Extensions/IConsensusPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@

namespace Nethermind.Api.Extensions
{
public interface IConsensusPlugin : INethermindPlugin, IBlockProducerFactory
public interface IConsensusPlugin : INethermindPlugin, IBlockProducerFactory, IBlockProducerRunnerFactory
{
string SealEngineType { get; }

INethermindApi CreateApi(IConfigProvider configProvider, IJsonSerializer jsonSerializer,
ILogManager logManager, ChainSpec chainSpec) => new NethermindApi(configProvider, jsonSerializer, logManager, chainSpec);

IBlockProducerRunner CreateBlockProducerRunner();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@ public interface IConsensusWrapperPlugin : INethermindPlugin
{
IBlockProducer InitBlockProducer(IBlockProducerFactory baseBlockProducerFactory, ITxSource? txSource);

IBlockProducerRunner InitBlockProducerRunner(IBlockProducerRunner baseRunner) => baseRunner;
/// <summary>
/// Initializes the <see cref="IBlockProducerRunner"/>.
/// </summary>
/// <remarks>
/// BE CAREFUL IF MORE THAN ONE <see cref="IConsensusWrapperPlugin"/> OVERRIDES THIS METHOD AT A TIME.
/// SEE <see cref="InitBlockProducer"/> FOR MORE DETAILS ON THE INITIALIZATION PROCESS.
/// </remarks>
IBlockProducerRunner InitBlockProducerRunner(IBlockProducerRunnerFactory baseRunnerFactory,
IBlockProducer blockProducer) => baseRunnerFactory.InitBlockProducerRunner(blockProducer);

/// <summary>
/// Priorities for ordering multiple plugin. Only used to determine the wrapping order of block production.
Expand Down
4 changes: 2 additions & 2 deletions src/Nethermind/Nethermind.Consensus.AuRa/AuRaPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ public IBlockProducer InitBlockProducer(ITxSource? additionalTxSource = null)
return null;
}

public IBlockProducerRunner CreateBlockProducerRunner()
public IBlockProducerRunner InitBlockProducerRunner(IBlockProducer blockProducer)
{
return new StandardBlockProducerRunner(
_blockProducerStarter.CreateTrigger(),
_nethermindApi.BlockTree,
_nethermindApi.BlockProducer!);
blockProducer);
}

public INethermindApi CreateApi(IConfigProvider configProvider, IJsonSerializer jsonSerializer,
Expand Down
4 changes: 2 additions & 2 deletions src/Nethermind/Nethermind.Consensus.Clique/CliquePlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,14 @@ public IBlockProducer InitBlockProducer(ITxSource? additionalTxSource = null)
return blockProducer;
}

public IBlockProducerRunner CreateBlockProducerRunner()
public IBlockProducerRunner InitBlockProducerRunner(IBlockProducer blockProducer)
{
_blockProducerRunner = new CliqueBlockProducerRunner(
_nethermindApi.BlockTree,
_nethermindApi.Timestamper,
_nethermindApi.CryptoRandom,
_snapshotManager,
(CliqueBlockProducer)_nethermindApi.BlockProducer!,
(CliqueBlockProducer)blockProducer,
_cliqueConfig,
_nethermindApi.LogManager);
_nethermindApi.DisposeStack.Push(_blockProducerRunner);
Expand Down
4 changes: 2 additions & 2 deletions src/Nethermind/Nethermind.Consensus.Ethash/EthashPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ public IBlockProducer InitBlockProducer(ITxSource? additionalTxSource = null)

public string SealEngineType => Core.SealEngineType.Ethash;

public IBlockProducerRunner CreateBlockProducerRunner()
public IBlockProducerRunner InitBlockProducerRunner(IBlockProducer blockProducer)
{
return new StandardBlockProducerRunner(
_nethermindApi.ManualBlockProductionTrigger,
_nethermindApi.BlockTree,
_nethermindApi.BlockProducer!);
blockProducer);
}
}
}
4 changes: 2 additions & 2 deletions src/Nethermind/Nethermind.Consensus.Ethash/NethDevPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,15 @@ public IBlockProducer InitBlockProducer(ITxSource? additionalTxSource = null)

public string SealEngineType => NethDev;

public IBlockProducerRunner CreateBlockProducerRunner()
public IBlockProducerRunner InitBlockProducerRunner(IBlockProducer blockProducer)
{
IBlockProductionTrigger trigger = new BuildBlocksRegularly(TimeSpan.FromMilliseconds(200))
.IfPoolIsNotEmpty(_nethermindApi.TxPool)
.Or(_nethermindApi.ManualBlockProductionTrigger);
return new StandardBlockProducerRunner(
trigger,
_nethermindApi.BlockTree,
_nethermindApi.BlockProducer!);
blockProducer);
}
}
}
15 changes: 15 additions & 0 deletions src/Nethermind/Nethermind.Consensus/IBlockProducerRunnerFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-FileCopyrightText: 2025 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

namespace Nethermind.Consensus;

public interface IBlockProducerRunnerFactory
{
/// <summary>
/// Creates a <see cref="IBlockProducerRunner"/> to run the given <see cref="IBlockProducer"/>.
/// </summary>
/// <param name="blockProducer">
/// The instance of <see cref="IBlockProducer"/> that should be started by the runner.
/// </param>
IBlockProducerRunner InitBlockProducerRunner(IBlockProducer blockProducer);
}
6 changes: 6 additions & 0 deletions src/Nethermind/Nethermind.Evm.Test/Nethermind.Evm.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,10 @@
<ProjectReference Include="..\Nethermind.JsonRpc\Nethermind.JsonRpc.csproj" />
<ProjectReference Include="..\Nethermind.Synchronization\Nethermind.Synchronization.csproj" />
</ItemGroup>
<ItemGroup>
<Content Include="TestFiles\p256Verify.json">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>

This file was deleted.

66 changes: 66 additions & 0 deletions src/Nethermind/Nethermind.Evm.Test/Secp256r1PrecompileTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using System;
using System.Collections.Generic;
using System.IO;
using System.Text.Json;
using Nethermind.Core.Extensions;
using Nethermind.Evm.Precompiles;
using Nethermind.Specs.Forks;
using NUnit.Framework;

namespace Nethermind.Evm.Test
{
[TestFixture]
public class Secp256r1PrecompileTests : VirtualMachineTestsBase
{
// ReSharper disable once ClassNeverInstantiated.Local
public record TestCase(string Input, string Expected, string Name);

private static IEnumerable<TestCase> TestSource()
{
// /~https://github.com/ethereum-optimism/op-geth/blob/7017b54770d480b5c8be63dc40eac9da166150f5/core/vm/testdata/precompiles/p256Verify.json
var data = File.ReadAllText("TestFiles/p256Verify.json");
return JsonSerializer.Deserialize<TestCase[]>(data);
}

[TestCaseSource(nameof(TestSource))]
public void Produces_Correct_Outputs(TestCase testCase)
{
var input = Bytes.FromHexString(testCase.Input);
var expected = Bytes.FromHexString(testCase.Expected);

(ReadOnlyMemory<byte> output, bool success) = Secp256r1Precompile.Instance.Run(input, Prague.Instance);

using (Assert.EnterMultipleScope())
{
Assert.That(success, Is.True);
Assert.That(output.ToArray(), Is.EquivalentTo(expected));
}
}

[Test]
[TestCase(
""
)]
[TestCase(
"4cee90eb86eaa050036147a12d49004b6a"
)]
[TestCase(
"4cee90eb86eaa050036147a12d49004b6a958b991cfd78f16537fe6d1f4afd10273384db08bdfc843562a22b0626766686f6aec8247599f40bfe01bec0e0ecf17b4319559022d4d9bf007fe929943004eb4866760dedf319"
)]
public void Produces_Empty_Output_On_Invalid_Input(string input)
{
var bytes = Bytes.FromHexString(input);

(ReadOnlyMemory<byte> output, bool success) = Secp256r1Precompile.Instance.Run(bytes, Prague.Instance);

using (Assert.EnterMultipleScope())
{
Assert.That(success, Is.True);
Assert.That(output.ToArray(), Is.EquivalentTo(Array.Empty<byte>()));
}
}
}
}
Loading

0 comments on commit 523247b

Please sign in to comment.