Skip to content

Commit 471d181

Browse files
rjnrohitkamilchodola
authored andcommitted
requests validation hotfix (#8156)
1 parent 0c41a73 commit 471d181

File tree

2 files changed

+51
-2
lines changed

2 files changed

+51
-2
lines changed

src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V4.cs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,39 @@ public async Task NewPayloadV4_reject_payload_with_bad_authorization_list_rlp()
200200
Assert.That(response.Data.Status, Is.EqualTo("INVALID"));
201201
}
202202

203+
[Test]
204+
public async Task NewPayloadV4_reject_payload_with_bad_execution_requests()
205+
{
206+
ExecutionRequestsProcessorMock executionRequestsProcessorMock = new();
207+
using MergeTestBlockchain chain = await CreateBlockchain(Prague.Instance, null, null, null, executionRequestsProcessorMock);
208+
IEngineRpcModule rpc = CreateEngineModule(chain);
209+
Hash256 lastHash = (await ProduceBranchV4(rpc, chain, 10, CreateParentBlockRequestOnHead(chain.BlockTree), true, withRequests: true))
210+
.LastOrDefault()?.BlockHash ?? Keccak.Zero;
211+
212+
Block TestBlock = Build.A.Block.WithNumber(chain.BlockTree.Head!.Number + 1).TestObject;
213+
ExecutionPayloadV3 executionPayload = ExecutionPayloadV3.Create(TestBlock);
214+
215+
// must reject if execution requests types are not in ascending order
216+
var response = await rpc.engine_newPayloadV4(
217+
executionPayload,
218+
[],
219+
TestBlock.ParentBeaconBlockRoot,
220+
executionRequests: [Bytes.FromHexString("0x0001"), Bytes.FromHexString("0x0101"), Bytes.FromHexString("0x0101")]
221+
);
222+
223+
Assert.That(response.ErrorCode, Is.EqualTo(ErrorCodes.InvalidParams));
224+
225+
//must reject if one of the execution requests size is <= 1 byte
226+
response = await rpc.engine_newPayloadV4(
227+
executionPayload,
228+
[],
229+
TestBlock.ParentBeaconBlockRoot,
230+
executionRequests: [Bytes.FromHexString("0x0001"), Bytes.FromHexString("0x01"), Bytes.FromHexString("0x0101")]
231+
);
232+
233+
Assert.That(response.ErrorCode, Is.EqualTo(ErrorCodes.InvalidParams));
234+
}
235+
203236
[TestCase(30)]
204237
public async Task can_progress_chain_one_by_one_v4(int count)
205238
{
@@ -247,7 +280,7 @@ private async Task<IReadOnlyList<ExecutionPayload>> ProduceBranchV4(IEngineRpcMo
247280
ExecutionPayloadV3? getPayloadResult = await BuildAndGetPayloadOnBranchV4(rpc, chain, parentHeader,
248281
parentBlock.Timestamp + 12,
249282
random ?? TestItem.KeccakA, Address.Zero);
250-
PayloadStatusV1 payloadStatusResponse = (await rpc.engine_newPayloadV4(getPayloadResult, [], Keccak.Zero, executionRequests: withRequests ? ExecutionRequestsProcessorMock.Requests : new byte[][] { [], [], [] })).Data;
283+
PayloadStatusV1 payloadStatusResponse = (await rpc.engine_newPayloadV4(getPayloadResult, [], Keccak.Zero, executionRequests: withRequests ? ExecutionRequestsProcessorMock.Requests : new byte[][] { })).Data;
251284
payloadStatusResponse.Status.Should().Be(PayloadStatus.Valid);
252285
if (setHead)
253286
{

src/Nethermind/Nethermind.Merge.Plugin/Data/IExecutionPayloadParams.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,23 @@ public ValidationResult ValidateParams(IReleaseSpec spec, int version, out strin
5151
if (ExecutionRequests.Length > ExecutionRequestExtensions.MaxRequestsCount)
5252
{
5353
error = $"Execution requests must have less than {ExecutionRequestExtensions.MaxRequestsCount} items";
54-
return ValidationResult.Invalid;
54+
return ValidationResult.Fail;
55+
}
56+
57+
// verification of the requests
58+
for (int i = 0; i < ExecutionRequests.Length; i++)
59+
{
60+
if (ExecutionRequests[i] == null || ExecutionRequests[i].Length <= 1)
61+
{
62+
error = "Execution request data must be longer than 1 byte";
63+
return ValidationResult.Fail;
64+
}
65+
66+
if (i > 0 && ExecutionRequests[i][0] <= ExecutionRequests[i - 1][0])
67+
{
68+
error = "Execution requests must not contain duplicates and be ordered by request_type in ascending order";
69+
return ValidationResult.Fail;
70+
}
5571
}
5672

5773
}

0 commit comments

Comments
 (0)