Skip to content

Commit

Permalink
rename daBatchV2 to daBatchV3
Browse files Browse the repository at this point in the history
  • Loading branch information
colinlyguo committed Oct 16, 2024
1 parent 3e092dd commit 558d029
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 28 deletions.
6 changes: 3 additions & 3 deletions encoding/codecv3.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (d *DACodecV3) NewDABatch(batch *Batch) (DABatch, error) {
lastChunk := batch.Chunks[len(batch.Chunks)-1]
lastBlock := lastChunk.Blocks[len(lastChunk.Blocks)-1]

return newDABatchV2(
return newDABatchV3(
uint8(CodecV3), // version
batch.Index, // batchIndex
totalL1MessagePoppedAfter-batch.TotalL1MessagePoppedBefore, // l1MessagePopped
Expand All @@ -81,7 +81,7 @@ func (d *DACodecV3) NewDABatchFromBytes(data []byte) (DABatch, error) {
return nil, fmt.Errorf("invalid codec version: %d, expected: %d", data[0], CodecV3)
}

b := newDABatchV2WithProof(
b := newDABatchV3WithProof(
data[0], // Version
binary.BigEndian.Uint64(data[1:9]), // BatchIndex
binary.BigEndian.Uint64(data[9:17]), // L1MessagePopped
Expand Down Expand Up @@ -182,7 +182,7 @@ func (d *DACodecV3) EstimateBatchL1CommitGas(b *Batch) (uint64, error) {
return totalL1CommitGas, nil
}

// JSONFromBytes converts the bytes to a daBatchV2 and then marshals it to JSON.
// JSONFromBytes converts the bytes to a daBatchV3 and then marshals it to JSON.
func (d *DACodecV3) JSONFromBytes(data []byte) ([]byte, error) {
batch, err := d.NewDABatchFromBytes(data)
if err != nil {
Expand Down
46 changes: 23 additions & 23 deletions encoding/codecv3_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
"github.com/scroll-tech/go-ethereum/crypto/kzg4844"
)

// daBatchV2 contains metadata about a batch of DAChunks.
type daBatchV2 struct {
// daBatchV3 contains metadata about a batch of DAChunks.
type daBatchV3 struct {
daBatchV0

blobVersionedHash common.Hash
Expand All @@ -24,11 +24,11 @@ type daBatchV2 struct {
blobBytes []byte
}

// newDABatchV2 is a constructor for daBatchV2 that calls blobDataProofForPICircuit internally.
func newDABatchV2(version uint8, batchIndex, l1MessagePopped, totalL1MessagePopped, lastBlockTimestamp uint64,
// newDABatchV3 is a constructor for daBatchV3 that calls blobDataProofForPICircuit internally.
func newDABatchV3(version uint8, batchIndex, l1MessagePopped, totalL1MessagePopped, lastBlockTimestamp uint64,
dataHash, parentBatchHash, blobVersionedHash common.Hash, skippedL1MessageBitmap []byte, blob *kzg4844.Blob,
z *kzg4844.Point, blobBytes []byte) (*daBatchV2, error) {
daBatch := &daBatchV2{
z *kzg4844.Point, blobBytes []byte) (*daBatchV3, error) {
daBatch := &daBatchV3{
daBatchV0: daBatchV0{
version: version,
batchIndex: batchIndex,
Expand All @@ -55,11 +55,11 @@ func newDABatchV2(version uint8, batchIndex, l1MessagePopped, totalL1MessagePopp
return daBatch, nil
}

// newDABatchV2WithProof is a constructor for daBatchV2 that allows directly passing blobDataProof.
func newDABatchV2WithProof(version uint8, batchIndex, l1MessagePopped, totalL1MessagePopped, lastBlockTimestamp uint64,
// newDABatchV3WithProof is a constructor for daBatchV3 that allows directly passing blobDataProof.
func newDABatchV3WithProof(version uint8, batchIndex, l1MessagePopped, totalL1MessagePopped, lastBlockTimestamp uint64,
dataHash, parentBatchHash, blobVersionedHash common.Hash, skippedL1MessageBitmap []byte,
blob *kzg4844.Blob, z *kzg4844.Point, blobBytes []byte, blobDataProof [2]common.Hash) *daBatchV2 {
return &daBatchV2{
blob *kzg4844.Blob, z *kzg4844.Point, blobBytes []byte, blobDataProof [2]common.Hash) *daBatchV3 {
return &daBatchV3{
daBatchV0: daBatchV0{
version: version,
batchIndex: batchIndex,
Expand All @@ -79,7 +79,7 @@ func newDABatchV2WithProof(version uint8, batchIndex, l1MessagePopped, totalL1Me
}

// Encode serializes the DABatch into bytes.
func (b *daBatchV2) Encode() []byte {
func (b *daBatchV3) Encode() []byte {
batchBytes := make([]byte, 193)
batchBytes[0] = b.version
binary.BigEndian.PutUint64(batchBytes[1:9], b.batchIndex)
Expand All @@ -95,13 +95,13 @@ func (b *daBatchV2) Encode() []byte {
}

// Hash computes the hash of the serialized DABatch.
func (b *daBatchV2) Hash() common.Hash {
func (b *daBatchV3) Hash() common.Hash {
bytes := b.Encode()
return crypto.Keccak256Hash(bytes)
}

// blobDataProofForPICircuit computes the abi-encoded blob verification data.
func (b *daBatchV2) blobDataProofForPICircuit() ([2]common.Hash, error) {
func (b *daBatchV3) blobDataProofForPICircuit() ([2]common.Hash, error) {
if b.blob == nil {
return [2]common.Hash{}, errors.New("called blobDataProofForPICircuit with empty blob")
}
Expand All @@ -126,7 +126,7 @@ func (b *daBatchV2) blobDataProofForPICircuit() ([2]common.Hash, error) {
}

// BlobDataProofForPointEvaluation computes the abi-encoded blob verification data.
func (b *daBatchV2) BlobDataProofForPointEvaluation() ([]byte, error) {
func (b *daBatchV3) BlobDataProofForPointEvaluation() ([]byte, error) {
if b.blob == nil {
return nil, errors.New("called BlobDataProofForPointEvaluation with empty blob")
}
Expand All @@ -148,19 +148,19 @@ func (b *daBatchV2) BlobDataProofForPointEvaluation() ([]byte, error) {
}

// Blob returns the blob of the batch.
func (b *daBatchV2) Blob() *kzg4844.Blob {
func (b *daBatchV3) Blob() *kzg4844.Blob {
return b.blob
}

// BlobBytes returns the blob bytes of the batch.
func (b *daBatchV2) BlobBytes() []byte {
func (b *daBatchV3) BlobBytes() []byte {
return b.blobBytes
}

// MarshalJSON implements the custom JSON serialization for daBatchV2.
// MarshalJSON implements the custom JSON serialization for daBatchV3.
// This method is designed to provide prover with batch info in snake_case format.
func (b *daBatchV2) MarshalJSON() ([]byte, error) {
type daBatchV2JSON struct {
func (b *daBatchV3) MarshalJSON() ([]byte, error) {
type daBatchV3JSON struct {
Version uint8 `json:"version"`
BatchIndex uint64 `json:"batch_index"`
L1MessagePopped uint64 `json:"l1_message_popped"`
Expand All @@ -174,7 +174,7 @@ func (b *daBatchV2) MarshalJSON() ([]byte, error) {
BlobDataProof [2]string `json:"blob_data_proof"`
}

return json.Marshal(&daBatchV2JSON{
return json.Marshal(&daBatchV3JSON{
Version: b.version,
BatchIndex: b.batchIndex,
L1MessagePopped: b.l1MessagePopped,
Expand All @@ -193,16 +193,16 @@ func (b *daBatchV2) MarshalJSON() ([]byte, error) {
}

// Version returns the version of the DABatch.
func (b *daBatchV2) Version() uint8 {
func (b *daBatchV3) Version() uint8 {
return b.version
}

// SkippedL1MessageBitmap returns the skipped L1 message bitmap of the DABatch.
func (b *daBatchV2) SkippedL1MessageBitmap() []byte {
func (b *daBatchV3) SkippedL1MessageBitmap() []byte {
return b.skippedL1MessageBitmap
}

// DataHash returns the data hash of the DABatch.
func (b *daBatchV2) DataHash() common.Hash {
func (b *daBatchV3) DataHash() common.Hash {
return b.dataHash
}
4 changes: 2 additions & 2 deletions encoding/codecv4.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (d *DACodecV4) NewDABatch(batch *Batch) (DABatch, error) {
return nil, err
}

return newDABatchV2(
return newDABatchV3(
uint8(CodecV4), // version
batch.Index, // batchIndex
totalL1MessagePoppedAfter-batch.TotalL1MessagePoppedBefore, // l1MessagePopped
Expand All @@ -106,7 +106,7 @@ func (d *DACodecV4) NewDABatchFromBytes(data []byte) (DABatch, error) {
return nil, fmt.Errorf("invalid codec version: %d, expected: %d", data[0], CodecV4)
}

b := newDABatchV2WithProof(
b := newDABatchV3WithProof(
data[0], // Version
binary.BigEndian.Uint64(data[1:9]), // BatchIndex
binary.BigEndian.Uint64(data[9:17]), // L1MessagePopped
Expand Down

0 comments on commit 558d029

Please sign in to comment.