|
43 | 43 | keystore_management, slashing_protection, validator_duties, validator_pool], |
44 | 44 | ".."/spec/mev/[rest_deneb_mev_calls, rest_electra_mev_calls, rest_fulu_mev_calls] |
45 | 45 |
|
46 | | -from std/sequtils import countIt, foldl, mapIt |
| 46 | +from std/sequtils import countIt, deduplicate, foldl, mapIt |
47 | 47 | from eth/async_utils import awaitWithTimeout |
48 | 48 |
|
49 | 49 | # Metrics for tracking attestation and beacon block loss |
@@ -443,6 +443,8 @@ proc getExecutionPayload( |
443 | 443 | PayloadType, beaconHead.blck.bid.root, executionHead, latestSafe, |
444 | 444 | latestFinalized, timestamp, random, feeRecipient, withdrawals) |
445 | 445 |
|
| 446 | +from std/algorithm import isSorted |
| 447 | + |
446 | 448 | # BlockRewards has issues resolving somehow otherwise |
447 | 449 | import ".."/spec/state_transition_block |
448 | 450 |
|
@@ -541,19 +543,37 @@ proc makeBeaconBlockForHeadAndSlot*( |
541 | 543 | let execution_requests_actual = |
542 | 544 | when PayloadType.kind >= ConsensusFork.Electra: |
543 | 545 | # Don't want un-decoded SSZ going any further/deeper |
| 546 | + var execution_requests_buffer: ExecutionRequests |
| 547 | + block: |
| 548 | + let request_types = mapIt(payload.executionRequests, it[0]) |
| 549 | + if not isSorted(request_types): |
| 550 | + return err("Execution layer request types not sorted") |
| 551 | + if payload.executionRequests.len != |
| 552 | + deduplicate(request_types, isSorted = true).len: |
| 553 | + return err("Execution layer request types duplicated") |
544 | 554 | try: |
545 | | - ExecutionRequests( |
546 | | - deposits: SSZ.decode( |
547 | | - payload.executionRequests[0], |
548 | | - List[DepositRequest, Limit MAX_DEPOSIT_REQUESTS_PER_PAYLOAD]), |
549 | | - withdrawals: SSZ.decode( |
550 | | - payload.executionRequests[1], |
551 | | - List[WithdrawalRequest, Limit MAX_WITHDRAWAL_REQUESTS_PER_PAYLOAD]), |
552 | | - consolidations: SSZ.decode( |
553 | | - payload.executionRequests[2], |
554 | | - List[ConsolidationRequest, Limit MAX_CONSOLIDATION_REQUESTS_PER_PAYLOAD])) |
| 555 | + for request_type_and_payload in payload.executionRequests: |
| 556 | + if request_type_and_payload.len < 2: |
| 557 | + return err("Execution layer request too short") |
| 558 | + template request_payload: untyped = |
| 559 | + request_type_and_payload.toOpenArray( |
| 560 | + 1, request_type_and_payload.len - 1) |
| 561 | + case request_type_and_payload[0] |
| 562 | + of 0'u8: execution_requests_buffer.deposits = SSZ.decode( |
| 563 | + request_payload, |
| 564 | + List[DepositRequest, Limit MAX_DEPOSIT_REQUESTS_PER_PAYLOAD]) |
| 565 | + of 1'u8: execution_requests_buffer.withdrawals = SSZ.decode( |
| 566 | + request_payload, |
| 567 | + List[WithdrawalRequest, Limit MAX_WITHDRAWAL_REQUESTS_PER_PAYLOAD]) |
| 568 | + of 2'u8: execution_requests_buffer.consolidations = SSZ.decode( |
| 569 | + request_payload, |
| 570 | + List[ConsolidationRequest, Limit MAX_CONSOLIDATION_REQUESTS_PER_PAYLOAD]) |
| 571 | + else: |
| 572 | + return err("Execution layer invalid request type") |
555 | 573 | except CatchableError: |
556 | 574 | return err("Unable to deserialize execution layer requests") |
| 575 | + |
| 576 | + execution_requests_buffer |
557 | 577 | else: |
558 | 578 | default(ExecutionRequests) # won't be used by block builder |
559 | 579 |
|
|
0 commit comments