10 KiB
Electra -- Honest Validator
Table of contents
- Introduction
- Prerequisites
- Helpers
- Containers
- Protocol
- Block proposal
- Attesting
- Attestation aggregation
Introduction
This document represents the changes to be made in the code of an "honest validator" to implement Electra.
Prerequisites
This document is an extension of the Deneb -- Honest Validator guide. All behaviors and definitions defined in this document, and documents it extends, carry over unless explicitly noted or overridden.
All terminology, constants, functions, and protocol mechanics defined in the updated Beacon Chain doc of Electra are requisite for this document and used throughout. Please see related Beacon Chain doc before continuing and use them as a reference throughout.
Helpers
Modified GetPayloadResponse
@dataclass
class GetPayloadResponse(object):
execution_payload: ExecutionPayload
block_value: uint256
blobs_bundle: BlobsBundle
execution_requests: Sequence[bytes] # [New in Electra]
Containers
Modified Containers
AggregateAndProof
class AggregateAndProof(Container):
aggregator_index: ValidatorIndex
aggregate: Attestation # [Modified in Electra:EIP7549]
selection_proof: BLSSignature
SignedAggregateAndProof
class SignedAggregateAndProof(Container):
message: AggregateAndProof # [Modified in Electra:EIP7549]
signature: BLSSignature
Protocol
ExecutionEngine
Modified get_payload
Given the payload_id, get_payload returns the most recent version of the execution payload that
has been built since the corresponding call to notify_forkchoice_updated method.
def get_payload(self: ExecutionEngine, payload_id: PayloadId) -> GetPayloadResponse:
"""
Return ExecutionPayload, uint256, BlobsBundle and execution requests (as Sequence[bytes]) objects.
"""
# pylint: disable=unused-argument
...
Block proposal
Constructing the BeaconBlockBody
Attester slashings
Changed the max attester slashings size to MAX_ATTESTER_SLASHINGS_ELECTRA.
Attestations
Changed the max attestations size to MAX_ATTESTATIONS_ELECTRA.
The network attestation aggregates contain only the assigned committee attestations.
Attestation aggregates received by the block proposer from the committee aggregators with disjoint committee_bits sets and equal AttestationData SHOULD be consolidated into a single Attestation object.
The proposer should run the following function to construct an on chain final aggregate form a list of network aggregates with equal AttestationData:
def compute_on_chain_aggregate(network_aggregates: Sequence[Attestation]) -> Attestation:
aggregates = sorted(network_aggregates, key=lambda a: get_committee_indices(a.committee_bits)[0])
data = aggregates[0].data
aggregation_bits = Bitlist[MAX_VALIDATORS_PER_COMMITTEE * MAX_COMMITTEES_PER_SLOT]()
for a in aggregates:
for b in a.aggregation_bits:
aggregation_bits.append(b)
signature = bls.Aggregate([a.signature for a in aggregates])
committee_indices = [get_committee_indices(a.committee_bits)[0] for a in aggregates]
committee_flags = [(index in committee_indices) for index in range(0, MAX_COMMITTEES_PER_SLOT)]
committee_bits = Bitvector[MAX_COMMITTEES_PER_SLOT](committee_flags)
return Attestation(
aggregation_bits=aggregation_bits,
data=data,
committee_bits=committee_bits,
signature=signature,
)
Deposits
[New in Electra:EIP6110] The expected number of deposits MUST be changed from min(MAX_DEPOSITS, eth1_data.deposit_count - state.eth1_deposit_index) to the result of the following function:
def get_eth1_pending_deposit_count(state: BeaconState) -> uint64:
eth1_deposit_index_limit = min(state.eth1_data.deposit_count, state.deposit_requests_start_index)
if state.eth1_deposit_index < eth1_deposit_index_limit:
return min(MAX_DEPOSITS, eth1_deposit_index_limit - state.eth1_deposit_index)
else:
return uint64(0)
Execution payload
prepare_execution_payload is updated from the Deneb specs.
Note: In this section, state is the state of the slot for the block proposal without the block yet applied.
That is, state is the previous_state processed through any empty slots up to the assigned slot using process_slots(previous_state, slot).
Note: The only change to prepare_execution_payload is the new definition of get_expected_withdrawals.
def prepare_execution_payload(state: BeaconState,
safe_block_hash: Hash32,
finalized_block_hash: Hash32,
suggested_fee_recipient: ExecutionAddress,
execution_engine: ExecutionEngine) -> Optional[PayloadId]:
# Verify consistency of the parent hash with respect to the previous execution payload header
parent_hash = state.latest_execution_payload_header.block_hash
# Set the forkchoice head and initiate the payload build process
withdrawals, _ = get_expected_withdrawals(state) # [Modified in EIP-7251]
payload_attributes = PayloadAttributes(
timestamp=compute_timestamp_at_slot(state, state.slot),
prev_randao=get_randao_mix(state, get_current_epoch(state)),
suggested_fee_recipient=suggested_fee_recipient,
withdrawals=withdrawals,
parent_beacon_block_root=hash_tree_root(state.latest_block_header),
)
return execution_engine.notify_forkchoice_updated(
head_block_hash=parent_hash,
safe_block_hash=safe_block_hash,
finalized_block_hash=finalized_block_hash,
payload_attributes=payload_attributes,
)
Execution Requests
[New in Electra]
- The execution payload is obtained from the execution engine as defined above using
payload_id. The response also includes aexecution_requestsentry containing a list of bytes. Each element on the list corresponds to one SSZ list of requests as defined in EIP-7685. The first byte of each request is used to determine the request type. Requests must be ordered by request type in ascending order. As a result, there can only be at most one instance of each request type. - Set
block.body.execution_requests = get_execution_requests(execution_requests), where:
def get_execution_requests(execution_requests_list: Sequence[bytes]) -> ExecutionRequests:
deposits = []
withdrawals = []
consolidations = []
request_types = [
DEPOSIT_REQUEST_TYPE,
WITHDRAWAL_REQUEST_TYPE,
CONSOLIDATION_REQUEST_TYPE,
]
prev_request_type = None
for request in execution_requests_list:
request_type, request_data = request[0:1], request[1:]
# Check that the request type is valid
assert request_type in request_types
# Check that the request data is not empty
assert len(request_data) != 0
# Check that requests are in strictly ascending order
# Each successive type must be greater than the last with no duplicates
assert prev_request_type is None or prev_request_type < request_type
prev_request_type = request_type
if request_type == DEPOSIT_REQUEST_TYPE:
deposits = ssz_deserialize(
List[DepositRequest, MAX_DEPOSIT_REQUESTS_PER_PAYLOAD],
request_data
)
elif request_type == WITHDRAWAL_REQUEST_TYPE:
withdrawals = ssz_deserialize(
List[WithdrawalRequest, MAX_WITHDRAWAL_REQUESTS_PER_PAYLOAD],
request_data
)
elif request_type == CONSOLIDATION_REQUEST_TYPE:
consolidations = ssz_deserialize(
List[ConsolidationRequest, MAX_CONSOLIDATION_REQUESTS_PER_PAYLOAD],
request_data
)
return ExecutionRequests(
deposits=deposits,
withdrawals=withdrawals,
consolidations=consolidations,
)
Constructing the BlobSidecars
Sidecar
[Modified in Electra:EIP7691]
def compute_subnet_for_blob_sidecar(blob_index: BlobIndex) -> SubnetID:
return SubnetID(blob_index % BLOB_SIDECAR_SUBNET_COUNT_ELECTRA)
Attesting
Construct attestation
The validator creates attestation as a SingleAttestation container
with updated field assignments:
- Set
attestation_data.index = 0. - Set
attestation.committee_indexto the index associated with the validator's committee. - Set
attestation.attester_indexto the index of the validator.
Attestation aggregation
Construct aggregate
- Set
attestation_data.index = 0. - Let
aggregation_bitsbe aBitlist[MAX_VALIDATORS_PER_COMMITTEE * MAX_COMMITTEES_PER_SLOT]of lengthlen(committee), where each bit set from each individual attestation is set to0b1. - Set
attestation.committee_bits = committee_bits, wherecommittee_bitshas the bit set corresponding tocommittee_indexin each individual attestation.