Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
colinlyguo committed Oct 18, 2024
1 parent ef5f1a6 commit 3faa778
Show file tree
Hide file tree
Showing 14 changed files with 46 additions and 46 deletions.
4 changes: 2 additions & 2 deletions encoding/codecv0.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions encoding/codecv0_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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())
Expand Down
8 changes: 4 additions & 4 deletions encoding/codecv0_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions encoding/codecv1.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions encoding/codecv1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -973,7 +973,7 @@ func TestCodecV1BatchStandardTestCases(t *testing.T) {

batch := daBatchV1{
daBatchV0: daBatchV0{
version: uint8(CodecV3),
version: CodecV3,
batchIndex: 6789,
l1MessagePopped: 101,
totalL1MessagePopped: 10101,
Expand Down
6 changes: 3 additions & 3 deletions encoding/codecv1_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions encoding/codecv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions encoding/codecv2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -1014,7 +1014,7 @@ func TestCodecV2BatchStandardTestCases(t *testing.T) {

batch := daBatchV1{
daBatchV0: daBatchV0{
version: uint8(CodecV2),
version: CodecV2,
batchIndex: 6789,
l1MessagePopped: 101,
totalL1MessagePopped: 10101,
Expand Down
4 changes: 2 additions & 2 deletions encoding/codecv3.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions encoding/codecv3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -1155,7 +1155,7 @@ func TestCodecV3BatchStandardTestCases(t *testing.T) {

batch := daBatchV3{
daBatchV0: daBatchV0{
version: uint8(CodecV3),
version: CodecV3,
batchIndex: 6789,
l1MessagePopped: 101,
totalL1MessagePopped: 10101,
Expand Down
26 changes: 13 additions & 13 deletions encoding/codecv3_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Expand Down Expand Up @@ -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{
Expand All @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions encoding/codecv4.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions encoding/codecv4_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -1155,7 +1155,7 @@ func TestCodecV4BatchStandardTestCasesEnableCompression(t *testing.T) {

batch := daBatchV3{
daBatchV0: daBatchV0{
version: uint8(CodecV4),
version: CodecV4,
batchIndex: 6789,
l1MessagePopped: 101,
totalL1MessagePopped: 10101,
Expand Down Expand Up @@ -1303,7 +1303,7 @@ func TestCodecV4BatchStandardTestCasesDisableCompression(t *testing.T) {

batch := daBatchV3{
daBatchV0: daBatchV0{
version: uint8(CodecV4),
version: CodecV4,
batchIndex: 6789,
l1MessagePopped: 101,
totalL1MessagePopped: 10101,
Expand Down
2 changes: 1 addition & 1 deletion encoding/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ type Codec interface {
}

// CodecVersion represents the version of the codec.
type CodecVersion int
type CodecVersion uint8

const (
CodecV0 CodecVersion = iota
Expand Down

0 comments on commit 3faa778

Please sign in to comment.