Repository navigation
update rollup layer validium #1822
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
Open
georgehao
wants to merge
2
commits into
develop
Choose a base branch
from
feat/rollup_layer_validium
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
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,77 @@ | ||
| package utils | ||
|
|
||
| import ( | ||
| "math/big" | ||
| "testing" | ||
|
|
||
| "github.com/scroll-tech/da-codec/encoding" | ||
| "github.com/scroll-tech/go-ethereum/common" | ||
| gethTypes "github.com/scroll-tech/go-ethereum/core/types" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func genesisBatch() *encoding.Batch { | ||
| genesis := &gethTypes.Header{ | ||
| Number: big.NewInt(0), | ||
| Difficulty: big.NewInt(1), | ||
| GasLimit: 10000000, | ||
| Root: common.HexToHash("0x1a4a1e5e4f9f12a88d4d38163e9ea4b7b0b52e23d72f09b56f1d49d6ad21e63a"), | ||
| } | ||
| chunk := &encoding.Chunk{Blocks: []*encoding.Block{{Header: genesis}}} | ||
| return &encoding.Batch{ | ||
| Index: 0, | ||
| TotalL1MessagePoppedBefore: 0, | ||
| ParentBatchHash: common.Hash{}, | ||
| Chunks: []*encoding.Chunk{chunk}, | ||
| Blocks: chunk.Blocks, | ||
| } | ||
| } | ||
|
|
||
| func TestGetBatchMetadataGenesisBatch(t *testing.T) { | ||
| // The genesis batch always uses the rollup encoding, in rollup mode and in validium mode | ||
| // alike: a validium chain is a rollup chain migrated to ScrollChainValidiumV2 at some batch | ||
| // height, so committedBatches[0] inherited from the rollup is the rollup genesis batch hash. | ||
| meta, err := GetBatchMetadata(genesisBatch(), encoding.CodecV0, false) | ||
| require.NoError(t, err) | ||
|
|
||
| // The rollup CodecV0 batch header is 89 bytes: | ||
| // version (1) + batchIndex (8) + l1MessagePopped (8) + totalL1MessagePopped (8) + | ||
| // dataHash (32) + parentBatchHash (32). | ||
| assert.Len(t, meta.BatchBytes, 89) | ||
| assert.NotEqual(t, common.Hash{}, meta.BatchHash) | ||
|
|
||
| // The genesis batch can no longer be encoded as a validium batch header: the validium | ||
| // contract removes importGenesisBatch, so a validium-encoded genesis would never match | ||
| // the on-chain genesis batch hash. | ||
| _, err = GetBatchMetadata(genesisBatch(), encoding.CodecV0, true) | ||
| assert.Error(t, err) | ||
| } | ||
|
|
||
| func TestGetBatchMetadataValidiumHeader(t *testing.T) { | ||
| // A validium batch header is 137 bytes: | ||
| // version (1) + batchIndex (8) + parentBatchHash (32) + postStateRoot (32) + | ||
| // withdrawRoot (32) + commitment (32), matching BatchHeaderValidiumV0Codec with a | ||
| // 32-byte commitment. | ||
| header := &gethTypes.Header{ | ||
| Number: big.NewInt(1), | ||
| Difficulty: big.NewInt(1), | ||
| GasLimit: 10000000, | ||
| Root: common.HexToHash("0x2b5b2f6f5fa023b99e5e49274f0fb5c8c1c63f34e83f0ac67f2e5ae7be32f74b"), | ||
| } | ||
| chunk := &encoding.Chunk{Blocks: []*encoding.Block{{Header: header}}} | ||
| batch := &encoding.Batch{ | ||
| Index: 1, | ||
| ParentBatchHash: common.HexToHash("0x010203"), | ||
| Chunks: []*encoding.Chunk{chunk}, | ||
| Blocks: chunk.Blocks, | ||
| } | ||
|
|
||
| meta, err := GetBatchMetadata(batch, encoding.CodecV10, true) | ||
| require.NoError(t, err) | ||
| assert.Len(t, meta.BatchBytes, 137) | ||
|
|
||
| // version 1, big-endian batch index 1 | ||
| assert.Equal(t, uint8(1), meta.BatchBytes[0]) | ||
| assert.Equal(t, batch.ParentBatchHash.Bytes(), meta.BatchBytes[9:41]) | ||
| } |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift
🔎 Supported by static analysis
🏁 Script executed:
Repository: scroll-tech/scroll
Length of output: 41456
🏁 Script executed:
Repository: scroll-tech/scroll
Length of output: 42022
🏁 Script executed:
Repository: scroll-tech/scroll
Length of output: 34383
Reject a mismatched inherited genesis before finalizing it locally.
When the database is empty,
initializeGenesisbuilds the batch from the L2 block-0 header, marks itRollupFinalized, and returns in validium mode without reading L1. ComparedbBatch.HashwithcommittedBatches(0)anddbBatch.StateRootwithstateRoots(0). Abort before updating the local status if either value differs.Later validium submissions use the stored parent hash in
r.validiumABI.Pack("commitBatch", ...), so an unverified local genesis can produce a parent hash that does not match L1.🤖 Prompt for AI Agents