diff --git a/packages/client/src/rpc/modules/engine/util/getPayload.ts b/packages/client/src/rpc/modules/engine/util/getPayload.ts index fec0814f2d..615fbe04f7 100644 --- a/packages/client/src/rpc/modules/engine/util/getPayload.ts +++ b/packages/client/src/rpc/modules/engine/util/getPayload.ts @@ -25,9 +25,20 @@ export const blockToExecutionPayload = ( // ethereumjs does not provide any transaction censoring detection (yet) to suggest // overriding builder/mev-boost blocks const shouldOverrideBuilder = false + + let executionRequests = undefined + if (requests !== undefined) { + executionRequests = [] + for (const request of requests) { + if (request.bytes.length > 1) { + executionRequests.push(bytesToHex(request.bytes)) + } + } + } + return { executionPayload, - executionRequests: requests?.map((req) => bytesToHex(req.data)), + executionRequests, blockValue: bigIntToHex(value), blobsBundle, shouldOverrideBuilder, diff --git a/packages/client/src/rpc/modules/engine/util/newPayload.ts b/packages/client/src/rpc/modules/engine/util/newPayload.ts index 5155ddfc5a..c2c42e6f7a 100644 --- a/packages/client/src/rpc/modules/engine/util/newPayload.ts +++ b/packages/client/src/rpc/modules/engine/util/newPayload.ts @@ -57,30 +57,35 @@ export const validateAndGen7685RequestsHash = ( common: Common, executionRequests: PrefixedHexString[], ): PrefixedHexString => { - let validationError: string | null = null - const requests: CLRequest[] = [] - let requestIndex = 0 - if (common.isActivatedEIP(6110)) { - requests.push(new CLRequest(CLRequestType.Deposit, hexToBytes(executionRequests[requestIndex]))) - requestIndex++ - } - if (common.isActivatedEIP(7002)) { - requests.push( - new CLRequest(CLRequestType.Withdrawal, hexToBytes(executionRequests[requestIndex])), - ) - requestIndex++ - } - if (common.isActivatedEIP(7251)) { - requests.push( - new CLRequest(CLRequestType.Consolidation, hexToBytes(executionRequests[requestIndex])), - ) - requestIndex++ - } - if (requestIndex !== executionRequests.length) { - validationError = `Invalid executionRequests=${executionRequests.length} expected=${requestIndex}` - throw validationError + for (const request of executionRequests) { + const bytes = hexToBytes(request) + if (bytes.length === 0) { + throw new Error('Got a request without a request-identifier') + } + switch (bytes[0]) { + case 0: + if (!common.isActivatedEIP(6110)) { + throw new Error(`Deposit requests are not active`) + } + requests.push(new CLRequest(CLRequestType.Deposit, bytes.slice(1))) + break + case 1: + if (!common.isActivatedEIP(7002)) { + throw new Error(`Withdrawal requests are not active`) + } + requests.push(new CLRequest(CLRequestType.Withdrawal, bytes.slice(1))) + break + case 2: + if (!common.isActivatedEIP(7251)) { + throw new Error(`Consolidation requests are not active`) + } + requests.push(new CLRequest(CLRequestType.Consolidation, bytes.slice(1))) + break + default: + throw new Error(`Unknown request identifier: got ${bytes[0]}`) + } } const sha256Function = common.customCrypto.sha256 ?? sha256 diff --git a/packages/client/test/rpc/engine/newPayloadV4.spec.ts b/packages/client/test/rpc/engine/newPayloadV4.spec.ts index 3fdda74f04..6b5634024b 100644 --- a/packages/client/test/rpc/engine/newPayloadV4.spec.ts +++ b/packages/client/test/rpc/engine/newPayloadV4.spec.ts @@ -180,7 +180,7 @@ describe(`${method}: call with executionPayloadV4`, () => { assert.ok(res.error.message.includes(expectedError)) } - res = await rpc.request(method, [validBlock, [], parentBeaconBlockRoot, ['0x', '0x', '0x']]) + res = await rpc.request(method, [validBlock, [], parentBeaconBlockRoot, []]) assert.equal(res.result.status, 'VALID') res = await rpc.request('engine_forkchoiceUpdatedV3', validPayload) @@ -201,9 +201,20 @@ describe(`${method}: call with executionPayloadV4`, () => { res = await rpc.request('engine_getPayloadV4', [payloadId]) const { executionPayload, executionRequests } = res.result + + assert.ok( + executionRequests?.length === 1, + 'executionRequests should have the deposit request, and should exclude the other requests (these are empty)', + ) + + const depositRequestBytes = hexToBytes(executionRequests[0]) + assert.ok( + depositRequestBytes[0] === 0x00, + 'deposit request byte 0 is the deposit request identifier byte (0x00)', + ) assert.ok( - executionRequests?.length === 3, - 'executionRequests should have 3 entries for each request type', + depositRequestBytes.length > 1, + 'deposit request includes data (and is thus not empty)', ) res = await rpc.request(method, [