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

EIP-7251: Add EL triggered consolidations #7182

Merged
merged 50 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
ca2caa9
address lukasz comments
rjnrohit May 15, 2024
a752e0e
format files
rjnrohit May 15, 2024
c36640a
fix errors
rjnrohit May 15, 2024
2e74124
modify deposit processor tests
rjnrohit May 15, 2024
bd9e8cd
flag withdrawal request processor test
rjnrohit May 15, 2024
79788d2
add requests order test
rjnrohit May 17, 2024
88e54e6
modify withdrawalRequestProcessorTest
rjnrohit May 20, 2024
6e46f06
add withdrawal modal test case
rjnrohit May 21, 2024
f633374
add withdrawal request processor test
rjnrohit May 22, 2024
a0abbc0
add handlers and classes
rjnrohit May 31, 2024
00c1be2
add api capabilities
rjnrohit May 31, 2024
c628c1a
format files
rjnrohit May 31, 2024
7d25d34
add missing handlers: EngineModuleTests.V3
rjnrohit May 31, 2024
868238c
add some tests
Jun 4, 2024
45a19be
update tests
rjnrohit Jun 5, 2024
bc0c9ff
fix tests
rjnrohit Jun 11, 2024
c6cba04
add rest of the testcases
rjnrohit Jun 11, 2024
5156339
format files
rjnrohit Jun 11, 2024
54cd0ce
fix errors
rjnrohit Jun 12, 2024
7281a31
format files
rjnrohit Jun 12, 2024
33805b7
add consolidations
rjnrohit Jun 14, 2024
de8cb10
add consolidations requests decode tests
rjnrohit Jun 14, 2024
6862a3f
format files
rjnrohit Jun 14, 2024
26b471f
add consolidationRequestProcessor
rjnrohit Jun 15, 2024
e135bac
update size in ConsolidationRequestProcessor test
rjnrohit Jun 15, 2024
37ce573
fix consolidationRequestProcessor tests
rjnrohit Jun 15, 2024
27c9d0b
rename consolidationRequest fields
rjnrohit Jun 15, 2024
4ee78c1
Merge branch 'pectra' into prague/get_payload_bodies
rjnrohit Jun 16, 2024
5d12c8d
sync with pectra
rjnrohit Jun 16, 2024
d2e5d70
Merge branch 'prague/get_payload_bodies' into feature/consolidations
rjnrohit Jun 16, 2024
6d7d743
cosmetic
MarekM25 Jun 20, 2024
e894d2b
fix specProvider issues
MarekM25 Jun 23, 2024
4ace152
consolidations wasn't processed, fixed
MarekM25 Jun 23, 2024
8ef38be
cleanups
MarekM25 Jun 23, 2024
c5017d1
Merge branch 'prague/get_payload_bodies' into feature/consolidations
MarekM25 Jun 23, 2024
da30af9
reuse WithdrawalCredentialsField
rjnrohit Jun 24, 2024
a987ce7
address PR comments
rjnrohit Jun 24, 2024
f20bee0
format files
rjnrohit Jun 24, 2024
56ca5e7
IList -> IReadOnlyList
rjnrohit Jun 24, 2024
504daba
fix engineModule error
rjnrohit Jun 24, 2024
1bb8ba0
fix merge plugin issue
rjnrohit Jun 24, 2024
50a0b3c
don't initialize list
rjnrohit Jun 24, 2024
24342fc
add continue
rjnrohit Jun 24, 2024
ffbadbb
Merge branch 'prague/get_payload_bodies' into feature/consolidations
rjnrohit Jun 24, 2024
e0efd88
format files
rjnrohit Jun 24, 2024
ef744c1
refactor handles
rjnrohit Jun 25, 2024
395b94e
Merge branch 'prague/get_payload_bodies' into feature/consolidations
rjnrohit Jun 25, 2024
16b4477
format files
rjnrohit Jun 25, 2024
e1a47d8
Merge branch 'pectra' into feature/consolidations
rjnrohit Jun 26, 2024
2df29d8
address PR comments
rjnrohit Jun 26, 2024
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

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ ILogManager logManager
selectedTxs,
Array.Empty<BlockHeader>(),
spec.WithdrawalsEnabled ? Enumerable.Empty<Withdrawal>() : null,
spec.ConsensusRequestsEnabled ? Enumerable.Empty<ConsensusRequest>() : null
spec.RequestsEnabled ? Enumerable.Empty<ConsensusRequest>() : null
);
header.TxRoot = TxTrie.CalculateRoot(block.Transactions);
block.Header.Author = _sealer.Address;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,28 @@
using Nethermind.Core.Crypto;
using Nethermind.Core.Specs;
using Nethermind.Evm.TransactionProcessing;
using Nethermind.Serialization.Rlp;
using Nethermind.State;
using Nethermind.State.Proofs;

namespace Nethermind.Consensus.Requests;

public class ConsensusRequestsProcessor(ITransactionProcessor transactionProcessor) : IConsensusRequestsProcessor
{
private readonly ConsolidationRequestsProcessor _consolidationRequestsProcessor = new(transactionProcessor);
private readonly WithdrawalRequestsProcessor _withdrawalRequestsProcessor = new(transactionProcessor);
private readonly IDepositsProcessor _depositsProcessor = new DepositsProcessor();

public void ProcessRequests(IReleaseSpec spec, IWorldState state, Block block, TxReceipt[] receipts)
{
if (!spec.DepositsEnabled && !spec.WithdrawalRequestsEnabled)
if (!spec.RequestsEnabled)
return;

using ArrayPoolList<ConsensusRequest> requestsList = new(receipts.Length * 2);

// Process deposits
requestsList.AddRange(_depositsProcessor.ProcessDeposits(block, receipts, spec));
requestsList.AddRange(_withdrawalRequestsProcessor.ReadWithdrawalRequests(spec, state, block));
requestsList.AddRange(_consolidationRequestsProcessor.ReadConsolidationRequests(spec, state, block));

ConsensusRequest[] requests = requestsList.ToArray();
Hash256 root = new RequestsTrie(requests).RootHash;
Expand Down
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.Linq;
using Nethermind.Core;
using Nethermind.Core.ConsensusRequests;
using Nethermind.Core.Crypto;
using Nethermind.Core.Extensions;
using Nethermind.Core.Specs;
using Nethermind.Crypto;
using Nethermind.Evm;
using Nethermind.Evm.Tracing;
using Nethermind.Evm.TransactionProcessing;
using Nethermind.Int256;
using Nethermind.State;

namespace Nethermind.Consensus.Requests;

// https://eips.ethereum.org/EIPS/eip-7251#block-processing
public class ConsolidationRequestsProcessor(ITransactionProcessor transactionProcessor)
{
private const long GasLimit = 30_000_000L;

public IEnumerable<ConsolidationRequest> ReadConsolidationRequests(IReleaseSpec spec, IWorldState state, Block block)
{
if (!spec.ConsolidationRequestsEnabled)
yield break;

Address eip7251Account = spec.Eip7251ContractAddress;
if (!state.AccountExists(eip7251Account)) // not needed anymore?
yield break;

CallOutputTracer tracer = new();

Transaction? transaction = new()
{
Value = UInt256.Zero,
Data = Array.Empty<byte>(),
To = spec.Eip7251ContractAddress,
SenderAddress = Address.SystemUser,
GasLimit = GasLimit,
GasPrice = UInt256.Zero,
};
transaction.Hash = transaction.CalculateHash();

transactionProcessor.Execute(transaction, new BlockExecutionContext(block.Header), tracer);
var result = tracer.ReturnValue;
if (result == null || result.Length == 0)
yield break;

int sizeOfClass = 20 + 48 + 48;
int count = result.Length / sizeOfClass;
for (int i = 0; i < count; ++i)
{
ConsolidationRequest request = new();
Span<byte> span = new Span<byte>(result, i * sizeOfClass, sizeOfClass);
request.SourceAddress = new Address(span.Slice(0, 20).ToArray());
request.SourcePubkey = span.Slice(20, 48).ToArray();
request.TargetPubkey = span.Slice(68, 48).ToArray();

yield return request;
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
namespace Nethermind.Consensus.Requests;

// https://eips.ethereum.org/EIPS/eip-7002#block-processing
public class WithdrawalRequestsProcessor(ITransactionProcessor transactionProcessor) : IWithdrawalRequestsProcessor
public class WithdrawalRequestsProcessor(ITransactionProcessor transactionProcessor)
{
private const long GasLimit = 30_000_000L;

public IEnumerable<WithdrawalRequest> ReadWithdrawalRequests(IReleaseSpec spec, IWorldState state, Block block)
{
if (!spec.IsEip7002Enabled)
if (!spec.WithdrawalRequestsEnabled)
yield break;

Address eip7002Account = spec.Eip7002ContractAddress;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ public bool ValidateRequests(Block block, out string? error) =>

public bool ValidateRequests(Block block, IReleaseSpec spec, out string? error)
{
if (spec.ConsensusRequestsEnabled && block.Requests is null)
if (spec.RequestsEnabled && block.Requests is null)
{
error = BlockErrorMessages.MissingRequests;

Expand All @@ -304,7 +304,7 @@ public bool ValidateRequests(Block block, IReleaseSpec spec, out string? error)
return false;
}

if (!spec.ConsensusRequestsEnabled && block.Requests is not null)
if (!spec.RequestsEnabled && block.Requests is not null)
{
error = BlockErrorMessages.RequestsNotEnabled;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ protected virtual Block GetGenesisBlock()
genesisBlockBuilder.WithParentBeaconBlockRoot(Keccak.Zero);
}

if (SpecProvider.GenesisSpec.IsEip6110Enabled || SpecProvider.GenesisSpec.IsEip7002Enabled)
if (SpecProvider.GenesisSpec.RequestsEnabled)
{
genesisBlockBuilder.WithConsensusRequests(0);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

namespace Nethermind.Core.Test.Builders;
using Nethermind.Core.ConsensusRequests;

public class ConsolidationRequestBuilder : BuilderBase<ConsolidationRequest>
{
public ConsolidationRequestBuilder() => TestObject = new();

public ConsolidationRequestBuilder WithSourceAddress(Address sourceAddress)
{
TestObject.SourceAddress = sourceAddress;

return this;
}

public ConsolidationRequestBuilder WithSourcePubkey(byte[] SourcePubkey)
{
TestObject.SourcePubkey = SourcePubkey;

return this;
}

public ConsolidationRequestBuilder WithTargetPubkey(byte[] TargetPubkey)
{
TestObject.TargetPubkey = TargetPubkey;

return this;
}

}
7 changes: 7 additions & 0 deletions src/Nethermind/Nethermind.Core.Test/Builders/TestItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@ public static Hash256 KeccakFromNumber(int i)
public static WithdrawalRequest WithdrawalRequestE = new() { SourceAddress = AddressE, ValidatorPubkey = PublicKeyE.Bytes };
public static WithdrawalRequest WithdrawalRequestF = new() { SourceAddress = AddressF, ValidatorPubkey = PublicKeyF.Bytes };

public static ConsolidationRequest ConsolidationRequestA = new() { SourceAddress = AddressA, SourcePubkey = PublicKeyA.Bytes, TargetPubkey = PublicKeyB.Bytes };
public static ConsolidationRequest ConsolidationRequestB = new() { SourceAddress = AddressB, SourcePubkey = PublicKeyB.Bytes, TargetPubkey = PublicKeyC.Bytes };
public static ConsolidationRequest ConsolidationRequestC = new() { SourceAddress = AddressC, SourcePubkey = PublicKeyC.Bytes, TargetPubkey = PublicKeyD.Bytes };
public static ConsolidationRequest ConsolidationRequestD = new() { SourceAddress = AddressD, SourcePubkey = PublicKeyD.Bytes, TargetPubkey = PublicKeyE.Bytes };
public static ConsolidationRequest ConsolidationRequestE = new() { SourceAddress = AddressE, SourcePubkey = PublicKeyE.Bytes, TargetPubkey = PublicKeyF.Bytes };
public static ConsolidationRequest ConsolidationRequestF = new() { SourceAddress = AddressF, SourcePubkey = PublicKeyF.Bytes, TargetPubkey = PublicKeyA.Bytes };

public static IPEndPoint IPEndPointA = IPEndPoint.Parse("10.0.0.1");
public static IPEndPoint IPEndPointB = IPEndPoint.Parse("10.0.0.2");
public static IPEndPoint IPEndPointC = IPEndPoint.Parse("10.0.0.3");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,26 @@ public void Roundtrip_withdrawalRequest()
decoded.Should().BeEquivalentTo(withdrawalRequest);
}

[Test]
public void Roundtrip_consolidationRequest()
{
byte[] SourcePubkey = new byte[48];
SourcePubkey[11] = 11;
byte[] TargetPubkey = new byte[48];
TargetPubkey[22] = 22;
ConsensusRequest consolidationRequest = new ConsolidationRequest()
{
SourceAddress = TestItem.AddressA,
SourcePubkey = SourcePubkey,
TargetPubkey = TargetPubkey
};

byte[] rlp = Rlp.Encode(consolidationRequest).Bytes;
ConsensusRequest decoded = Rlp.Decode<ConsensusRequest>(rlp);

decoded.Should().BeEquivalentTo(consolidationRequest);
}

[Test]
public void Should_decode_deposit_with_ValueDecoderContext()
{
Expand Down Expand Up @@ -93,7 +113,27 @@ public void Should_decode_withdrawalRequest_with_ValueDecoderContext()
}

[Test]
public void Should_encode_deposit_same_for_Rlp_Encode_and_DepositDecoder_Encode()
public void Should_decode_consolidationRequest_with_ValueDecoderContext()
{
ConsensusRequest consolidationRequest = new ConsolidationRequest()
{
SourceAddress = TestItem.AddressA,
SourcePubkey = KeccakTests.KeccakOfAnEmptyString.ToBytes(),
TargetPubkey = KeccakTests.KeccakOfAnEmptyString.ToBytes()
};
RlpStream stream = new(1024);
ConsensusRequestDecoder codec = new();

codec.Encode(stream, consolidationRequest);

Rlp.ValueDecoderContext decoderContext = new(stream.Data.AsSpan());
ConsolidationRequest? decoded = (ConsolidationRequest?)codec.Decode(ref decoderContext);

decoded.Should().BeEquivalentTo(consolidationRequest);
}

[Test]
public void Should_encode_deposit_same_for_Rlp_Encode_and_ConsensusRequestDecoder_Encode()
{
ConsensusRequest deposit = new Deposit()
{
Expand All @@ -110,7 +150,7 @@ public void Should_encode_deposit_same_for_Rlp_Encode_and_DepositDecoder_Encode(
}

[Test]
public void Should_encode_withdrawalRequest_same_for_Rlp_Encode_and_DepositDecoder_Encode()
public void Should_encode_withdrawalRequest_same_for_Rlp_Encode_and_ConsensusRequestDecoder_Encode()
{
ConsensusRequest withdrawalRequest = new WithdrawalRequest()
{
Expand All @@ -124,6 +164,21 @@ public void Should_encode_withdrawalRequest_same_for_Rlp_Encode_and_DepositDecod
rlp1.Should().BeEquivalentTo(rlp2);
}

[Test]
public void Should_encode_consolidationRequest_same_for_Rlp_Encode_and_ConsensusRequestDecoder_Encode()
{
ConsensusRequest consolidationRequest = new ConsolidationRequest()
{
SourceAddress = TestItem.AddressA,
SourcePubkey = KeccakTests.KeccakOfAnEmptyString.ToBytes(),
TargetPubkey = KeccakTests.KeccakOfAnEmptyString.ToBytes()
};
byte[] rlp1 = new ConsensusRequestDecoder().Encode(consolidationRequest).Bytes;
byte[] rlp2 = Rlp.Encode(consolidationRequest).Bytes;

rlp1.Should().BeEquivalentTo(rlp2);
}

[Test]
public void Should_encode_ConsensusRequests_Array()
{
Expand All @@ -142,6 +197,12 @@ public void Should_encode_ConsensusRequests_Array()
SourceAddress = TestItem.AddressA,
ValidatorPubkey = KeccakTests.KeccakOfAnEmptyString.ToBytes(),
Amount = int.MaxValue
},
new ConsolidationRequest()
{
SourceAddress = TestItem.AddressA,
SourcePubkey = KeccakTests.KeccakOfAnEmptyString.ToBytes(),
TargetPubkey = KeccakTests.KeccakOfAnEmptyString.ToBytes()
}
};

Expand Down
Loading