From f36d13ed121e982161d706a47e411d7bc4696aeb Mon Sep 17 00:00:00 2001 From: Rohit Ranjan Date: Tue, 4 Feb 2025 14:35:50 +0530 Subject: [PATCH 1/4] add endpoint to support rBuilder payload --- .../Nethermind.Flashbots/Data/BidTrace.cs | 63 +++++++++---- .../Data/BuilderBlockValidationRequest.cs | 11 ++- .../Nethermind.Flashbots/Data/Message.cs | 46 ++++++++++ .../Data/RBuilderBlockValidationRequest.cs | 45 +++++++++ .../Data/RExecutionPayloadV3.cs | 91 +++++++++++++++++++ .../Modules/Flashbots/FlashbotsRpcModule.cs | 16 +++- .../Modules/Flashbots/IFlashbotsRpcModule.cs | 6 ++ .../Nethermind.Runner/configs/holesky.json | 5 +- 8 files changed, 261 insertions(+), 22 deletions(-) create mode 100644 src/Nethermind/Nethermind.Flashbots/Data/Message.cs create mode 100644 src/Nethermind/Nethermind.Flashbots/Data/RBuilderBlockValidationRequest.cs create mode 100644 src/Nethermind/Nethermind.Flashbots/Data/RExecutionPayloadV3.cs diff --git a/src/Nethermind/Nethermind.Flashbots/Data/BidTrace.cs b/src/Nethermind/Nethermind.Flashbots/Data/BidTrace.cs index 8fddcb0d205..2ff3054297b 100644 --- a/src/Nethermind/Nethermind.Flashbots/Data/BidTrace.cs +++ b/src/Nethermind/Nethermind.Flashbots/Data/BidTrace.cs @@ -7,23 +7,50 @@ namespace Nethermind.Flashbots.Data; -public class BidTrace( - ulong slot, - Hash256 blockHash, - PublicKey builderPublicKey, - PublicKey proposerPublicKey, - Address proposerFeeRecipient, - long gasLimit, - long gasUsed, - UInt256 value) +public class BidTrace { - public ulong Slot { get; } = slot; - public required Hash256 ParentHash { get; set; } - public Hash256 BlockHash { get; } = blockHash; - public PublicKey BuilderPublicKey { get; } = builderPublicKey; - public PublicKey ProposerPublicKey { get; } = proposerPublicKey; - public Address ProposerFeeRecipient { get; } = proposerFeeRecipient; - public long GasLimit { get; } = gasLimit; - public long GasUsed { get; } = gasUsed; - public UInt256 Value { get; } = value; + public ulong Slot { get; } + public Hash256 ParentHash { get; } + public Hash256 BlockHash { get; } + public PublicKey BuilderPublicKey { get; } + public PublicKey ProposerPublicKey { get; } + public Address ProposerFeeRecipient { get; } + public long GasLimit { get; } + public long GasUsed { get; } + public UInt256 Value { get; } + + public BidTrace( + ulong slot, + Hash256 parentHash, + Hash256 blockHash, + PublicKey builderPublicKey, + PublicKey proposerPublicKey, + Address proposerFeeRecipient, + long gasLimit, + long gasUsed, + UInt256 value) + { + Slot = slot; + ParentHash = parentHash; + BlockHash = blockHash; + BuilderPublicKey = builderPublicKey; + ProposerPublicKey = proposerPublicKey; + ProposerFeeRecipient = proposerFeeRecipient; + GasLimit = gasLimit; + GasUsed = gasUsed; + Value = value; + } + + // public BidTrace(Message message) : this( + // message.Slot, + // message.ParentHash, + // message.BlockHash, + // message.BuilderPublicKey, + // message.ProposerPublicKey, + // message.ProposerFeeRecipient, + // message.GasLimit, + // message.GasUsed, + // message.Value) + // { + // } } diff --git a/src/Nethermind/Nethermind.Flashbots/Data/BuilderBlockValidationRequest.cs b/src/Nethermind/Nethermind.Flashbots/Data/BuilderBlockValidationRequest.cs index 66463d74ffc..3285afc563b 100644 --- a/src/Nethermind/Nethermind.Flashbots/Data/BuilderBlockValidationRequest.cs +++ b/src/Nethermind/Nethermind.Flashbots/Data/BuilderBlockValidationRequest.cs @@ -8,16 +8,23 @@ namespace Nethermind.Flashbots.Data; public class BuilderBlockValidationRequest { + public BuilderBlockValidationRequest(Hash256 parentBeaconBlockRoot, long registerGasLimit, SubmitBlockRequest blockRequest) + { + ParentBeaconBlockRoot = parentBeaconBlockRoot; + RegisterGasLimit = registerGasLimit; + BlockRequest = blockRequest; + } + /// /// The block hash of the parent beacon block. /// /// [JsonRequired] - public required Hash256 ParentBeaconBlockRoot { get; set; } + public Hash256 ParentBeaconBlockRoot { get; set; } [JsonRequired] public long RegisterGasLimit { get; set; } [JsonRequired] - public required SubmitBlockRequest BlockRequest { get; set; } + public SubmitBlockRequest BlockRequest { get; set; } } diff --git a/src/Nethermind/Nethermind.Flashbots/Data/Message.cs b/src/Nethermind/Nethermind.Flashbots/Data/Message.cs new file mode 100644 index 00000000000..9246b5319b4 --- /dev/null +++ b/src/Nethermind/Nethermind.Flashbots/Data/Message.cs @@ -0,0 +1,46 @@ +// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited +// SPDX-License-Identifier: LGPL-3.0-only + +using Nethermind.Core; +using Nethermind.Core.Crypto; +using Nethermind.Int256; + +namespace Nethermind.Flashbots.Data; + +public class Message( + ulong slot, + Hash256 parent_hash, + Hash256 block_hash, + PublicKey builder_pubkey, + PublicKey proposer_pubkey, + Address proposer_fee_recipient, + long gas_limit, + long gas_used, + UInt256 value) +{ + public ulong slot { get; } = slot; + public required Hash256 parent_hash { get; set; } = parent_hash; + public Hash256 block_hash { get; } = block_hash; + public PublicKey builder_pubkey { get; } = builder_pubkey; + public PublicKey proposer_pubkey { get; } = proposer_pubkey; + public Address proposer_fee_recipient { get; } = proposer_fee_recipient; + public long gas_limit { get; } = gas_limit; + public long gas_used { get; } = gas_used; + public UInt256 value { get; } = value; + + public BidTrace ToBidTrace() + { + return new BidTrace( + slot, + parent_hash, + block_hash, + builder_pubkey, + proposer_pubkey, + proposer_fee_recipient, + gas_limit, + gas_used, + value + ); + } +} + diff --git a/src/Nethermind/Nethermind.Flashbots/Data/RBuilderBlockValidationRequest.cs b/src/Nethermind/Nethermind.Flashbots/Data/RBuilderBlockValidationRequest.cs new file mode 100644 index 00000000000..a2f2dc945e1 --- /dev/null +++ b/src/Nethermind/Nethermind.Flashbots/Data/RBuilderBlockValidationRequest.cs @@ -0,0 +1,45 @@ +// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited +// SPDX-License-Identifier: LGPL-3.0-only + +using System.Text.Json.Serialization; +using Nethermind.Core.Crypto; +using Nethermind.Merge.Plugin.Data; + +namespace Nethermind.Flashbots.Data; + +public class RBuilderBlockValidationRequest +{ + public RBuilderBlockValidationRequest( + Message message, + RExecutionPayloadV3 execution_payload, + BlobsBundleV1 blobs_bundle, + long registered_gas_limit, + Hash256 withdrawals_root, + Hash256 parent_beacon_block_root) + { + this.message = message; + this.execution_payload = execution_payload; + this.blobs_bundle = blobs_bundle; + this.registered_gas_limit = registered_gas_limit; + this.withdrawals_root = withdrawals_root; + this.parent_beacon_block_root = parent_beacon_block_root; + } + + [JsonRequired] + public Message message { get; set; } + + [JsonRequired] + public RExecutionPayloadV3 execution_payload { get; set; } + + [JsonRequired] + public BlobsBundleV1 blobs_bundle { get; set; } + + [JsonRequired] + public long registered_gas_limit { get; set; } + + [JsonRequired] + public Hash256 withdrawals_root { get; set; } + + [JsonRequired] + public Hash256 parent_beacon_block_root { get; set; } +} diff --git a/src/Nethermind/Nethermind.Flashbots/Data/RExecutionPayloadV3.cs b/src/Nethermind/Nethermind.Flashbots/Data/RExecutionPayloadV3.cs new file mode 100644 index 00000000000..239e05705d7 --- /dev/null +++ b/src/Nethermind/Nethermind.Flashbots/Data/RExecutionPayloadV3.cs @@ -0,0 +1,91 @@ +// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited +// SPDX-License-Identifier: LGPL-3.0-only + +using Nethermind.Core; +using Nethermind.Core.Crypto; +using Nethermind.Int256; +using Nethermind.Merge.Plugin.Data; + +public class RExecutionPayloadV3 +{ + public Hash256 parent_hash { get; set; } + public Address fee_recipient { get; set; } + public Hash256 state_root { get; set; } + public Hash256 receipts_root { get; set; } + public Bloom logs_bloom { get; set; } + public Hash256 prev_randao { get; set; } + public long block_number { get; set; } + public long gas_limit { get; set; } + public long gas_used { get; set; } + public ulong timestamp { get; set; } + public byte[] extra_data { get; set; } + public UInt256 base_fee_per_gas { get; set; } + public Hash256 block_hash { get; set; } + public byte[][] transactions { get; set; } + public Withdrawal[]? withdrawals { get; set; } + public ulong? blob_gas_used { get; set; } + public ulong? excess_blob_gas { get; set; } + + public ExecutionPayloadV3 ToExecutionPayloadV3() + { + return new ExecutionPayloadV3 + { + ParentHash = parent_hash, + FeeRecipient = fee_recipient, + StateRoot = state_root, + ReceiptsRoot = receipts_root, + LogsBloom = logs_bloom, + PrevRandao = prev_randao, + BlockNumber = block_number, + GasLimit = gas_limit, + GasUsed = gas_used, + Timestamp = timestamp, + ExtraData = extra_data, + BaseFeePerGas = base_fee_per_gas, + BlockHash = block_hash, + Transactions = transactions, + Withdrawals = withdrawals, + BlobGasUsed = blob_gas_used, + ExcessBlobGas = excess_blob_gas + }; + } + + public RExecutionPayloadV3( + Hash256 parent_hash, + Address fee_recipient, + Hash256 state_root, + Hash256 receipts_root, + Bloom logs_bloom, + Hash256 prev_randao, + long block_number, + long gas_limit, + long gas_used, + ulong timestamp, + byte[] extra_data, + UInt256 base_fee_per_gas, + Hash256 block_hash, + byte[][] transactions, + Withdrawal[]? withdrawals, + ulong? blob_gas_used, + ulong? excess_blob_gas + ) + { + this.parent_hash = parent_hash; + this.fee_recipient = fee_recipient; + this.state_root = state_root; + this.receipts_root = receipts_root; + this.logs_bloom = logs_bloom; + this.prev_randao = prev_randao; + this.block_number = block_number; + this.gas_limit = gas_limit; + this.gas_used = gas_used; + this.timestamp = timestamp; + this.extra_data = extra_data; + this.base_fee_per_gas = base_fee_per_gas; + this.block_hash = block_hash; + this.transactions = transactions; + this.withdrawals = withdrawals; + this.blob_gas_used = blob_gas_used; + this.excess_blob_gas = excess_blob_gas; + } +} diff --git a/src/Nethermind/Nethermind.Flashbots/Modules/Flashbots/FlashbotsRpcModule.cs b/src/Nethermind/Nethermind.Flashbots/Modules/Flashbots/FlashbotsRpcModule.cs index 8f10a21fd5d..e4bbe526011 100644 --- a/src/Nethermind/Nethermind.Flashbots/Modules/Flashbots/FlashbotsRpcModule.cs +++ b/src/Nethermind/Nethermind.Flashbots/Modules/Flashbots/FlashbotsRpcModule.cs @@ -2,10 +2,10 @@ // SPDX-License-Identifier: LGPL-3.0-only using System.Threading.Tasks; -using Nethermind.Core.Crypto; using Nethermind.Flashbots.Data; using Nethermind.Flashbots.Handlers; using Nethermind.JsonRpc; +using Nethermind.Merge.Plugin.Data; namespace Nethermind.Flashbots.Modules.Flashbots; @@ -21,4 +21,18 @@ public FlashbotsRpcModule(ValidateSubmissionHandler validateSubmissionHandler) Task> IFlashbotsRpcModule.flashbots_validateBuilderSubmissionV3(BuilderBlockValidationRequest @params) => _validateSubmissionHandler.ValidateSubmission(@params); + Task> IFlashbotsRpcModule.flashbots_validateRBuilderSubmissionV3(RBuilderBlockValidationRequest @params) + { + ExecutionPayloadV3 executionPayload = @params.execution_payload.ToExecutionPayloadV3(); + BuilderBlockValidationRequest builderBlockValidationRequest = new BuilderBlockValidationRequest( + @params.parent_beacon_block_root, + @params.registered_gas_limit, + new SubmitBlockRequest( + executionPayload, + @params.blobs_bundle, + @params.message.ToBidTrace() + ) + ); + return _validateSubmissionHandler.ValidateSubmission(builderBlockValidationRequest); + } } diff --git a/src/Nethermind/Nethermind.Flashbots/Modules/Flashbots/IFlashbotsRpcModule.cs b/src/Nethermind/Nethermind.Flashbots/Modules/Flashbots/IFlashbotsRpcModule.cs index b81da13fb39..b0fdad2ab06 100644 --- a/src/Nethermind/Nethermind.Flashbots/Modules/Flashbots/IFlashbotsRpcModule.cs +++ b/src/Nethermind/Nethermind.Flashbots/Modules/Flashbots/IFlashbotsRpcModule.cs @@ -16,4 +16,10 @@ public interface IFlashbotsRpcModule : IRpcModule IsSharable = false, IsImplemented = true)] Task> flashbots_validateBuilderSubmissionV3(BuilderBlockValidationRequest @params); + + [JsonRpcMethod( + Description = " validate the builder submissions as received by a relay", + IsSharable = false, + IsImplemented = true)] + Task> flashbots_validateRBuilderSubmissionV3(RBuilderBlockValidationRequest @params); } diff --git a/src/Nethermind/Nethermind.Runner/configs/holesky.json b/src/Nethermind/Nethermind.Runner/configs/holesky.json index 27101434088..617ea933a55 100644 --- a/src/Nethermind/Nethermind.Runner/configs/holesky.json +++ b/src/Nethermind/Nethermind.Runner/configs/holesky.json @@ -27,7 +27,10 @@ "Port": 8545, "EngineHost": "127.0.0.1", "EnginePort": 8551, - "EngineEnabledModules": "net,eth,subscribe,engine,web3,client" + "EngineEnabledModules": "net,eth,subscribe,engine,web3,client,flashbots" + }, + "Flashbots": { + "Enabled": true }, "Merge": { "Enabled": true From feca33d92edac24d16ba6d09d09aded99e3d3fbf Mon Sep 17 00:00:00 2001 From: Rohit Ranjan Date: Tue, 4 Feb 2025 14:38:44 +0530 Subject: [PATCH 2/4] remove comments --- .../Nethermind.Flashbots/Data/BidTrace.cs | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/src/Nethermind/Nethermind.Flashbots/Data/BidTrace.cs b/src/Nethermind/Nethermind.Flashbots/Data/BidTrace.cs index 2ff3054297b..073a8b8370e 100644 --- a/src/Nethermind/Nethermind.Flashbots/Data/BidTrace.cs +++ b/src/Nethermind/Nethermind.Flashbots/Data/BidTrace.cs @@ -40,17 +40,4 @@ public BidTrace( GasUsed = gasUsed; Value = value; } - - // public BidTrace(Message message) : this( - // message.Slot, - // message.ParentHash, - // message.BlockHash, - // message.BuilderPublicKey, - // message.ProposerPublicKey, - // message.ProposerFeeRecipient, - // message.GasLimit, - // message.GasUsed, - // message.Value) - // { - // } } From d9c34cb1e228e219d0ab827c06b98768b717f429 Mon Sep 17 00:00:00 2001 From: Rohit Ranjan Date: Tue, 4 Feb 2025 14:39:22 +0530 Subject: [PATCH 3/4] revert holesky config --- src/Nethermind/Nethermind.Runner/configs/holesky.json | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Nethermind/Nethermind.Runner/configs/holesky.json b/src/Nethermind/Nethermind.Runner/configs/holesky.json index 617ea933a55..27101434088 100644 --- a/src/Nethermind/Nethermind.Runner/configs/holesky.json +++ b/src/Nethermind/Nethermind.Runner/configs/holesky.json @@ -27,10 +27,7 @@ "Port": 8545, "EngineHost": "127.0.0.1", "EnginePort": 8551, - "EngineEnabledModules": "net,eth,subscribe,engine,web3,client,flashbots" - }, - "Flashbots": { - "Enabled": true + "EngineEnabledModules": "net,eth,subscribe,engine,web3,client" }, "Merge": { "Enabled": true From 6e8b581f8356c7c9f0998ae7165b69950d7faa2f Mon Sep 17 00:00:00 2001 From: Rohit Ranjan Date: Tue, 4 Feb 2025 16:47:15 +0530 Subject: [PATCH 4/4] add signature --- .../Data/RBuilderBlockValidationRequest.cs | 5 +++++ .../Nethermind.Flashbots/Data/SubmitBlockRequest.cs | 4 +++- .../Modules/Flashbots/FlashbotsRpcModule.cs | 3 ++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Nethermind/Nethermind.Flashbots/Data/RBuilderBlockValidationRequest.cs b/src/Nethermind/Nethermind.Flashbots/Data/RBuilderBlockValidationRequest.cs index a2f2dc945e1..4d80db37bc0 100644 --- a/src/Nethermind/Nethermind.Flashbots/Data/RBuilderBlockValidationRequest.cs +++ b/src/Nethermind/Nethermind.Flashbots/Data/RBuilderBlockValidationRequest.cs @@ -13,6 +13,7 @@ public RBuilderBlockValidationRequest( Message message, RExecutionPayloadV3 execution_payload, BlobsBundleV1 blobs_bundle, + byte[] signature, long registered_gas_limit, Hash256 withdrawals_root, Hash256 parent_beacon_block_root) @@ -20,6 +21,7 @@ public RBuilderBlockValidationRequest( this.message = message; this.execution_payload = execution_payload; this.blobs_bundle = blobs_bundle; + this.signature = signature; this.registered_gas_limit = registered_gas_limit; this.withdrawals_root = withdrawals_root; this.parent_beacon_block_root = parent_beacon_block_root; @@ -34,6 +36,9 @@ public RBuilderBlockValidationRequest( [JsonRequired] public BlobsBundleV1 blobs_bundle { get; set; } + [JsonRequired] + public byte[] signature { get; set; } + [JsonRequired] public long registered_gas_limit { get; set; } diff --git a/src/Nethermind/Nethermind.Flashbots/Data/SubmitBlockRequest.cs b/src/Nethermind/Nethermind.Flashbots/Data/SubmitBlockRequest.cs index 6e7cc6d783c..f46c9743f4d 100644 --- a/src/Nethermind/Nethermind.Flashbots/Data/SubmitBlockRequest.cs +++ b/src/Nethermind/Nethermind.Flashbots/Data/SubmitBlockRequest.cs @@ -10,13 +10,15 @@ public class SubmitBlockRequest private readonly ExecutionPayloadV3 _executionPayload; private readonly BlobsBundleV1 _blobsBundle; - public SubmitBlockRequest(ExecutionPayloadV3 executionPayload, BlobsBundleV1 blobsBundle, BidTrace message) + public SubmitBlockRequest(ExecutionPayloadV3 executionPayload, BlobsBundleV1 blobsBundle, BidTrace message, byte[] signature) { _executionPayload = executionPayload; _blobsBundle = blobsBundle; Message = message; + Signature = signature; } public ExecutionPayloadV3 ExecutionPayload => _executionPayload; public BlobsBundleV1 BlobsBundle => _blobsBundle; public BidTrace Message { get; } + public byte[] Signature { get; } } diff --git a/src/Nethermind/Nethermind.Flashbots/Modules/Flashbots/FlashbotsRpcModule.cs b/src/Nethermind/Nethermind.Flashbots/Modules/Flashbots/FlashbotsRpcModule.cs index e4bbe526011..dc7570a44a0 100644 --- a/src/Nethermind/Nethermind.Flashbots/Modules/Flashbots/FlashbotsRpcModule.cs +++ b/src/Nethermind/Nethermind.Flashbots/Modules/Flashbots/FlashbotsRpcModule.cs @@ -30,7 +30,8 @@ Task> IFlashbotsRpcModule.flashbots_validateRBuil new SubmitBlockRequest( executionPayload, @params.blobs_bundle, - @params.message.ToBidTrace() + @params.message.ToBidTrace(), + @params.signature ) ); return _validateSubmissionHandler.ValidateSubmission(builderBlockValidationRequest);