diff --git a/encoding/codecv0.go b/encoding/codecv0.go index 5843e61..7e693db 100644 --- a/encoding/codecv0.go +++ b/encoding/codecv0.go @@ -190,7 +190,7 @@ func (d *DACodecV0) NewDABatch(batch *Batch) (DABatch, error) { l1MessagePopped := totalL1MessagePoppedAfter - batch.TotalL1MessagePoppedBefore daBatch := newDABatchV0( - uint8(CodecV0), // version + CodecV0, // version batch.Index, // batchIndex l1MessagePopped, // l1MessagePopped totalL1MessagePoppedAfter, // totalL1MessagePopped @@ -213,7 +213,7 @@ func (d *DACodecV0) NewDABatchFromBytes(data []byte) (DABatch, error) { } return newDABatchV0( - data[daBatchOffsetVersion], // version + CodecVersion(data[daBatchOffsetVersion]), // version binary.BigEndian.Uint64(data[daBatchOffsetBatchIndex:daBatchV0OffsetL1MessagePopped]), // batchIndex binary.BigEndian.Uint64(data[daBatchV0OffsetL1MessagePopped:daBatchV0OffsetTotalL1MessagePopped]), // l1MessagePopped binary.BigEndian.Uint64(data[daBatchV0OffsetTotalL1MessagePopped:daBatchOffsetDataHash]), // totalL1MessagePopped diff --git a/encoding/codecv0_test.go b/encoding/codecv0_test.go index aae0d34..a8e1bb5 100644 --- a/encoding/codecv0_test.go +++ b/encoding/codecv0_test.go @@ -195,7 +195,7 @@ func TestCodecV0BatchEncode(t *testing.T) { // empty batch batch := &daBatchV1{ daBatchV0: daBatchV0{ - version: uint8(CodecV0), + version: CodecV0, }, } encoded := hex.EncodeToString(batch.Encode()) @@ -271,7 +271,7 @@ func TestCodecV0BatchHash(t *testing.T) { // empty batch batch := &daBatchV1{ daBatchV0: daBatchV0{ - version: uint8(CodecV0), + version: CodecV0, }, } assert.Equal(t, common.HexToHash("0x7f74e58579672e582998264e7e8191c51b6b8981afd0f9bf1a2ffc3abb39e678"), batch.Hash()) diff --git a/encoding/codecv0_types.go b/encoding/codecv0_types.go index af7022a..e110268 100644 --- a/encoding/codecv0_types.go +++ b/encoding/codecv0_types.go @@ -213,7 +213,7 @@ func (c *daChunkV0) BlockRange() (uint64, uint64, error) { // daBatchV0 contains metadata about a batch of DAChunks. type daBatchV0 struct { - version uint8 + version CodecVersion batchIndex uint64 l1MessagePopped uint64 totalL1MessagePopped uint64 @@ -223,7 +223,7 @@ type daBatchV0 struct { } // newDABatchV0 is a constructor for daBatchV0. -func newDABatchV0(version uint8, batchIndex, l1MessagePopped, totalL1MessagePopped uint64, dataHash, parentBatchHash common.Hash, skippedL1MessageBitmap []byte) *daBatchV0 { +func newDABatchV0(version CodecVersion, batchIndex, l1MessagePopped, totalL1MessagePopped uint64, dataHash, parentBatchHash common.Hash, skippedL1MessageBitmap []byte) *daBatchV0 { return &daBatchV0{ version: version, batchIndex: batchIndex, @@ -238,7 +238,7 @@ func newDABatchV0(version uint8, batchIndex, l1MessagePopped, totalL1MessagePopp // Encode serializes the DABatchV0 into bytes. func (b *daBatchV0) Encode() []byte { batchBytes := make([]byte, daBatchV0EncodedMinLength+len(b.skippedL1MessageBitmap)) - batchBytes[daBatchOffsetVersion] = b.version + batchBytes[daBatchOffsetVersion] = byte(b.version) binary.BigEndian.PutUint64(batchBytes[daBatchOffsetBatchIndex:daBatchV0OffsetL1MessagePopped], b.batchIndex) binary.BigEndian.PutUint64(batchBytes[daBatchV0OffsetL1MessagePopped:daBatchV0OffsetTotalL1MessagePopped], b.l1MessagePopped) binary.BigEndian.PutUint64(batchBytes[daBatchV0OffsetTotalL1MessagePopped:daBatchOffsetDataHash], b.totalL1MessagePopped) @@ -271,7 +271,7 @@ func (b *daBatchV0) BlobDataProofForPointEvaluation() ([]byte, error) { // Version returns the version of the DABatch. func (b *daBatchV0) Version() CodecVersion { - return CodecVersion(b.version) + return b.version } // SkippedL1MessageBitmap returns the skipped L1 message bitmap of the DABatch. diff --git a/encoding/codecv1.go b/encoding/codecv1.go index 5c30253..cde947d 100644 --- a/encoding/codecv1.go +++ b/encoding/codecv1.go @@ -132,7 +132,7 @@ func (d *DACodecV1) NewDABatch(batch *Batch) (DABatch, error) { l1MessagePopped := totalL1MessagePoppedAfter - batch.TotalL1MessagePoppedBefore daBatch := newDABatchV1( - uint8(CodecV1), // version + CodecV1, // version batch.Index, // batchIndex l1MessagePopped, // l1MessagePopped totalL1MessagePoppedAfter, // totalL1MessagePopped @@ -250,7 +250,7 @@ func (d *DACodecV1) NewDABatchFromBytes(data []byte) (DABatch, error) { } return newDABatchV1( - data[daBatchOffsetVersion], // version + CodecVersion(data[daBatchOffsetVersion]), // version binary.BigEndian.Uint64(data[daBatchOffsetBatchIndex:daBatchV1OffsetL1MessagePopped]), // batchIndex binary.BigEndian.Uint64(data[daBatchV1OffsetL1MessagePopped:daBatchV1OffsetTotalL1MessagePopped]), // l1MessagePopped binary.BigEndian.Uint64(data[daBatchV1OffsetTotalL1MessagePopped:daBatchOffsetDataHash]), // totalL1MessagePopped diff --git a/encoding/codecv1_test.go b/encoding/codecv1_test.go index 8bb4015..8dcd007 100644 --- a/encoding/codecv1_test.go +++ b/encoding/codecv1_test.go @@ -243,7 +243,7 @@ func TestCodecV1BatchEncode(t *testing.T) { // empty batch batch := &daBatchV1{ daBatchV0: daBatchV0{ - version: uint8(CodecV1), + version: CodecV1, }, } encoded := hex.EncodeToString(batch.Encode()) @@ -319,7 +319,7 @@ func TestCodecV1BatchHash(t *testing.T) { // empty batch batch := &daBatchV1{ daBatchV0: daBatchV0{ - version: uint8(CodecV1), + version: CodecV1, }, } assert.Equal(t, common.HexToHash("0x4b6fe410f63051f6e93532087b42ece79fb7b966e2ba5845e6cd1c091f27e564"), batch.Hash()) @@ -973,7 +973,7 @@ func TestCodecV1BatchStandardTestCases(t *testing.T) { batch := daBatchV1{ daBatchV0: daBatchV0{ - version: uint8(CodecV3), + version: CodecV3, batchIndex: 6789, l1MessagePopped: 101, totalL1MessagePopped: 10101, diff --git a/encoding/codecv1_types.go b/encoding/codecv1_types.go index bde669b..c81f5f0 100644 --- a/encoding/codecv1_types.go +++ b/encoding/codecv1_types.go @@ -84,7 +84,7 @@ type daBatchV1 struct { } // newDABatchV1 is a constructor for daBatchV1. -func newDABatchV1(version uint8, batchIndex, l1MessagePopped, totalL1MessagePopped uint64, dataHash, parentBatchHash, blobVersionedHash common.Hash, skippedL1MessageBitmap []byte, blob *kzg4844.Blob, z *kzg4844.Point) *daBatchV1 { +func newDABatchV1(version CodecVersion, batchIndex, l1MessagePopped, totalL1MessagePopped uint64, dataHash, parentBatchHash, blobVersionedHash common.Hash, skippedL1MessageBitmap []byte, blob *kzg4844.Blob, z *kzg4844.Point) *daBatchV1 { return &daBatchV1{ daBatchV0: daBatchV0{ version: version, @@ -104,7 +104,7 @@ func newDABatchV1(version uint8, batchIndex, l1MessagePopped, totalL1MessagePopp // Encode serializes the DABatchV1 into bytes. func (b *daBatchV1) Encode() []byte { batchBytes := make([]byte, daBatchV1EncodedMinLength+len(b.skippedL1MessageBitmap)) - batchBytes[daBatchOffsetVersion] = b.version + batchBytes[daBatchOffsetVersion] = byte(b.version) binary.BigEndian.PutUint64(batchBytes[daBatchOffsetBatchIndex:daBatchV1OffsetL1MessagePopped], b.batchIndex) binary.BigEndian.PutUint64(batchBytes[daBatchV1OffsetL1MessagePopped:daBatchV1OffsetTotalL1MessagePopped], b.l1MessagePopped) binary.BigEndian.PutUint64(batchBytes[daBatchV1OffsetTotalL1MessagePopped:daBatchOffsetDataHash], b.totalL1MessagePopped) @@ -177,7 +177,7 @@ func (b *daBatchV1) BlobDataProofForPointEvaluation() ([]byte, error) { // Version returns the version of the DABatch. func (b *daBatchV1) Version() CodecVersion { - return CodecVersion(b.version) + return b.version } // SkippedL1MessageBitmap returns the skipped L1 message bitmap of the DABatch. diff --git a/encoding/codecv2.go b/encoding/codecv2.go index 534e2d9..ad33224 100644 --- a/encoding/codecv2.go +++ b/encoding/codecv2.go @@ -79,7 +79,7 @@ func (d *DACodecV2) NewDABatch(batch *Batch) (DABatch, error) { l1MessagePopped := totalL1MessagePoppedAfter - batch.TotalL1MessagePoppedBefore daBatch := newDABatchV1( - uint8(CodecV2), // version + CodecV2, // version batch.Index, // batchIndex l1MessagePopped, // l1MessagePopped totalL1MessagePoppedAfter, // totalL1MessagePopped @@ -217,7 +217,7 @@ func (d *DACodecV2) NewDABatchFromBytes(data []byte) (DABatch, error) { } return newDABatchV1( - data[daBatchOffsetVersion], // version + CodecVersion(data[daBatchOffsetVersion]), // version binary.BigEndian.Uint64(data[daBatchOffsetBatchIndex:daBatchV1OffsetL1MessagePopped]), // batchIndex binary.BigEndian.Uint64(data[daBatchV1OffsetL1MessagePopped:daBatchV1OffsetTotalL1MessagePopped]), // l1MessagePopped binary.BigEndian.Uint64(data[daBatchV1OffsetTotalL1MessagePopped:daBatchOffsetDataHash]), // totalL1MessagePopped diff --git a/encoding/codecv2_test.go b/encoding/codecv2_test.go index d7e6c2e..85fd7ba 100644 --- a/encoding/codecv2_test.go +++ b/encoding/codecv2_test.go @@ -243,7 +243,7 @@ func TestCodecV2BatchEncode(t *testing.T) { // empty batch batch := &daBatchV1{ daBatchV0: daBatchV0{ - version: uint8(CodecV2), + version: CodecV2, }, } encoded := hex.EncodeToString(batch.Encode()) @@ -319,7 +319,7 @@ func TestCodecV2BatchHash(t *testing.T) { // empty batch batch := &daBatchV1{ daBatchV0: daBatchV0{ - version: uint8(CodecV2), + version: CodecV2, }, } assert.Equal(t, common.HexToHash("0x8839b8a7b8dfebdc8e829f6fe543578ccdc8da1307e1e1581541a1e2a8fa5592"), batch.Hash()) @@ -1014,7 +1014,7 @@ func TestCodecV2BatchStandardTestCases(t *testing.T) { batch := daBatchV1{ daBatchV0: daBatchV0{ - version: uint8(CodecV2), + version: CodecV2, batchIndex: 6789, l1MessagePopped: 101, totalL1MessagePopped: 10101, diff --git a/encoding/codecv3.go b/encoding/codecv3.go index 6bb214e..ac37e89 100644 --- a/encoding/codecv3.go +++ b/encoding/codecv3.go @@ -61,7 +61,7 @@ func (d *DACodecV3) NewDABatch(batch *Batch) (DABatch, error) { l1MessagePopped := totalL1MessagePoppedAfter - batch.TotalL1MessagePoppedBefore return newDABatchV3( - uint8(CodecV3), // version + CodecV3, // version batch.Index, // batchIndex l1MessagePopped, // l1MessagePopped totalL1MessagePoppedAfter, // totalL1MessagePopped @@ -88,7 +88,7 @@ func (d *DACodecV3) NewDABatchFromBytes(data []byte) (DABatch, error) { } return newDABatchV3WithProof( - data[daBatchOffsetVersion], // version + CodecVersion(data[daBatchOffsetVersion]), // version binary.BigEndian.Uint64(data[daBatchOffsetBatchIndex:daBatchV3OffsetL1MessagePopped]), // batchIndex binary.BigEndian.Uint64(data[daBatchV3OffsetL1MessagePopped:daBatchV3OffsetTotalL1MessagePopped]), // l1MessagePopped binary.BigEndian.Uint64(data[daBatchV3OffsetTotalL1MessagePopped:daBatchOffsetDataHash]), // totalL1MessagePopped diff --git a/encoding/codecv3_test.go b/encoding/codecv3_test.go index c202f11..5e3e2e8 100644 --- a/encoding/codecv3_test.go +++ b/encoding/codecv3_test.go @@ -244,7 +244,7 @@ func TestCodecV3BatchEncode(t *testing.T) { // empty daBatch daBatchV3 := &daBatchV3{ daBatchV0: daBatchV0{ - version: uint8(CodecV3), + version: CodecV3, }, } encoded := hex.EncodeToString(daBatchV3.Encode()) @@ -320,7 +320,7 @@ func TestCodecV3BatchHash(t *testing.T) { // empty daBatch daBatchV3 := &daBatchV3{ daBatchV0: daBatchV0{ - version: uint8(CodecV3), + version: CodecV3, }, } assert.Equal(t, common.HexToHash("0x9f059299e02cd1ccaed5bbcc821843000ae6b992b68b55ff59a51252478681b0"), daBatchV3.Hash()) @@ -1155,7 +1155,7 @@ func TestCodecV3BatchStandardTestCases(t *testing.T) { batch := daBatchV3{ daBatchV0: daBatchV0{ - version: uint8(CodecV3), + version: CodecV3, batchIndex: 6789, l1MessagePopped: 101, totalL1MessagePopped: 10101, diff --git a/encoding/codecv3_types.go b/encoding/codecv3_types.go index bffd2e7..fd75046 100644 --- a/encoding/codecv3_types.go +++ b/encoding/codecv3_types.go @@ -25,7 +25,7 @@ type daBatchV3 struct { } // newDABatchV3 is a constructor for daBatchV3 that calls blobDataProofForPICircuit internally. -func newDABatchV3(version uint8, batchIndex, l1MessagePopped, totalL1MessagePopped, lastBlockTimestamp uint64, +func newDABatchV3(version CodecVersion, batchIndex, l1MessagePopped, totalL1MessagePopped, lastBlockTimestamp uint64, dataHash, parentBatchHash, blobVersionedHash common.Hash, skippedL1MessageBitmap []byte, blob *kzg4844.Blob, z *kzg4844.Point, blobBytes []byte, ) (*daBatchV3, error) { @@ -57,7 +57,7 @@ func newDABatchV3(version uint8, batchIndex, l1MessagePopped, totalL1MessagePopp } // newDABatchV3WithProof is a constructor for daBatchV3 that allows directly passing blobDataProof. -func newDABatchV3WithProof(version uint8, batchIndex, l1MessagePopped, totalL1MessagePopped, lastBlockTimestamp uint64, +func newDABatchV3WithProof(version CodecVersion, batchIndex, l1MessagePopped, totalL1MessagePopped, lastBlockTimestamp uint64, dataHash, parentBatchHash, blobVersionedHash common.Hash, skippedL1MessageBitmap []byte, blob *kzg4844.Blob, z *kzg4844.Point, blobBytes []byte, blobDataProof [2]common.Hash, ) *daBatchV3 { @@ -83,7 +83,7 @@ func newDABatchV3WithProof(version uint8, batchIndex, l1MessagePopped, totalL1Me // Encode serializes the DABatchV3 into bytes. func (b *daBatchV3) Encode() []byte { batchBytes := make([]byte, daBatchV3EncodedLength) - batchBytes[daBatchOffsetVersion] = b.version + batchBytes[daBatchOffsetVersion] = byte(b.version) binary.BigEndian.PutUint64(batchBytes[daBatchOffsetBatchIndex:daBatchV3OffsetL1MessagePopped], b.batchIndex) binary.BigEndian.PutUint64(batchBytes[daBatchV3OffsetL1MessagePopped:daBatchV3OffsetTotalL1MessagePopped], b.l1MessagePopped) binary.BigEndian.PutUint64(batchBytes[daBatchV3OffsetTotalL1MessagePopped:daBatchOffsetDataHash], b.totalL1MessagePopped) @@ -163,15 +163,15 @@ func (b *daBatchV3) BlobBytes() []byte { // This method is designed to provide prover with batch info in snake_case format. func (b *daBatchV3) MarshalJSON() ([]byte, error) { type daBatchV3JSON struct { - Version uint8 `json:"version"` - BatchIndex uint64 `json:"batch_index"` - L1MessagePopped uint64 `json:"l1_message_popped"` - TotalL1MessagePopped uint64 `json:"total_l1_message_popped"` - DataHash string `json:"data_hash"` - ParentBatchHash string `json:"parent_batch_hash"` - BlobVersionedHash string `json:"blob_versioned_hash"` - LastBlockTimestamp uint64 `json:"last_block_timestamp"` - BlobDataProof [2]string `json:"blob_data_proof"` + Version CodecVersion `json:"version"` + BatchIndex uint64 `json:"batch_index"` + L1MessagePopped uint64 `json:"l1_message_popped"` + TotalL1MessagePopped uint64 `json:"total_l1_message_popped"` + DataHash string `json:"data_hash"` + ParentBatchHash string `json:"parent_batch_hash"` + BlobVersionedHash string `json:"blob_versioned_hash"` + LastBlockTimestamp uint64 `json:"last_block_timestamp"` + BlobDataProof [2]string `json:"blob_data_proof"` } return json.Marshal(&daBatchV3JSON{ @@ -192,7 +192,7 @@ func (b *daBatchV3) MarshalJSON() ([]byte, error) { // Version returns the version of the DABatch. func (b *daBatchV3) Version() CodecVersion { - return CodecVersion(b.version) + return b.version } // SkippedL1MessageBitmap returns the skipped L1 message bitmap of the DABatch. diff --git a/encoding/codecv4.go b/encoding/codecv4.go index 367c86e..d9eb6cc 100644 --- a/encoding/codecv4.go +++ b/encoding/codecv4.go @@ -89,7 +89,7 @@ func (d *DACodecV4) NewDABatch(batch *Batch) (DABatch, error) { l1MessagePopped := totalL1MessagePoppedAfter - batch.TotalL1MessagePoppedBefore return newDABatchV3( - uint8(CodecV4), // version + CodecV4, // version batch.Index, // batchIndex l1MessagePopped, // l1MessagePopped totalL1MessagePoppedAfter, // totalL1MessagePopped @@ -116,7 +116,7 @@ func (d *DACodecV4) NewDABatchFromBytes(data []byte) (DABatch, error) { } return newDABatchV3WithProof( - data[daBatchOffsetVersion], // version + CodecVersion(data[daBatchOffsetVersion]), // version binary.BigEndian.Uint64(data[daBatchOffsetBatchIndex:daBatchV3OffsetL1MessagePopped]), // batchIndex binary.BigEndian.Uint64(data[daBatchV3OffsetL1MessagePopped:daBatchV3OffsetTotalL1MessagePopped]), // l1MessagePopped binary.BigEndian.Uint64(data[daBatchV3OffsetTotalL1MessagePopped:daBatchOffsetDataHash]), // totalL1MessagePopped diff --git a/encoding/codecv4_test.go b/encoding/codecv4_test.go index 376d157..92e183a 100644 --- a/encoding/codecv4_test.go +++ b/encoding/codecv4_test.go @@ -244,7 +244,7 @@ func TestCodecV4BatchEncode(t *testing.T) { // empty daBatch daBatchV3 := &daBatchV3{ daBatchV0: daBatchV0{ - version: uint8(CodecV4), + version: CodecV4, }, } encoded := hex.EncodeToString(daBatchV3.Encode()) @@ -320,7 +320,7 @@ func TestCodecV4BatchHash(t *testing.T) { // empty daBatch daBatchV3 := &daBatchV3{ daBatchV0: daBatchV0{ - version: uint8(CodecV4), + version: CodecV4, }, } assert.Equal(t, common.HexToHash("0xdaf0827d02b32d41458aea0d5796dd0072d0a016f9834a2cb1a964d2c6ee135c"), daBatchV3.Hash()) @@ -1155,7 +1155,7 @@ func TestCodecV4BatchStandardTestCasesEnableCompression(t *testing.T) { batch := daBatchV3{ daBatchV0: daBatchV0{ - version: uint8(CodecV4), + version: CodecV4, batchIndex: 6789, l1MessagePopped: 101, totalL1MessagePopped: 10101, @@ -1303,7 +1303,7 @@ func TestCodecV4BatchStandardTestCasesDisableCompression(t *testing.T) { batch := daBatchV3{ daBatchV0: daBatchV0{ - version: uint8(CodecV4), + version: CodecV4, batchIndex: 6789, l1MessagePopped: 101, totalL1MessagePopped: 10101, diff --git a/encoding/interfaces.go b/encoding/interfaces.go index 3f7ef6e..683057a 100644 --- a/encoding/interfaces.go +++ b/encoding/interfaces.go @@ -65,7 +65,7 @@ type Codec interface { } // CodecVersion represents the version of the codec. -type CodecVersion int +type CodecVersion uint8 const ( CodecV0 CodecVersion = iota