Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
21 changes: 13 additions & 8 deletions encoding/codecv7.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,15 @@ import (
"github.com/scroll-tech/da-codec/encoding/zstd"
)

type DACodecV7 struct{}
type DACodecV7 struct {
forcedVersion *CodecVersion
}

// Version returns the codec version.
func (d *DACodecV7) Version() CodecVersion {
if d.forcedVersion != nil {
return *d.forcedVersion
}
return CodecV7
}

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

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

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

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

if daBatch.version != CodecV7 {
return nil, fmt.Errorf("codec version mismatch: expected %d but found %d", CodecV7, daBatch.version)
if daBatch.version != d.Version() {
return nil, fmt.Errorf("codec version mismatch: expected %d but found %d", d.Version(), daBatch.version)
}

return daBatch, nil
}

func (d *DACodecV7) NewDABatchFromParams(batchIndex uint64, blobVersionedHash, parentBatchHash common.Hash) (DABatch, error) {
return newDABatchV7(CodecV7, batchIndex, blobVersionedHash, parentBatchHash, nil, nil, common.Hash{})
return newDABatchV7(d.Version(), batchIndex, blobVersionedHash, parentBatchHash, nil, nil, common.Hash{})
}

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

// read the blob envelope header
version := rawBytes[blobEnvelopeV7OffsetVersion]
if CodecVersion(version) != CodecV7 {
return nil, fmt.Errorf("codec version mismatch: expected %d but found %d", CodecV7, version)
if CodecVersion(version) != d.Version() {
return nil, fmt.Errorf("codec version mismatch: expected %d but found %d", d.Version(), version)
}

// read the data size
Expand Down
14 changes: 14 additions & 0 deletions encoding/codecv8.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package encoding

type DACodecV8 struct {
DACodecV7
}

func NewDACodecV8() *DACodecV8 {
v := CodecV8
return &DACodecV8{
DACodecV7: DACodecV7{
forcedVersion: &v,
},
}
}
269 changes: 269 additions & 0 deletions encoding/codecv8_test.go

Large diffs are not rendered by default.

16 changes: 10 additions & 6 deletions encoding/da.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ type Block struct {
type Chunk struct {
Blocks []*Block `json:"blocks"`

// CodecV7. Used for chunk creation in relayer.
// CodecV7, CodecV8. Used for chunk creation in relayer.
PrevL1MessageQueueHash common.Hash
PostL1MessageQueueHash common.Hash
}
Expand All @@ -122,7 +122,7 @@ type Batch struct {
ParentBatchHash common.Hash
Chunks []*Chunk

// CodecV7
// CodecV7, CodecV8.
PrevL1MessageQueueHash common.Hash
PostL1MessageQueueHash common.Hash
Blocks []*Block
Expand Down Expand Up @@ -766,8 +766,10 @@ func GetHardforkName(config *params.ChainConfig, blockHeight, blockTimestamp uin
return "darwinV2"
} else if !config.IsEuclidV2(blockTimestamp) {
return "euclid"
} else {
} else if !config.IsFeynman(blockTimestamp) {
return "euclidV2"
} else {
return "feynman"
}
}

Expand All @@ -787,8 +789,10 @@ func GetCodecVersion(config *params.ChainConfig, blockHeight, blockTimestamp uin
} else if !config.IsEuclidV2(blockTimestamp) {
// V5 is skipped, because it is only used for the special Euclid transition batch that we handle explicitly
return CodecV6
} else {
} else if !config.IsFeynman(blockTimestamp) {
return CodecV7
} else {
return CodecV8
}
}

Expand Down Expand Up @@ -817,7 +821,7 @@ func GetChunkEnableCompression(codecVersion CodecVersion, chunk *Chunk) (bool, e
return false, nil
case CodecV2, CodecV3:
return true, nil
case CodecV4, CodecV5, CodecV6, CodecV7:
case CodecV4, CodecV5, CodecV6, CodecV7, CodecV8:
return CheckChunkCompressedDataCompatibility(chunk, codecVersion)
default:
return false, fmt.Errorf("unsupported codec version: %v", codecVersion)
Expand All @@ -831,7 +835,7 @@ func GetBatchEnableCompression(codecVersion CodecVersion, batch *Batch) (bool, e
return false, nil
case CodecV2, CodecV3:
return true, nil
case CodecV4, CodecV5, CodecV6, CodecV7:
case CodecV4, CodecV5, CodecV6, CodecV7, CodecV8:
return CheckBatchCompressedDataCompatibility(batch, codecVersion)
default:
return false, fmt.Errorf("unsupported codec version: %v", codecVersion)
Expand Down
7 changes: 6 additions & 1 deletion encoding/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ const (
CodecV5
CodecV6
CodecV7
CodecV8
)

// CodecFromVersion returns the appropriate codec for the given version.
Expand All @@ -111,14 +112,18 @@ func CodecFromVersion(version CodecVersion) (Codec, error) {
return NewDACodecV6(), nil
case CodecV7:
return &DACodecV7{}, nil
case CodecV8:
return NewDACodecV8(), nil
default:
return nil, fmt.Errorf("unsupported codec version: %v", version)
}
}

// CodecFromConfig determines and returns the appropriate codec based on chain configuration, block number, and timestamp.
func CodecFromConfig(chainCfg *params.ChainConfig, startBlockNumber *big.Int, startBlockTimestamp uint64) Codec {
if chainCfg.IsEuclidV2(startBlockTimestamp) {
if chainCfg.IsFeynman(startBlockTimestamp) {
return NewDACodecV8()
} else if chainCfg.IsEuclidV2(startBlockTimestamp) {
return &DACodecV7{}
} else if chainCfg.IsEuclid(startBlockTimestamp) {
// V5 is skipped, because it is only used for the special Euclid transition batch that we handle explicitly
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.21

require (
github.com/agiledragon/gomonkey/v2 v2.12.0
github.com/scroll-tech/go-ethereum v1.10.14-0.20250305151038-478940e79601
github.com/scroll-tech/go-ethereum v1.10.14-0.20250611141528-cf3d22ef8707
github.com/stretchr/testify v1.9.0
)

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