Skip to content

Commit 17bf3e4

Browse files
author
colinlyguo
committed
feat: support codecv8
1 parent bfa7133 commit 17bf3e4

File tree

7 files changed

+315
-18
lines changed

7 files changed

+315
-18
lines changed

encoding/codecv7.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,15 @@ import (
1717
"github.com/scroll-tech/da-codec/encoding/zstd"
1818
)
1919

20-
type DACodecV7 struct{}
20+
type DACodecV7 struct {
21+
forcedVersion *CodecVersion
22+
}
2123

2224
// Version returns the codec version.
2325
func (d *DACodecV7) Version() CodecVersion {
26+
if d.forcedVersion != nil {
27+
return *d.forcedVersion
28+
}
2429
return CodecV7
2530
}
2631

@@ -86,7 +91,7 @@ func (d *DACodecV7) NewDABatch(batch *Batch) (DABatch, error) {
8691
return nil, fmt.Errorf("failed to construct blob: %w", err)
8792
}
8893

89-
daBatch, err := newDABatchV7(CodecV7, batch.Index, blobVersionedHash, batch.ParentBatchHash, blob, blobBytes, challengeDigest)
94+
daBatch, err := newDABatchV7(d.Version(), batch.Index, blobVersionedHash, batch.ParentBatchHash, blob, blobBytes, challengeDigest)
9095
if err != nil {
9196
return nil, fmt.Errorf("failed to construct DABatch: %w", err)
9297
}
@@ -115,7 +120,7 @@ func (d *DACodecV7) constructBlob(batch *Batch) (*kzg4844.Blob, common.Hash, []b
115120

116121
sizeSlice := encodeSize3Bytes(uint32(len(payloadBytes)))
117122

118-
blobBytes[blobEnvelopeV7OffsetVersion] = uint8(CodecV7)
123+
blobBytes[blobEnvelopeV7OffsetVersion] = uint8(d.Version())
119124
copy(blobBytes[blobEnvelopeV7OffsetByteSize:blobEnvelopeV7OffsetCompressedFlag], sizeSlice)
120125
blobBytes[blobEnvelopeV7OffsetCompressedFlag] = isCompressedFlag
121126
blobBytes = append(blobBytes, payloadBytes...)
@@ -166,15 +171,15 @@ func (d *DACodecV7) NewDABatchFromBytes(data []byte) (DABatch, error) {
166171
return nil, fmt.Errorf("failed to decode DA batch: %w", err)
167172
}
168173

169-
if daBatch.version != CodecV7 {
170-
return nil, fmt.Errorf("codec version mismatch: expected %d but found %d", CodecV7, daBatch.version)
174+
if daBatch.version != d.Version() {
175+
return nil, fmt.Errorf("codec version mismatch: expected %d but found %d", d.Version(), daBatch.version)
171176
}
172177

173178
return daBatch, nil
174179
}
175180

176181
func (d *DACodecV7) NewDABatchFromParams(batchIndex uint64, blobVersionedHash, parentBatchHash common.Hash) (DABatch, error) {
177-
return newDABatchV7(CodecV7, batchIndex, blobVersionedHash, parentBatchHash, nil, nil, common.Hash{})
182+
return newDABatchV7(d.Version(), batchIndex, blobVersionedHash, parentBatchHash, nil, nil, common.Hash{})
178183
}
179184

180185
func (d *DACodecV7) DecodeDAChunksRawTx(_ [][]byte) ([]*DAChunkRawTx, error) {
@@ -186,8 +191,8 @@ func (d *DACodecV7) DecodeBlob(blob *kzg4844.Blob) (DABlobPayload, error) {
186191

187192
// read the blob envelope header
188193
version := rawBytes[blobEnvelopeV7OffsetVersion]
189-
if CodecVersion(version) != CodecV7 {
190-
return nil, fmt.Errorf("codec version mismatch: expected %d but found %d", CodecV7, version)
194+
if CodecVersion(version) != d.Version() {
195+
return nil, fmt.Errorf("codec version mismatch: expected %d but found %d", d.Version(), version)
191196
}
192197

193198
// read the data size

encoding/codecv8.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package encoding
2+
3+
type DACodecV8 struct {
4+
DACodecV7
5+
}
6+
7+
func NewDACodecV8() *DACodecV8 {
8+
v := CodecV8
9+
return &DACodecV8{
10+
DACodecV7: DACodecV7{
11+
forcedVersion: &v,
12+
},
13+
}
14+
}

encoding/codecv8_test.go

Lines changed: 269 additions & 0 deletions
Large diffs are not rendered by default.

encoding/da.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ type Block struct {
110110
type Chunk struct {
111111
Blocks []*Block `json:"blocks"`
112112

113-
// CodecV7. Used for chunk creation in relayer.
113+
// CodecV7, CodecV8. Used for chunk creation in relayer.
114114
PrevL1MessageQueueHash common.Hash
115115
PostL1MessageQueueHash common.Hash
116116
}
@@ -122,7 +122,7 @@ type Batch struct {
122122
ParentBatchHash common.Hash
123123
Chunks []*Chunk
124124

125-
// CodecV7
125+
// CodecV7, CodecV8.
126126
PrevL1MessageQueueHash common.Hash
127127
PostL1MessageQueueHash common.Hash
128128
Blocks []*Block
@@ -766,8 +766,10 @@ func GetHardforkName(config *params.ChainConfig, blockHeight, blockTimestamp uin
766766
return "darwinV2"
767767
} else if !config.IsEuclidV2(blockTimestamp) {
768768
return "euclid"
769-
} else {
769+
} else if !config.IsFeynman(blockTimestamp) {
770770
return "euclidV2"
771+
} else {
772+
return "feynman"
771773
}
772774
}
773775

@@ -787,8 +789,10 @@ func GetCodecVersion(config *params.ChainConfig, blockHeight, blockTimestamp uin
787789
} else if !config.IsEuclidV2(blockTimestamp) {
788790
// V5 is skipped, because it is only used for the special Euclid transition batch that we handle explicitly
789791
return CodecV6
790-
} else {
792+
} else if !config.IsFeynman(blockTimestamp) {
791793
return CodecV7
794+
} else {
795+
return CodecV8
792796
}
793797
}
794798

@@ -817,7 +821,7 @@ func GetChunkEnableCompression(codecVersion CodecVersion, chunk *Chunk) (bool, e
817821
return false, nil
818822
case CodecV2, CodecV3:
819823
return true, nil
820-
case CodecV4, CodecV5, CodecV6, CodecV7:
824+
case CodecV4, CodecV5, CodecV6, CodecV7, CodecV8:
821825
return CheckChunkCompressedDataCompatibility(chunk, codecVersion)
822826
default:
823827
return false, fmt.Errorf("unsupported codec version: %v", codecVersion)
@@ -831,7 +835,7 @@ func GetBatchEnableCompression(codecVersion CodecVersion, batch *Batch) (bool, e
831835
return false, nil
832836
case CodecV2, CodecV3:
833837
return true, nil
834-
case CodecV4, CodecV5, CodecV6, CodecV7:
838+
case CodecV4, CodecV5, CodecV6, CodecV7, CodecV8:
835839
return CheckBatchCompressedDataCompatibility(batch, codecVersion)
836840
default:
837841
return false, fmt.Errorf("unsupported codec version: %v", codecVersion)

encoding/interfaces.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ const (
9090
CodecV5
9191
CodecV6
9292
CodecV7
93+
CodecV8
9394
)
9495

9596
// CodecFromVersion returns the appropriate codec for the given version.
@@ -111,14 +112,18 @@ func CodecFromVersion(version CodecVersion) (Codec, error) {
111112
return NewDACodecV6(), nil
112113
case CodecV7:
113114
return &DACodecV7{}, nil
115+
case CodecV8:
116+
return NewDACodecV8(), nil
114117
default:
115118
return nil, fmt.Errorf("unsupported codec version: %v", version)
116119
}
117120
}
118121

119122
// CodecFromConfig determines and returns the appropriate codec based on chain configuration, block number, and timestamp.
120123
func CodecFromConfig(chainCfg *params.ChainConfig, startBlockNumber *big.Int, startBlockTimestamp uint64) Codec {
121-
if chainCfg.IsEuclidV2(startBlockTimestamp) {
124+
if chainCfg.IsFeynman(startBlockTimestamp) {
125+
return NewDACodecV8()
126+
} else if chainCfg.IsEuclidV2(startBlockTimestamp) {
122127
return &DACodecV7{}
123128
} else if chainCfg.IsEuclid(startBlockTimestamp) {
124129
// V5 is skipped, because it is only used for the special Euclid transition batch that we handle explicitly

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.21
44

55
require (
66
github.com/agiledragon/gomonkey/v2 v2.12.0
7-
github.com/scroll-tech/go-ethereum v1.10.14-0.20250305151038-478940e79601
7+
github.com/scroll-tech/go-ethereum v1.10.14-0.20250611141528-cf3d22ef8707
88
github.com/stretchr/testify v1.9.0
99
)
1010

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis=
7878
github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
7979
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
8080
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
81-
github.com/scroll-tech/go-ethereum v1.10.14-0.20250305151038-478940e79601 h1:NEsjCG6uSvLRBlsP3+x6PL1kM+Ojs3g8UGotIPgJSz8=
82-
github.com/scroll-tech/go-ethereum v1.10.14-0.20250305151038-478940e79601/go.mod h1:OblWe1+QrZwdpwO0j/LY3BSGuKT3YPUFBDQQgvvfStQ=
81+
github.com/scroll-tech/go-ethereum v1.10.14-0.20250611141528-cf3d22ef8707 h1:rC6eEsAwSG1VzNT48fLM00rqwTGWPckiipmFC8D6D5o=
82+
github.com/scroll-tech/go-ethereum v1.10.14-0.20250611141528-cf3d22ef8707/go.mod h1:756YMENiSfx/5pCwKq3+uSTWjXuHTbiCB+TirJjsQT8=
8383
github.com/scroll-tech/zktrie v0.8.4 h1:UagmnZ4Z3ITCk+aUq9NQZJNAwnWl4gSxsLb2Nl7IgRE=
8484
github.com/scroll-tech/zktrie v0.8.4/go.mod h1:XvNo7vAk8yxNyTjBDj5WIiFzYW4bx/gJ78+NK6Zn6Uk=
8585
github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI=

0 commit comments

Comments
 (0)