-
Notifications
You must be signed in to change notification settings - Fork 22
feat(CodecV7): add CodecV7 to support upgrade 5.2 Euclid phase2 #33
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 1 commit
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
286f209
add initial CodecV6 and daBatchV6
jonastheis 6767845
feat: add codecv5 and codecv6 for Euclid fork
omerfirmak cc9561b
implement blob encoding and decoding according to new blob layout
jonastheis 8c2a5cc
rename to CodecV7
jonastheis 9117170
add NewDABatchFromParams
jonastheis 4ef7bfc
add DecodeBlob to Codec
jonastheis bf16156
Update da.go
omerfirmak 2817674
Update interfaces.go
omerfirmak 7a60b34
Merge remote-tracking branch 'origin/omerfirmak/euclid' into feat/cod…
jonastheis 64133ef
fixes after merge
jonastheis 1dde89a
address review comments
jonastheis c9c1a44
add sanity checks for blob payload generation
jonastheis e980b3d
fix few small bugs uncovered by unit tests
jonastheis 0e930c6
upgrade to latest l2geth version and add correct getter for CodecV7 i…
jonastheis 5d200f3
fix linter warnings
jonastheis 5292e3c
add unit tests
jonastheis 3cfed43
go mod tidy
jonastheis eed341f
fix linter warnings
jonastheis be6b422
add function MessageQueueV2ApplyL1MessagesFromBlocks to compute the L…
jonastheis d77916b
fix lint and unit test errors
b71c047
call checkCompressedDataCompatibility only once -> constructBlobPaylo…
jonastheis cbed8b2
address review comments
jonastheis 392b6ff
update BlobEnvelopeV7 documentation
jonastheis edaf5d2
add CodecV7 to general util functions
jonastheis 894a93b
add InitialL1MessageQueueHash and LastL1MessageQueueHash to encoding.…
jonastheis f3271d9
Merge remote-tracking branch 'origin/main' into feat/codec-v6
jonastheis 2611ae1
go mod tidy
jonastheis 4d46aad
upgrade go-ethereum dependency to latest develop
jonastheis f4b274c
implement estimate functions
jonastheis 3c106a2
update TestMain and run go mod tidy
Thegaram 538036b
add NewDAChunk to CodecV7 for easier use in relayer
jonastheis 14d07e7
Merge branch 'feat/codec-v6' of github.com:scroll-tech/da-codec into …
jonastheis cfb316b
add daChunkV7 type to calculate chunk hash
jonastheis c6ae41e
allow batch.chunks but check consistency with batch.blocks
jonastheis d028c53
fix off-by-one error with L1 messages
jonastheis 8fa5e27
Fix: rolling hash implementation (#42)
roynalnaruto 4f13363
Apply suggestions from code review
jonastheis bcad556
rename initialL1MessageQueueHash -> prevL1MessageQueueHash and lastL1…
jonastheis 7522931
address review comments
jonastheis 32f5b49
address review comments
jonastheis 0247443
add challenge digest computation for batch
jonastheis 2043787
remove InitialL1MessageIndex from CodecV7
jonastheis de09af4
address review comments
jonastheis f9608ed
fix tests
jonastheis 01bd9b5
refactoring to minimize duplicate code and increase maintainability
jonastheis fca406c
fix nil pointer
jonastheis 5fd8356
address review comments
jonastheis 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,77 @@ | ||
| package encoding | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "fmt" | ||
|
|
||
| "github.com/scroll-tech/go-ethereum/crypto/kzg4844" | ||
| ) | ||
|
|
||
| type DACodecV6 struct { | ||
| DACodecV4 | ||
| } | ||
|
|
||
| // Version returns the codec version. | ||
| func (d *DACodecV6) Version() CodecVersion { | ||
| return CodecV6 | ||
| } | ||
|
|
||
| // MaxNumChunksPerBatch returns the maximum number of chunks per batch. | ||
| func (d *DACodecV6) MaxNumChunksPerBatch() int { | ||
| return 1 | ||
Thegaram marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| // NewDAChunk creates a new DAChunk from the given Chunk and the total number of L1 messages popped before. | ||
| // Note: For DACodecV6, this function is not implemented since there is no notion of DAChunk in this version. Blobs | ||
| // contain the entire batch data, and it is up to a prover to decide the chunk sizes. | ||
| func (d *DACodecV6) NewDAChunk(_ *Chunk, _ uint64) (DAChunk, error) { | ||
| return nil, nil | ||
| } | ||
|
|
||
| // NewDABatch creates a DABatch including blob from the provided Batch. | ||
| func (d *DACodecV6) NewDABatch(batch *Batch) (DABatch, error) { | ||
| // TODO: create DABatch from the provided batch once the blob layout is defined. See DACodecV4 for reference. | ||
| return nil, nil | ||
| } | ||
|
|
||
| // NewDABatchFromBytes decodes the given byte slice into a DABatch. | ||
| // Note: This function only populates the batch header, it leaves the blob-related fields and skipped L1 message bitmap empty. | ||
| func (d *DACodecV6) NewDABatchFromBytes(data []byte) (DABatch, error) { | ||
| daBatch, err := decodeDABatchV6(data) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to decode DA batch: %w", err) | ||
| } | ||
|
|
||
| if daBatch.version != CodecV6 { | ||
| return nil, fmt.Errorf("codec version mismatch: expected %d but found %d", CodecV6, daBatch.version) | ||
| } | ||
|
|
||
| return daBatch, nil | ||
| } | ||
|
|
||
| func (d *DACodecV6) DecodeDAChunksRawTx(chunkBytes [][]byte) ([]*DAChunkRawTx, error) { | ||
| return nil, nil | ||
| } | ||
|
|
||
| func (d *DACodecV6) DecodeTxsFromBlob(blob *kzg4844.Blob, chunks []*DAChunkRawTx) error { | ||
| return nil | ||
| } | ||
|
|
||
| // TODO: add DecodeBlob to interface to decode the blob and transactions or reuse DecodeTxsFromBlob but only have a single "chunk" for all transactions in the batch? | ||
|
|
||
| // TODO: which of the Estimate* functions are needed? | ||
colinlyguo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // JSONFromBytes converts the bytes to a DABatch and then marshals it to JSON. | ||
| func (d *DACodecV6) JSONFromBytes(data []byte) ([]byte, error) { | ||
| batch, err := d.NewDABatchFromBytes(data) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to decode DABatch from bytes: %w", err) | ||
| } | ||
|
|
||
| jsonBytes, err := json.Marshal(batch) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to marshal DABatch to JSON, version %d, hash %s: %w", batch.Version(), batch.Hash(), err) | ||
| } | ||
|
|
||
| return jsonBytes, nil | ||
| } | ||
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,135 @@ | ||
| package encoding | ||
|
|
||
| import ( | ||
| "encoding/binary" | ||
| "encoding/hex" | ||
| "encoding/json" | ||
| "errors" | ||
| "fmt" | ||
|
|
||
| "github.com/scroll-tech/go-ethereum/common" | ||
| "github.com/scroll-tech/go-ethereum/crypto" | ||
| "github.com/scroll-tech/go-ethereum/crypto/kzg4844" | ||
| ) | ||
|
|
||
| // daBatchV3 contains metadata about a batch of DAChunks. | ||
| type daBatchV6 struct { | ||
| version CodecVersion | ||
| batchIndex uint64 | ||
| parentBatchHash common.Hash | ||
| blobVersionedHash common.Hash | ||
|
|
||
| blob *kzg4844.Blob | ||
| z *kzg4844.Point | ||
| blobBytes []byte | ||
| } | ||
|
|
||
| // newDABatchV6 is a constructor for daBatchV6 that calls blobDataProofForPICircuit internally. | ||
| func newDABatchV6(version CodecVersion, batchIndex uint64, parentBatchHash, blobVersionedHash common.Hash, blob *kzg4844.Blob, z *kzg4844.Point, blobBytes []byte) (*daBatchV6, error) { | ||
| daBatch := &daBatchV6{ | ||
| version: version, | ||
| batchIndex: batchIndex, | ||
| parentBatchHash: parentBatchHash, | ||
| blobVersionedHash: blobVersionedHash, | ||
| blob: blob, | ||
| z: z, | ||
Thegaram marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| blobBytes: blobBytes, | ||
| } | ||
|
|
||
| return daBatch, nil | ||
| } | ||
|
|
||
| func decodeDABatchV6(data []byte) (*daBatchV6, error) { | ||
| if len(data) != daBatchV6EncodedLength { | ||
| return nil, fmt.Errorf("invalid data length for DABatchV6, expected %d bytes but got %d", daBatchV6EncodedLength, len(data)) | ||
| } | ||
|
|
||
| version := CodecVersion(data[daBatchOffsetVersion]) | ||
| batchIndex := binary.BigEndian.Uint64(data[daBatchOffsetBatchIndex:daBatchV6OffsetBlobVersionedHash]) | ||
| blobVersionedHash := common.BytesToHash(data[daBatchV6OffsetBlobVersionedHash:daBatchV6OffsetParentBatchHash]) | ||
| parentBatchHash := common.BytesToHash(data[daBatchV6OffsetParentBatchHash:daBatchV6EncodedLength]) | ||
|
|
||
| return newDABatchV6(version, batchIndex, parentBatchHash, blobVersionedHash, nil, nil, nil) | ||
| } | ||
|
|
||
| // Encode serializes the DABatchV3 into bytes. | ||
| func (b *daBatchV6) Encode() []byte { | ||
| batchBytes := make([]byte, daBatchV6EncodedLength) | ||
| batchBytes[daBatchOffsetVersion] = byte(b.version) | ||
| binary.BigEndian.PutUint64(batchBytes[daBatchOffsetBatchIndex:daBatchV6OffsetBlobVersionedHash], b.batchIndex) | ||
| copy(batchBytes[daBatchV6OffsetBlobVersionedHash:daBatchV6OffsetParentBatchHash], b.blobVersionedHash[:]) | ||
| copy(batchBytes[daBatchV6OffsetParentBatchHash:daBatchV6EncodedLength], b.parentBatchHash[:]) | ||
| return batchBytes | ||
| } | ||
|
|
||
| // Hash computes the hash of the serialized DABatch. | ||
| func (b *daBatchV6) Hash() common.Hash { | ||
| return crypto.Keccak256Hash(b.Encode()) | ||
| } | ||
|
|
||
| // BlobDataProofForPointEvaluation computes the abi-encoded blob verification data. | ||
| func (b *daBatchV6) BlobDataProofForPointEvaluation() ([]byte, error) { | ||
Thegaram marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if b.blob == nil { | ||
| return nil, errors.New("called BlobDataProofForPointEvaluation with empty blob") | ||
| } | ||
| if b.z == nil { | ||
| return nil, errors.New("called BlobDataProofForPointEvaluation with empty z") | ||
| } | ||
|
|
||
| commitment, err := kzg4844.BlobToCommitment(b.blob) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to create blob commitment: %w", err) | ||
| } | ||
|
|
||
| proof, y, err := kzg4844.ComputeProof(b.blob, *b.z) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to create KZG proof at point, err: %w, z: %v", err, hex.EncodeToString(b.z[:])) | ||
| } | ||
|
|
||
| return blobDataProofFromValues(*b.z, y, commitment, proof), nil | ||
| } | ||
|
|
||
| // Blob returns the blob of the batch. | ||
| func (b *daBatchV6) Blob() *kzg4844.Blob { | ||
| return b.blob | ||
| } | ||
|
|
||
| // BlobBytes returns the blob bytes of the batch. | ||
| func (b *daBatchV6) BlobBytes() []byte { | ||
| return b.blobBytes | ||
| } | ||
|
|
||
| // MarshalJSON implements the custom JSON serialization for daBatchV3. | ||
| // This method is designed to provide prover with batch info in snake_case format. | ||
| func (b *daBatchV6) MarshalJSON() ([]byte, error) { | ||
| type daBatchV6JSON struct { | ||
| Version CodecVersion `json:"version"` | ||
| BatchIndex uint64 `json:"batch_index"` | ||
| BlobVersionedHash string `json:"blob_versioned_hash"` | ||
| ParentBatchHash string `json:"parent_batch_hash"` | ||
| } | ||
|
|
||
| return json.Marshal(&daBatchV6JSON{ | ||
| Version: b.version, | ||
| BatchIndex: b.batchIndex, | ||
| BlobVersionedHash: b.blobVersionedHash.Hex(), | ||
| ParentBatchHash: b.parentBatchHash.Hex(), | ||
| }) | ||
| } | ||
|
|
||
| // Version returns the version of the DABatch. | ||
| func (b *daBatchV6) Version() CodecVersion { | ||
| return b.version | ||
| } | ||
|
|
||
| // SkippedL1MessageBitmap returns the skipped L1 message bitmap of the DABatch. | ||
| // For daBatchV6, there is no skipped L1 message bitmap. | ||
| func (b *daBatchV6) SkippedL1MessageBitmap() []byte { | ||
Thegaram marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return nil | ||
| } | ||
|
|
||
| // DataHash returns the data hash of the DABatch. | ||
| // For daBatchV6, there is no data hash. | ||
| func (b *daBatchV6) DataHash() common.Hash { | ||
| return common.Hash{} | ||
| } | ||
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
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.