-
Notifications
You must be signed in to change notification settings - Fork 202
feat: diff based L1 attributes transaction #13
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
Merged
Merged
Changes from 3 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,62 @@ | ||
| # Diff Based L1Attributes Transaction | ||
|
|
||
| <!-- START doctoc generated TOC please keep comment here to allow auto update --> | ||
| <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --> | ||
| **Table of Contents** | ||
|
|
||
| - [Implementation](#implementation) | ||
| - [Ecotone L1Attributes Example](#ecotone-l1attributes-example) | ||
| - [Node Implementation](#node-implementation) | ||
|
|
||
| <!-- END doctoc generated TOC please keep comment here to allow auto update --> | ||
|
|
||
| The `L1Attributes` transaction is the first transaction included in every L2 block. | ||
| It can be thought of as an extension to the L2 block header that is 100% backwards | ||
| compatible with L1 Ethereum by not changing the structure of the block header itself. | ||
| A major problem with the `L1Attributes` transaction is that it constantly submits the | ||
| same information over and over again. This adds chain history that must be preserved | ||
| forever. Ideally, the `L1Attributes` transaction only includes diffs to reduce the | ||
| growth of the chain history. | ||
|
|
||
| ## Implementation | ||
|
|
||
| The `L1Attributes` transaction already commits to a schema that is ABI encoded. | ||
| There is no concept of an `Optional` type in ABI encoding, so instead we can | ||
| utilize a custom data structure to indicate the presence of a field in the schema. | ||
| A leading bitfield can be used to use presence. Each bit indicates a specific item | ||
| in the schema where `1` means it is present and `0` means it is not present. Each | ||
| item MUST have at least a fixed size portion so that the decoder knows how far | ||
| forward to seek after a read when the item is present. | ||
|
|
||
| ### Ecotone L1Attributes Example | ||
|
|
||
| The following fields are required as part of the `L1Attributes` transaction after | ||
| the Ecotone network upgrade. | ||
|
|
||
| | Field | Size (bytes) | Bitfield Representation | | ||
| | ----------------- | ------------ | ------------------------ | | ||
| | baseFeeScalar | 4 | 0b1000\_0000\_0000\_0000 | | ||
| | blobBaseFeeScalar | 4 | 0b0100\_0000\_0000\_0000 | | ||
| | sequenceNumber | 8 | 0b0010\_0000\_0000\_0000 | | ||
| | l1BlockTimestamp | 8 | 0b0001\_0000\_0000\_0000 | | ||
| | l1BlockNumber | 8 | 0b0000\_1000\_0000\_0000 | | ||
| | basefee | 32 | 0b0000\_0100\_0000\_0000 | | ||
| | blobBaseFee | 32 | 0b0000\_0010\_0000\_0000 | | ||
| | l1BlockHash | 32 | 0b0000\_0001\_0000\_0000 | | ||
| | batcherHash | 32 | 0b0000\_0000\_1000\_0000 | | ||
|
|
||
| This is a total of 9 fields, so 9 bits are required to represent all of them. | ||
| It cannot fit into a single byte, so 2 bytes should be used to represent the bitfield. | ||
| Following the bitfield is the data tightly packed together. | ||
| When the value is set to `1` in the location that corresponds to the field, then | ||
| it indicates that the value is present and the the `size` number of bytes should | ||
| be read from the `calldata` and the offset of the next read from the calldata is | ||
| incremented by the `size`. If the value in the bitfield is a `0`, then the data | ||
| is not present and any reading/seeking is skipped. | ||
|
|
||
| ## Node Implementation | ||
|
|
||
| Previously, the node could read the calldata from the latest `L1Attributes` transaction | ||
| to be able to populate it's internal view of the `SystemConfig`. This will not be possible | ||
| with a diff based `L1Attributes` transaction implementation, but the problem can be solved | ||
| easily with a batch RPC call that reads each value directly from state using `eth_call`. | ||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.