Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update EIP-7612: Update func implementations and add further clarifications #8754

Merged
merged 4 commits into from
Jul 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 33 additions & 30 deletions EIPS/eip-7612.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@

## Abstract

This EIP proposes a method to switch the state tree tree format from hexary Merkle Patricia Tree (MPT) to a verkle tree: the MPT tree is frozen, and new writes to the state are stored in a verkle tree “laid over” the hexary MPT. The historical MPT state is left untouched and its eventual migration is handled at a later time.
This EIP proposes a method to switch the state tree tree format from hexary Merkle Patricia Tree (MPT) to a Verkle Tree (VKT): the MPT tree is frozen, and new writes to the state are stored in a VKT “laid over” the hexary MPT. The historical MPT state is left untouched and its eventual migration is handled at a later time.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For "Verkle Tree" do the same as we do for "Merkle Patricia Tree".


## Motivation

The Ethereum state is growing, and verkle trees offer a good mitigation strategy to stem this growth and enable weak statelessness. Owing to the difficulty of translating contracts with large storage while they are being accessed, proposals for migrating the current MPT state are complex and will require client teams to undergo a long process of refactoring their code to handle this conversion.
The Ethereum state is growing, and VKTs offer a good mitigation strategy to stem this growth and enable weak statelessness. Owing to the difficulty of translating contracts with large storage while they are being accessed, proposals for migrating the current MPT state are complex and will require client teams to undergo a long process of refactoring their code to handle this conversion.

The bigger the state, the longer any conversion process will take. This has an impact both while the conversion is happening, as well as when full-syncing the chain if the conversion is part of consensus. Fullsync is used extensively by core dev teams to test the performance of new code. A conversion longer than a month will impact the release schedule of client teams who typically release at this rate. Nodes that cannot follow the conversion will need to wait longer to rejoin. The conversion will also make reorg slower, so reducing its duration is desirable.
The bigger the state, the longer any conversion process will take. This has an impact both while the conversion is happening, as well as when full-syncing the chain if the conversion is part of consensus. Fullsync is used extensively by core dev teams to test the performance of new code. A conversion longer than a month will impact the release schedule of client teams who typically release at this rate. Nodes that cannot follow the conversion will need to wait longer to rejoin. The conversion will also make reorgs slower, so reducing its duration is desirable.

This current proposal suggests to stop the MPT state growth in its tracks by activating a new “overlay” verkle tree, that all new state updates are written to. The “base” MPT tree is frozen in place, until all execution clients are ready to perform the full transition. Data is read first from the overlay tree, and if not found there, from the MPT.
This current proposal suggests to stop the MPT state growth in its tracks by activating a new “overlay” VKT, that all new state updates are written to. The “base” MPT is frozen in place, until all execution clients are ready to perform the full transition. Data is read first from the overlay tree, and if not found there, from the MPT.

Whenever the block that freeze the MPT is finalized, internal node data can be deleted, in order to free up disk space.

Expand All @@ -31,9 +31,9 @@

### Constants

|Parameter|value|Description|
|-|-|-|
|`FORK_TIME`|`TDB`|Time at which the verkle, overlay tree is activated.|
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think TDB was a typo.

| Parameter | value | Description |
| ----------- | ----- | -------------------------------------------- |
| `FORK_TIME` | `TBD` | Time at which the overlay tree is activated. |

### Helper functions

Expand All @@ -45,43 +45,35 @@
# Write an account in the verkle tree
def verkle_set_account(tree: VerkleTree, key: Bytes32, account: Optional[Account]):
if account is not None:
versionkey = key
tree.set(versionkey, 0)
balancekey = key
balancekey[31] = BALANCE_LEAF_KEY
tree.set(balancekey, account.balance)
noncekey = key
noncekey[31] = NONCE_LEAF_KEY
tree.set(noncekey, account.nonce)
basicdata = bytes(0) # Version
basicdata += bytes(4) # Reserved
basicdata += len(account.code).to_bytes(3, 'big')
basicdata += account.nonce.to_bytes(8, 'big')
basicdata += account.balance.to_bytes(16, 'big')
Comment on lines +48 to +52
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update to do BASIC_DATA packing. This code assumes this PR will be accepted where we switch to big-endian encoding.

tree.set(key, basicdata)
ckkey = key
ckkey[31] = CODE_KECCAK_LEAF_KEY
ckkey[31] = CODEHASH_LEAF_KEY
Comment on lines -57 to +55
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Align naming to EIP-4762/EIP-6800

tree.set(ckkey, account.code_hash)
cskey = key
cskey[31] = CODE_SIZE_LEAF_KEY
tree.set(cskey, len(account.code))

# Reads an account from the verkle tree
def verkle_get_account(tree: VerkleTree, key: Bytes32) -> Optional[Account]:
version_leaf = tree.get(key)
if version_leaf is not None:
balancekey = key
balancekey[31] = BALANCE_LEAF_KEY
balance = tree.get(balancekey, account.balance)
noncekey = key
noncekey[31] = NONCE_LEAF_KEY
nonce = tree.get(noncekey)
basicdata_leaf = tree.get(key)
if basicdata_leaf is not None:
cs = int.from_bytes(basicdata_leaf[5:8], 'big')
nonce = int.from_bytes(basicdata_leaf[8:16], 'big')
balance = int.from_bytes(basicdata_leaf[16:32], 'big')
ckkey = key
ckkey[31] = CODE_KECCAK_LEAF_KEY
ckkey[31] = CODEHASH_LEAF_KEY
ck = tree.get(ckkey)
cskey = key
cskey[31] = CODE_SIZE_LEAF_KEY
cs = tree.set(cskey)
cs = tree.get(cskey)
account = Account(0, balance, nonce, ck, cs)

return account
```

### Changes to the execution spec:
### Changes to the execution spec

In the execution spec, modify the `State` class as such:

Expand Down Expand Up @@ -142,6 +134,17 @@
state._overlay_tree.set(get_tree_key_for_storage_slot(addr, slot), value)
```

Add the following function which is used when storing a contract in the tree:

```python3
def state_set_codechunk(state: State, addr: Address, chunk_num: int, chunk: Bytes):
state._overlay_tree.set(get_tree_key_for_code_chunk(addr, chunk_num), chunk)
```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isn't used anywhere, so imo we should remove it unless it is used

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not referenced in this EIP, but it's referenced in another one which has this one as a dependency, see here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would then put it the referring eip, but I will let the allmighty editors decide on this one. @g11tech ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually this code should be part of 6800, but that EIP doesn't have this "Python-style". But yep, let's see what @g11tech says and I can remove/move/add as needed.


### Changes to the block header

At `FORK_TIME` the block header state root is changed from the MPT root to the VKT root.

## Rationale

This approach doesn't convert the state, which is left to a subsequent EIP. This is meant as a stopgap in case we decide to push the conversion itself to a later time. It has the advantage of simplicity, which means that the Verge fork could happen at the same time as other, simpler EIPs. It also requires no change at the consensus layer.
Expand All @@ -152,7 +155,7 @@

## Test Cases

<!--

Check warning on line 158 in EIPS/eip-7612.md

View workflow job for this annotation

GitHub Actions / EIP Walidator

HTML comments are only allowed while `status` is one of: `Draft`, `Withdrawn`

warning[markdown-html-comments]: HTML comments are only allowed while `status` is one of: `Draft`, `Withdrawn` --> EIPS/eip-7612.md | 158 | <!-- | ::: EIPS/eip-7612.md | 173 | <!-- | = help: see https://ethereum.github.io/eipw/markdown-html-comments/

Check warning on line 158 in EIPS/eip-7612.md

View workflow job for this annotation

GitHub Actions / EIP Walidator

HTML comments are only allowed while `status` is one of: `Draft`, `Withdrawn`

warning[markdown-html-comments]: HTML comments are only allowed while `status` is one of: `Draft`, `Withdrawn` --> EIPS/eip-7612.md | 158 | <!-- | ::: EIPS/eip-7612.md | 173 | <!-- | = help: see https://ethereum.github.io/eipw/markdown-html-comments/

Check warning on line 158 in EIPS/eip-7612.md

View workflow job for this annotation

GitHub Actions / EIP Walidator

HTML comments are only allowed while `status` is one of: `Draft`, `Withdrawn`

warning[markdown-html-comments]: HTML comments are only allowed while `status` is one of: `Draft`, `Withdrawn` --> EIPS/eip-7612.md | 158 | <!-- | ::: EIPS/eip-7612.md | 173 | <!-- | = help: see https://ethereum.github.io/eipw/markdown-html-comments/
This section is optional for non-Core EIPs.

The Test Cases section should include expected input/output pairs, but may include a succinct set of executable tests. It should not include project build files. No new requirements may be be introduced here (meaning an implementation following only the Specification section should pass all tests here.)
Expand Down
Loading