-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a618ff2
commit 1d351ba
Showing
1 changed file
with
121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
--- | ||
eip: 6465 | ||
title: SSZ withdrawals root | ||
description: Migration of withdrawals MPT commitment to SSZ | ||
author: Etan Kissling (@etan-status) | ||
discussions-to: https://ethereum-magicians.org/t/eip-6465-ssz-withdrawals-root/12883 | ||
status: Draft | ||
type: Standards Track | ||
category: Core | ||
created: 2023-02-08 | ||
requires: 4895 | ||
--- | ||
|
||
## Abstract | ||
|
||
This EIP defines a migration process of the existing Merkle-Patricia Trie (MPT) commitment for withdrawals to SSZ. | ||
|
||
## Motivation | ||
|
||
While the consensus `ExecutionPayloadHeader` and the execution block header map to each other conceptually, they are encoded differently. This EIP aims to align the encoding of the `withdrawals_root`, taking advantage of the more modern SSZ format. This brings several advantages: | ||
|
||
1. **Reducing complexity:** Merkle-Patricia Tries (MPT) are hard to work with. Replacing them with SSZ leaves only the state trie in the legacy MPT format. | ||
|
||
2. **Better for smart contracts:** The SSZ format is optimized for production and verification of merkle proofs. It allows proving specific fields of containers and allows chunked processing, e.g., to support handling transactions that do not fit into calldata. | ||
|
||
3. **Better for light clients:** Light clients with access to the consensus `ExecutionPayload` no longer need to obtain the matching execution block header to verify proofs rooted in `withdrawals_root`. | ||
|
||
4. **Reducing ambiguity:** The name `withdrawals_root` is currently used to refer to different roots. The execution block header refers to a MPT root, the consensus `ExecutionPayloadHeader` refers to a SSZ root. | ||
|
||
## Specification | ||
|
||
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119 and RFC 8174. | ||
|
||
### Execution block header changes | ||
|
||
The existing consensus [`Withdrawal`](https://github.com/ethereum/consensus-specs/blob/67c2f9ee9eb562f7cc02b2ff90d92c56137944e1/specs/capella/beacon-chain.md#withdrawal) SSZ container is used to represent withdrawals. | ||
|
||
```python | ||
class Withdrawal(Container): | ||
index: WithdrawalIndex | ||
validator_index: ValidatorIndex | ||
address: ExecutionAddress | ||
amount: Gwei | ||
``` | ||
|
||
The execution block header's `withdrawals-root` is updated to match the consensus [`ExecutionPayloadHeader.withdrawals_root`](https://github.com/ethereum/consensus-specs/blob/67c2f9ee9eb562f7cc02b2ff90d92c56137944e1/specs/eip4844/beacon-chain.md#executionpayloadheader). | ||
|
||
| Name | Value | Description | | ||
| - | - | - | | ||
| [`MAX_WITHDRAWALS_PER_PAYLOAD`](https://github.com/ethereum/consensus-specs/blob/67c2f9ee9eb562f7cc02b2ff90d92c56137944e1/specs/capella/beacon-chain.md#execution) | `uint64(2**4)` (= 16) | Maximum amount of withdrawals allowed in each block | | ||
|
||
```python | ||
block_header.withdrawals_root == hash_tree_root(List[Withdrawal, MAX_WITHDRAWALS_PER_PAYLOAD]( | ||
withdrawal_0, | ||
withdrawal_1, | ||
withdrawal_2, | ||
... | ||
)) | ||
``` | ||
|
||
### Helpers | ||
|
||
```python | ||
def encode_withdrawal(withdrawal: Withdrawal) -> bytes: | ||
schema = ( | ||
(big_endian_int, withdrawal.index), | ||
(big_endian_int, withdrawal.validator_index), | ||
(Binary[20, 20], withdrawal.address), | ||
(big_endian_int, withdrawal.amount), | ||
) | ||
sedes = List([schema for schema, _ in schema]) | ||
values = [value for _, value in schema] | ||
return rlp.encode(values, sedes) | ||
``` | ||
|
||
```python | ||
def decode_withdrawal(encoded_withdrawal: bytes) -> Withdrawal: | ||
class RLPWithdrawal(rlp.Serializable): | ||
fields = ( | ||
('index', bid_endian_int), | ||
('validator_index', big_endian_int), | ||
('address', Binary[20, 20]), | ||
('amount', big_endian_int), | ||
) | ||
pre = RLPWithdrawal.deserialize(encoded_withdrawal) | ||
|
||
return Withdrawal( | ||
index=pre.index, | ||
validator_index=pre.validator_index, | ||
address=pre.address, | ||
amount=pre.amount, | ||
) | ||
``` | ||
|
||
## Rationale | ||
|
||
This change was originally a candidate for inclusion in Shanghai, but was postponed to accelerate the rollout of withdrawals. | ||
|
||
## Backwards Compatibility | ||
|
||
Applications that solely rely on the `Withdrawal` RLP encoding but do not rely on the `withdrawals_root` in the block header can still be used through a re-encoding proxy. | ||
|
||
Applications that rely on the replaced `withdrawals_root` in the block header can no longer find that information. | ||
|
||
Withdrawals were only just recently introduced as part of [EIP-4895](./eip-4895.md) (Shanghai). It is not expected that major applications already rely on the Merkle-Patricia Trie commitment for withdrawals. | ||
|
||
## Test Cases | ||
|
||
TBD | ||
|
||
## Reference Implementation | ||
|
||
TBD | ||
|
||
## Security Considerations | ||
|
||
None | ||
|
||
## Copyright | ||
|
||
Copyright and related rights waived via [CC0](../LICENSE.md). |