2022-03-10 05:31:11 +00:00
# EIP-4844 -- Honest Validator
**Notice**: This document is a work-in-progress for researchers and implementers.
## Table of contents
<!-- TOC -->
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE - RUN doctoc TO UPDATE -->
- [Introduction ](#introduction )
- [Prerequisites ](#prerequisites )
2022-07-13 10:13:30 +00:00
- [Custom types ](#custom-types )
- [Containers ](#containers )
2022-07-21 16:11:30 +00:00
- [`BlobsAndCommitments` ](#blobsandcommitments )
2022-07-13 10:13:30 +00:00
- [`PolynomialAndCommitment` ](#polynomialandcommitment )
2022-03-10 05:31:11 +00:00
- [Helpers ](#helpers )
- [`is_data_available` ](#is_data_available )
2022-06-23 10:44:37 +00:00
- [`hash_to_bls_field` ](#hash_to_bls_field )
- [`compute_powers` ](#compute_powers )
2022-07-13 10:13:30 +00:00
- [`compute_aggregated_poly_and_commitment` ](#compute_aggregated_poly_and_commitment )
2022-07-15 15:54:53 +00:00
- [`validate_blobs_sidecar` ](#validate_blobs_sidecar )
2022-07-13 10:13:30 +00:00
- [`compute_proof_from_blobs` ](#compute_proof_from_blobs )
2022-07-15 15:29:22 +00:00
- [`get_blobs_and_kzg_commitments` ](#get_blobs_and_kzg_commitments )
2022-03-10 05:31:11 +00:00
- [Beacon chain responsibilities ](#beacon-chain-responsibilities )
- [Block proposal ](#block-proposal )
- [Constructing the `BeaconBlockBody` ](#constructing-the-beaconblockbody )
2022-07-13 10:13:30 +00:00
- [Blob KZG commitments ](#blob-kzg-commitments )
2022-03-10 05:31:11 +00:00
- [Beacon Block publishing time ](#beacon-block-publishing-time )
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
<!-- /TOC -->
## Introduction
This document represents the changes to be made in the code of an "honest validator" to implement EIP-4844.
## Prerequisites
2022-03-14 17:54:54 +00:00
This document is an extension of the [Bellatrix -- Honest Validator ](../bellatrix/validator.md ) guide.
2022-03-10 05:31:11 +00:00
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 EIP4844 ](./beacon-chain.md ) are requisite for this document and used throughout.
Please see related Beacon Chain doc before continuing and use them as a reference throughout.
2022-07-13 10:12:31 +00:00
## Custom types
| Name | SSZ equivalent | Description |
| - | - | - |
2022-07-21 05:58:22 +00:00
| `Polynomial` | `List[BLSFieldElement, FIELD_ELEMENTS_PER_BLOB]` | a polynomial in evaluation form |
2022-07-13 10:12:31 +00:00
## Containers
2022-07-21 16:11:30 +00:00
### `BlobsAndCommitments`
2022-07-13 10:12:31 +00:00
```python
2022-07-21 16:11:30 +00:00
class BlobsAndCommitments(Container):
2022-07-13 10:12:31 +00:00
blobs: List[Blob, MAX_BLOBS_PER_BLOCK]
kzg_commitments: List[KZGCommitment, MAX_BLOBS_PER_BLOCK]
```
### `PolynomialAndCommitment`
```python
class PolynomialAndCommitment(Container):
polynomial: Polynomial
kzg_commitment: KZGCommitment
```
2022-03-10 05:31:11 +00:00
## Helpers
### `is_data_available`
The implementation of `is_data_available` is meant to change with later sharding upgrades.
Initially, it requires every verifying actor to retrieve the matching `BlobsSidecar` ,
2022-07-15 15:54:53 +00:00
and validate the sidecar with `validate_blobs_sidecar` .
2022-03-10 05:31:11 +00:00
Without the sidecar the block may be processed further optimistically,
but MUST NOT be considered valid until a valid `BlobsSidecar` has been downloaded.
```python
2022-07-13 10:13:30 +00:00
def is_data_available(slot: Slot, beacon_block_root: Root, blob_kzg_commitments: Sequence[KZGCommitment]) -> bool:
# `retrieve_blobs_sidecar` is implementation dependent, raises an exception if not available.
sidecar = retrieve_blobs_sidecar(slot, beacon_block_root)
2022-07-15 15:54:53 +00:00
validate_blobs_sidecar(slot, beacon_block_root, blob_kzg_commitments, sidecar)
return True
2022-03-10 05:31:11 +00:00
```
2022-06-23 10:44:37 +00:00
### `hash_to_bls_field`
2022-03-10 05:31:11 +00:00
```python
2022-06-13 12:36:31 +00:00
def hash_to_bls_field(x: Container) -> BLSFieldElement:
"""
2022-08-22 07:59:39 +00:00
Compute 32-byte hash of serialized container and convert it to BLS field.
The output is not uniform over the BLS field.
2022-06-13 12:36:31 +00:00
"""
2022-09-26 15:57:00 +00:00
return bytes_to_bls_field(hash(ssz_serialize(x)))
2022-06-23 10:44:37 +00:00
```
2022-06-13 12:36:31 +00:00
2022-06-23 10:44:37 +00:00
### `compute_powers`
```python
2022-07-13 10:12:31 +00:00
def compute_powers(x: BLSFieldElement, n: uint64) -> Sequence[BLSFieldElement]:
"""
Return ``x`` to power of [0, n-1].
"""
2022-06-13 12:36:31 +00:00
current_power = 1
powers = []
for _ in range(n):
powers.append(BLSFieldElement(current_power))
current_power = current_power * int(x) % BLS_MODULUS
return powers
2022-06-23 10:44:37 +00:00
```
2022-06-13 12:36:31 +00:00
2022-07-13 10:12:31 +00:00
### `compute_aggregated_poly_and_commitment`
2022-06-13 12:36:31 +00:00
2022-06-23 10:44:37 +00:00
```python
2022-07-13 10:12:31 +00:00
def compute_aggregated_poly_and_commitment(
2022-09-19 19:10:48 +00:00
blobs: Sequence[Sequence[BLSFieldElement]],
2022-07-13 10:12:31 +00:00
kzg_commitments: Sequence[KZGCommitment]) -> Tuple[Polynomial, KZGCommitment]:
2022-06-13 12:36:31 +00:00
"""
2022-07-13 10:12:31 +00:00
Return the aggregated polynomial and aggregated KZG commitment.
2022-06-13 12:36:31 +00:00
"""
2022-07-13 10:12:31 +00:00
# Generate random linear combination challenges
2022-07-21 16:11:30 +00:00
r = hash_to_bls_field(BlobsAndCommitments(blobs=blobs, kzg_commitments=kzg_commitments))
2022-07-13 10:12:31 +00:00
r_powers = compute_powers(r, len(kzg_commitments))
# Create aggregated polynomial in evaluation form
2022-09-19 19:16:19 +00:00
aggregated_poly = Polynomial(vector_lincomb(blobs, r_powers))
2022-07-13 10:12:31 +00:00
# Compute commitment to aggregated polynomial
2022-09-19 19:16:19 +00:00
aggregated_poly_commitment = KZGCommitment(g1_lincomb(kzg_commitments, r_powers))
2022-07-13 10:12:31 +00:00
return aggregated_poly, aggregated_poly_commitment
2022-06-23 10:44:37 +00:00
```
2022-06-13 12:36:31 +00:00
2022-07-15 15:54:53 +00:00
### `validate_blobs_sidecar`
2022-03-10 05:31:11 +00:00
```python
2022-07-15 15:54:53 +00:00
def validate_blobs_sidecar(slot: Slot,
beacon_block_root: Root,
expected_kzg_commitments: Sequence[KZGCommitment],
blobs_sidecar: BlobsSidecar) -> None:
2022-03-10 05:31:11 +00:00
assert slot == blobs_sidecar.beacon_block_slot
assert beacon_block_root == blobs_sidecar.beacon_block_root
blobs = blobs_sidecar.blobs
2022-06-13 12:30:12 +00:00
kzg_aggregated_proof = blobs_sidecar.kzg_aggregated_proof
2022-07-13 10:12:31 +00:00
assert len(expected_kzg_commitments) == len(blobs)
2022-03-10 05:31:11 +00:00
2022-07-13 10:12:31 +00:00
aggregated_poly, aggregated_poly_commitment = compute_aggregated_poly_and_commitment(
blobs,
expected_kzg_commitments,
)
2022-06-13 12:30:12 +00:00
# Generate challenge `x` and evaluate the aggregated polynomial at `x`
2022-07-13 10:12:31 +00:00
x = hash_to_bls_field(
PolynomialAndCommitment(polynomial=aggregated_poly, kzg_commitment=aggregated_poly_commitment)
)
# Evaluate aggregated polynomial at `x` (evaluation function checks for div-by-zero)
2022-06-13 12:30:12 +00:00
y = evaluate_polynomial_in_evaluation_form(aggregated_poly, x)
# Verify aggregated proof
2022-07-15 15:54:53 +00:00
assert verify_kzg_proof(aggregated_poly_commitment, x, y, kzg_aggregated_proof)
2022-07-13 10:12:31 +00:00
```
### `compute_proof_from_blobs`
```python
def compute_proof_from_blobs(blobs: Sequence[BLSFieldElement]) -> KZGProof:
commitments = [blob_to_kzg_commitment(blob) for blob in blobs]
aggregated_poly, aggregated_poly_commitment = compute_aggregated_poly_and_commitment(blobs, commitments)
x = hash_to_bls_field(PolynomialAndCommitment(
polynomial=aggregated_poly,
kzg_commitment=aggregated_poly_commitment,
))
return compute_kzg_proof(aggregated_poly, x)
2022-03-10 05:31:11 +00:00
```
2022-07-15 15:29:22 +00:00
### `get_blobs_and_kzg_commitments`
The interface to retrieve blobs and corresponding kzg commitments.
Note: This API is *unstable* . `get_blobs_and_kzg_commitments` and `get_payload` may be unified.
Implementers may also retrieve blobs individually per transaction.
```python
def get_blobs_and_kzg_commitments(payload_id: PayloadId) -> Tuple[Sequence[BLSFieldElement], Sequence[KZGCommitment]]:
...
```
2022-03-10 05:31:11 +00:00
## Beacon chain responsibilities
All validator responsibilities remain unchanged other than those noted below.
Namely, the blob handling and the addition of `BlobsSidecar` .
### Block proposal
#### Constructing the `BeaconBlockBody`
2022-07-13 10:12:31 +00:00
##### Blob KZG commitments
2022-03-10 05:31:11 +00:00
2022-07-15 15:29:22 +00:00
1. After retrieving the execution payload from the execution engine as specified in Bellatrix,
use the `payload_id` to retrieve `blobs` and `blob_kzg_commitments` via `get_blobs_and_kzg_commitments(payload_id)` .
2022-07-15 15:54:53 +00:00
2. Validate `blobs` and `blob_kzg_commitments` :
2022-03-10 05:31:11 +00:00
2022-07-15 15:29:22 +00:00
```python
2022-07-15 15:54:53 +00:00
def validate_blobs_and_kzg_commitments(execution_payload: ExecutionPayload,
blobs: Sequence[BLSFieldElement],
blob_kzg_commitments: Sequence[KZGCommitment]) -> None:
2022-07-15 15:29:22 +00:00
# Optionally sanity-check that the KZG commitments match the versioned hashes in the transactions
assert verify_kzg_commitments_against_transactions(execution_payload.transactions, blob_kzg_commitments)
# Optionally sanity-check that the KZG commitments match the blobs (as produced by the execution engine)
assert len(blob_kzg_commitments) == len(blobs)
assert [blob_to_kzg_commitment(blob) == commitment for blob, commitment in zip(blobs, blob_kzg_commitments)]
2022-07-13 10:12:31 +00:00
```
2022-03-10 05:31:11 +00:00
2022-07-15 15:29:22 +00:00
3. If valid, set `block.body.blob_kzg_commitments = blob_kzg_commitments` .
2022-03-10 05:31:11 +00:00
2022-07-15 15:29:22 +00:00
Note that the `blobs` should be held with the block in preparation of publishing.
2022-03-10 05:31:11 +00:00
Without the `blobs` , the published block will effectively be ignored by honest validators.
### Beacon Block publishing time
Before publishing a prepared beacon block proposal, the corresponding blobs are packaged into a sidecar object for distribution to the network:
```python
2022-07-13 10:12:31 +00:00
def get_blobs_sidecar(block: BeaconBlock, blobs: Sequence[Blob]) -> BlobsSidecar:
return BlobsSidecar(
beacon_block_root=hash_tree_root(block),
beacon_block_slot=block.slot,
blobs=blobs,
kzg_aggregated_proof=compute_proof_from_blobs(blobs),
)
2022-03-10 05:31:11 +00:00
```
And then signed:
```python
2022-07-13 10:12:31 +00:00
def get_signed_blobs_sidecar(state: BeaconState, blobs_sidecar: BlobsSidecar, privkey: int) -> SignedBlobsSidecar:
domain = get_domain(state, DOMAIN_BLOBS_SIDECAR, blobs_sidecar.beacon_block_slot // SLOTS_PER_EPOCH)
signing_root = compute_signing_root(blobs_sidecar, domain)
signature = bls.Sign(privkey, signing_root)
return SignedBlobsSidecar(message=blobs_sidecar, signature=signature)
2022-03-10 05:31:11 +00:00
```
2022-09-29 14:36:39 +00:00
This `signed_blobs_sidecar` is then published to the global `blobs_sidecar` topic as soon as the `signed_beacon_block` is published.
2022-03-10 05:31:11 +00:00
After publishing the sidecar peers on the network may request the sidecar through sync-requests, or a local user may be interested.
The validator MUST hold on to blobs for `MIN_EPOCHS_FOR_BLOBS_SIDECARS_REQUESTS` epochs and serve when capable,
to ensure the data-availability of these blobs throughout the network.
After `MIN_EPOCHS_FOR_BLOBS_SIDECARS_REQUESTS` nodes MAY prune the blobs and/or stop serving them.