encoding

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 21, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckBatchCompressedDataCompatibility

func CheckBatchCompressedDataCompatibility(batch *Batch, codecVersion CodecVersion) (bool, error)

CheckBatchCompressedDataCompatibility checks compressed data compatibility of a batch built by a single chunk.

func CheckChunkCompressedDataCompatibility

func CheckChunkCompressedDataCompatibility(chunk *Chunk, codecVersion CodecVersion) (bool, error)

CheckChunkCompressedDataCompatibility checks compressed data compatibility of a batch built by a single chunk.

func DecodeBitmap

func DecodeBitmap(skippedL1MessageBitmap []byte, totalL1MessagePopped int) ([]*big.Int, error)

DecodeBitmap decodes skipped L1 message bitmap of the batch from bytes to big.Int's.

func GetBatchEnableCompression

func GetBatchEnableCompression(codecVersion CodecVersion, batch *Batch) (bool, error)

GetBatchEnableCompression returns whether to enable compression for the given block height and timestamp.

func GetChunkEnableCompression

func GetChunkEnableCompression(codecVersion CodecVersion, chunk *Chunk) (bool, error)

GetChunkEnableCompression returns whether to enable compression for the given block height and timestamp.

func GetHardforkName

func GetHardforkName(config *params.ChainConfig, blockHeight, blockTimestamp uint64) string

GetHardforkName returns the name of the hardfork active at the given block height and timestamp.

func IsL1MessageSkipped

func IsL1MessageSkipped(skippedBitmap []*big.Int, index uint64) bool

IsL1MessageSkipped checks if the L1 message at the given index is skipped.

func TxsToTxsData

func TxsToTxsData(txs types.Transactions) []*types.TransactionData

TxsToTxsData converts transactions to a TransactionData array.

Types

type Batch

type Batch struct {
	Index                      uint64
	TotalL1MessagePoppedBefore uint64
	ParentBatchHash            common.Hash
	Chunks                     []*Chunk
}

Batch represents a batch of chunks.

func (*Batch) StateRoot

func (b *Batch) StateRoot() common.Hash

StateRoot gets the state root after committing/finalizing the batch.

func (*Batch) WithdrawRoot

func (b *Batch) WithdrawRoot() common.Hash

WithdrawRoot gets the withdraw root after committing/finalizing the batch.

type Block

type Block struct {
	Header         *types.Header
	Transactions   []*types.TransactionData
	WithdrawRoot   common.Hash           `json:"withdraw_trie_root,omitempty"`
	RowConsumption *types.RowConsumption `json:"row_consumption,omitempty"`
}

Block represents an L2 block.

func (*Block) NumL1Messages

func (b *Block) NumL1Messages(totalL1MessagePoppedBefore uint64) uint64

NumL1Messages returns the number of L1 messages in this block. This number is the sum of included and skipped L1 messages.

func (*Block) NumL2Transactions

func (b *Block) NumL2Transactions() uint64

NumL2Transactions returns the number of L2 transactions in this block.

type Chunk

type Chunk struct {
	Blocks []*Block `json:"blocks"`
}

Chunk represents a group of blocks.

func (*Chunk) CrcMax

func (c *Chunk) CrcMax() (uint64, error)

CrcMax calculates the maximum row consumption of crc.

func (*Chunk) NumL1Messages

func (c *Chunk) NumL1Messages(totalL1MessagePoppedBefore uint64) uint64

NumL1Messages returns the number of L1 messages in this chunk. This number is the sum of included and skipped L1 messages.

func (*Chunk) NumL2Transactions

func (c *Chunk) NumL2Transactions() uint64

NumL2Transactions calculates the total number of L2 transactions in a Chunk.

func (*Chunk) NumTransactions

func (c *Chunk) NumTransactions() uint64

NumTransactions calculates the total number of transactions in a Chunk.

func (*Chunk) TotalGasUsed

func (c *Chunk) TotalGasUsed() uint64

TotalGasUsed calculates the total gas of transactions in a Chunk.

type Codec

type Codec interface {
	Version() CodecVersion
	MaxNumChunksPerBatch() int

	NewDABlock(*Block, uint64) (DABlock, error)
	NewDAChunk(*Chunk, uint64) (DAChunk, error)
	NewDABatch(*Batch) (DABatch, error)
	NewDABatchFromBytes([]byte) (DABatch, error)

	DecodeDAChunksRawTx(chunkBytes [][]byte) ([]*DAChunkRawTx, error)
	DecodeTxsFromBlob(blob *kzg4844.Blob, chunks []*DAChunkRawTx) error

	CheckChunkCompressedDataCompatibility(*Chunk) (bool, error)
	CheckBatchCompressedDataCompatibility(*Batch) (bool, error)

	EstimateChunkL1CommitBatchSizeAndBlobSize(*Chunk) (uint64, uint64, error)
	EstimateBatchL1CommitBatchSizeAndBlobSize(*Batch) (uint64, uint64, error)
	EstimateBlockL1CommitCalldataSize(*Block) (uint64, error)
	EstimateChunkL1CommitCalldataSize(*Chunk) (uint64, error)
	EstimateChunkL1CommitGas(*Chunk) (uint64, error)
	EstimateBatchL1CommitGas(*Batch) (uint64, error)
	EstimateBatchL1CommitCalldataSize(*Batch) (uint64, error)

	JSONFromBytes([]byte) ([]byte, error) // convert batch header bytes to JSON, this is only used to provide witness data for the prover.
}

Codec represents the interface for encoding and decoding DA-related structures.

func CodecFromConfig

func CodecFromConfig(chainCfg *params.ChainConfig, startBlockNumber *big.Int, startBlockTimestamp uint64) Codec

CodecFromConfig determines and returns the appropriate codec based on chain configuration, block number, and timestamp.

func CodecFromVersion

func CodecFromVersion(version CodecVersion) (Codec, error)

CodecFromVersion returns the appropriate codec for the given version.

type CodecVersion

type CodecVersion uint8

CodecVersion represents the version of the codec.

const (
	CodecV0 CodecVersion = iota
	CodecV1
	CodecV2
	CodecV3
	CodecV4
)

func GetCodecVersion

func GetCodecVersion(config *params.ChainConfig, blockHeight, blockTimestamp uint64) CodecVersion

GetCodecVersion returns the encoding codec version for the given block height and timestamp.

type DABatch

type DABatch interface {
	Encode() []byte
	Hash() common.Hash
	DataHash() common.Hash
	BlobDataProofForPointEvaluation() ([]byte, error)
	Blob() *kzg4844.Blob
	BlobBytes() []byte
	Version() CodecVersion
	SkippedL1MessageBitmap() []byte
}

DABatch contains metadata about a batch of DAChunks.

type DABlock

type DABlock interface {
	Encode() []byte
	Decode([]byte) error
	Number() uint64
	NumTransactions() uint16
	NumL1Messages() uint16
	Timestamp() uint64
	BaseFee() *big.Int
	GasLimit() uint64
}

DABlock represents a Data Availability Block.

type DAChunk

type DAChunk interface {
	Encode() ([]byte, error)
	Hash() (common.Hash, error)
	BlockRange() (uint64, uint64, error)
}

DAChunk groups consecutive DABlocks with their transactions.

type DAChunkRawTx

type DAChunkRawTx struct {
	Blocks       []DABlock
	Transactions []types.Transactions
}

DAChunkRawTx groups consecutive DABlocks with their L2 transactions, L1 msgs are loaded in another place.

type DACodecV0

type DACodecV0 struct{}

func (*DACodecV0) CheckBatchCompressedDataCompatibility

func (d *DACodecV0) CheckBatchCompressedDataCompatibility(b *Batch) (bool, error)

CheckBatchCompressedDataCompatibility checks the compressed data compatibility for a batch.

func (*DACodecV0) CheckChunkCompressedDataCompatibility

func (d *DACodecV0) CheckChunkCompressedDataCompatibility(c *Chunk) (bool, error)

CheckChunkCompressedDataCompatibility checks the compressed data compatibility for a batch built from a single chunk.

func (*DACodecV0) DecodeDAChunksRawTx

func (d *DACodecV0) DecodeDAChunksRawTx(chunkBytes [][]byte) ([]*DAChunkRawTx, error)

DecodeDAChunksRawTx takes a byte slice and decodes it into a []*DAChunkRawTx.

func (*DACodecV0) DecodeTxsFromBlob

func (d *DACodecV0) DecodeTxsFromBlob(blob *kzg4844.Blob, chunks []*DAChunkRawTx) error

DecodeTxsFromBlob decodes txs from blob bytes and writes to chunks

func (*DACodecV0) EstimateBatchL1CommitBatchSizeAndBlobSize

func (d *DACodecV0) EstimateBatchL1CommitBatchSizeAndBlobSize(b *Batch) (uint64, uint64, error)

EstimateBatchL1CommitBatchSizeAndBlobSize estimates the L1 commit batch size and blob size for a batch.

func (*DACodecV0) EstimateBatchL1CommitCalldataSize

func (d *DACodecV0) EstimateBatchL1CommitCalldataSize(b *Batch) (uint64, error)

EstimateBatchL1CommitCalldataSize calculates the calldata size in l1 commit for this batch approximately.

func (*DACodecV0) EstimateBatchL1CommitGas

func (d *DACodecV0) EstimateBatchL1CommitGas(b *Batch) (uint64, error)

EstimateBatchL1CommitGas calculates the total L1 commit gas for this batch approximately.

func (*DACodecV0) EstimateBlockL1CommitCalldataSize

func (d *DACodecV0) EstimateBlockL1CommitCalldataSize(b *Block) (uint64, error)

EstimateBlockL1CommitCalldataSize calculates the calldata size in l1 commit for this block approximately.

func (*DACodecV0) EstimateBlockL1CommitGas

func (d *DACodecV0) EstimateBlockL1CommitGas(b *Block) (uint64, error)

EstimateBlockL1CommitGas calculates the total L1 commit gas for this block approximately.

func (*DACodecV0) EstimateChunkL1CommitBatchSizeAndBlobSize

func (d *DACodecV0) EstimateChunkL1CommitBatchSizeAndBlobSize(c *Chunk) (uint64, uint64, error)

EstimateChunkL1CommitBatchSizeAndBlobSize estimates the L1 commit batch size and blob size for a single chunk.

func (*DACodecV0) EstimateChunkL1CommitCalldataSize

func (d *DACodecV0) EstimateChunkL1CommitCalldataSize(c *Chunk) (uint64, error)

EstimateChunkL1CommitCalldataSize calculates the calldata size needed for committing a chunk to L1 approximately.

func (*DACodecV0) EstimateChunkL1CommitGas

func (d *DACodecV0) EstimateChunkL1CommitGas(c *Chunk) (uint64, error)

EstimateChunkL1CommitGas calculates the total L1 commit gas for this chunk approximately.

func (*DACodecV0) JSONFromBytes

func (c *DACodecV0) JSONFromBytes(data []byte) ([]byte, error)

JSONFromBytes for CodecV0 returns empty values.

func (*DACodecV0) MaxNumChunksPerBatch

func (d *DACodecV0) MaxNumChunksPerBatch() int

MaxNumChunksPerBatch returns the maximum number of chunks per batch.

func (*DACodecV0) NewDABatch

func (d *DACodecV0) NewDABatch(batch *Batch) (DABatch, error)

NewDABatch creates a DABatch from the provided Batch.

func (*DACodecV0) NewDABatchFromBytes

func (d *DACodecV0) NewDABatchFromBytes(data []byte) (DABatch, error)

NewDABatchFromBytes decodes the given byte slice into a DABatch.

func (*DACodecV0) NewDABlock

func (d *DACodecV0) NewDABlock(block *Block, totalL1MessagePoppedBefore uint64) (DABlock, error)

NewDABlock creates a new DABlock from the given Block and the total number of L1 messages popped before.

func (*DACodecV0) NewDAChunk

func (d *DACodecV0) NewDAChunk(chunk *Chunk, totalL1MessagePoppedBefore uint64) (DAChunk, error)

NewDAChunk creates a new DAChunk from the given Chunk and the total number of L1 messages popped before.

func (*DACodecV0) Version

func (d *DACodecV0) Version() CodecVersion

Version returns the codec version.

type DACodecV1

type DACodecV1 struct {
	DACodecV0
}

func (*DACodecV1) DecodeDAChunksRawTx

func (d *DACodecV1) DecodeDAChunksRawTx(chunkBytes [][]byte) ([]*DAChunkRawTx, error)

DecodeDAChunksRawTx takes a byte slice and decodes it into a []*DAChunkRawTx. Beginning from codecv1 tx data posted to blobs, not to chunk bytes in calldata

func (*DACodecV1) DecodeTxsFromBlob

func (d *DACodecV1) DecodeTxsFromBlob(blob *kzg4844.Blob, chunks []*DAChunkRawTx) error

DecodeTxsFromBlob decodes txs from blob bytes and writes to chunks

func (*DACodecV1) EstimateBatchL1CommitBatchSizeAndBlobSize

func (d *DACodecV1) EstimateBatchL1CommitBatchSizeAndBlobSize(b *Batch) (uint64, uint64, error)

EstimateBatchL1CommitBatchSizeAndBlobSize estimates the L1 commit batch size and blob size for a batch.

func (*DACodecV1) EstimateBatchL1CommitCalldataSize

func (d *DACodecV1) EstimateBatchL1CommitCalldataSize(b *Batch) (uint64, error)

EstimateBatchL1CommitCalldataSize calculates the calldata size in l1 commit for this batch approximately.

func (*DACodecV1) EstimateBatchL1CommitGas

func (d *DACodecV1) EstimateBatchL1CommitGas(b *Batch) (uint64, error)

EstimateBatchL1CommitGas calculates the total L1 commit gas for this batch approximately.

func (*DACodecV1) EstimateBlockL1CommitCalldataSize

func (d *DACodecV1) EstimateBlockL1CommitCalldataSize(_ *Block) (uint64, error)

EstimateBlockL1CommitCalldataSize calculates the calldata size in l1 commit for this block approximately.

func (*DACodecV1) EstimateBlockL1CommitGas

func (d *DACodecV1) EstimateBlockL1CommitGas(b *Block) (uint64, error)

EstimateBlockL1CommitGas calculates the total L1 commit gas for this block approximately.

func (*DACodecV1) EstimateChunkL1CommitBatchSizeAndBlobSize

func (d *DACodecV1) EstimateChunkL1CommitBatchSizeAndBlobSize(c *Chunk) (uint64, uint64, error)

EstimateChunkL1CommitBatchSizeAndBlobSize estimates the L1 commit batch size and blob size for a single chunk.

func (*DACodecV1) EstimateChunkL1CommitCalldataSize

func (d *DACodecV1) EstimateChunkL1CommitCalldataSize(c *Chunk) (uint64, error)

EstimateChunkL1CommitCalldataSize calculates the calldata size needed for committing a chunk to L1 approximately.

func (*DACodecV1) EstimateChunkL1CommitGas

func (d *DACodecV1) EstimateChunkL1CommitGas(c *Chunk) (uint64, error)

EstimateChunkL1CommitGas calculates the total L1 commit gas for this chunk approximately.

func (*DACodecV1) NewDABatch

func (d *DACodecV1) NewDABatch(batch *Batch) (DABatch, error)

NewDABatch creates a DABatch from the provided Batch.

func (*DACodecV1) NewDABatchFromBytes

func (d *DACodecV1) NewDABatchFromBytes(data []byte) (DABatch, error)

NewDABatchFromBytes decodes the given byte slice into a DABatch. Note: This function only populates the batch header, it leaves the blob-related fields empty.

func (*DACodecV1) NewDAChunk

func (d *DACodecV1) NewDAChunk(chunk *Chunk, totalL1MessagePoppedBefore uint64) (DAChunk, error)

NewDAChunk creates a new DAChunk from the given Chunk and the total number of L1 messages popped before.

func (*DACodecV1) Version

func (d *DACodecV1) Version() CodecVersion

Version returns the codec version.

type DACodecV2

type DACodecV2 struct {
	DACodecV1
}

func (*DACodecV2) CheckBatchCompressedDataCompatibility

func (d *DACodecV2) CheckBatchCompressedDataCompatibility(b *Batch) (bool, error)

CheckBatchCompressedDataCompatibility checks the compressed data compatibility for a batch. It constructs a batch payload, compresses the data, and checks the compressed data compatibility if the uncompressed data exceeds 128 KiB.

func (*DACodecV2) CheckChunkCompressedDataCompatibility

func (d *DACodecV2) CheckChunkCompressedDataCompatibility(c *Chunk) (bool, error)

CheckChunkCompressedDataCompatibility checks the compressed data compatibility for a batch built from a single chunk. It constructs a batch payload, compresses the data, and checks the compressed data compatibility if the uncompressed data exceeds 128 KiB.

func (*DACodecV2) DecodeTxsFromBlob

func (d *DACodecV2) DecodeTxsFromBlob(blob *kzg4844.Blob, chunks []*DAChunkRawTx) error

DecodeTxsFromBlob decodes txs from blob bytes and writes to chunks

func (*DACodecV2) EstimateBatchL1CommitBatchSizeAndBlobSize

func (d *DACodecV2) EstimateBatchL1CommitBatchSizeAndBlobSize(b *Batch) (uint64, uint64, error)

EstimateBatchL1CommitBatchSizeAndBlobSize estimates the L1 commit batch size and blob size for a batch.

func (*DACodecV2) EstimateChunkL1CommitBatchSizeAndBlobSize

func (d *DACodecV2) EstimateChunkL1CommitBatchSizeAndBlobSize(c *Chunk) (uint64, uint64, error)

EstimateChunkL1CommitBatchSizeAndBlobSize estimates the L1 commit batch size and blob size for a single chunk.

func (*DACodecV2) MaxNumChunksPerBatch

func (d *DACodecV2) MaxNumChunksPerBatch() int

MaxNumChunksPerBatch returns the maximum number of chunks per batch.

func (*DACodecV2) NewDABatch

func (d *DACodecV2) NewDABatch(batch *Batch) (DABatch, error)

NewDABatch creates a DABatch from the provided Batch.

func (*DACodecV2) NewDABatchFromBytes

func (d *DACodecV2) NewDABatchFromBytes(data []byte) (DABatch, error)

NewDABatchFromBytes decodes the given byte slice into a DABatch. Note: This function only populates the batch header, it leaves the blob-related fields empty.

func (*DACodecV2) Version

func (d *DACodecV2) Version() CodecVersion

Version returns the codec version.

type DACodecV3

type DACodecV3 struct {
	DACodecV2
}

func (*DACodecV3) EstimateBatchL1CommitGas

func (d *DACodecV3) EstimateBatchL1CommitGas(b *Batch) (uint64, error)

EstimateBatchL1CommitGas calculates the total L1 commit gas for this batch approximately.

func (*DACodecV3) EstimateChunkL1CommitGas

func (d *DACodecV3) EstimateChunkL1CommitGas(c *Chunk) (uint64, error)

EstimateChunkL1CommitGas calculates the total L1 commit gas for this chunk approximately.

func (*DACodecV3) JSONFromBytes

func (d *DACodecV3) JSONFromBytes(data []byte) ([]byte, error)

JSONFromBytes converts the bytes to a daBatchV3 and then marshals it to JSON.

func (*DACodecV3) NewDABatch

func (d *DACodecV3) NewDABatch(batch *Batch) (DABatch, error)

NewDABatch creates a DABatch from the provided Batch.

func (*DACodecV3) NewDABatchFromBytes

func (d *DACodecV3) NewDABatchFromBytes(data []byte) (DABatch, error)

NewDABatchFromBytes decodes the given byte slice into a DABatch. Note: This function only populates the batch header, it leaves the blob-related fields and skipped L1 message bitmap empty.

func (*DACodecV3) Version

func (d *DACodecV3) Version() CodecVersion

Version returns the codec version.

type DACodecV4

type DACodecV4 struct {
	DACodecV3
}

func (*DACodecV4) CheckBatchCompressedDataCompatibility

func (d *DACodecV4) CheckBatchCompressedDataCompatibility(b *Batch) (bool, error)

CheckBatchCompressedDataCompatibility checks the compressed data compatibility for a batch.

func (*DACodecV4) CheckChunkCompressedDataCompatibility

func (d *DACodecV4) CheckChunkCompressedDataCompatibility(c *Chunk) (bool, error)

CheckChunkCompressedDataCompatibility checks the compressed data compatibility for a batch built from a single chunk.

func (*DACodecV4) DecodeTxsFromBlob

func (d *DACodecV4) DecodeTxsFromBlob(blob *kzg4844.Blob, chunks []*DAChunkRawTx) error

DecodeTxsFromBlob decodes txs from blob bytes and writes to chunks

func (*DACodecV4) EstimateBatchL1CommitBatchSizeAndBlobSize

func (d *DACodecV4) EstimateBatchL1CommitBatchSizeAndBlobSize(b *Batch) (uint64, uint64, error)

EstimateBatchL1CommitBatchSizeAndBlobSize estimates the L1 commit batch size and blob size for a batch.

func (*DACodecV4) EstimateChunkL1CommitBatchSizeAndBlobSize

func (d *DACodecV4) EstimateChunkL1CommitBatchSizeAndBlobSize(c *Chunk) (uint64, uint64, error)

EstimateChunkL1CommitBatchSizeAndBlobSize estimates the L1 commit batch size and blob size for a single chunk.

func (*DACodecV4) JSONFromBytes

func (d *DACodecV4) JSONFromBytes(data []byte) ([]byte, error)

JSONFromBytes converts the bytes to a daBatchV3 and then marshals it to JSON.

func (*DACodecV4) NewDABatch

func (d *DACodecV4) NewDABatch(batch *Batch) (DABatch, error)

NewDABatch creates a DABatch from the provided Batch.

func (*DACodecV4) NewDABatchFromBytes

func (d *DACodecV4) NewDABatchFromBytes(data []byte) (DABatch, error)

NewDABatchFromBytes decodes the given byte slice into a DABatch. Note: This function only populates the batch header, it leaves the blob-related fields and skipped L1 message bitmap empty.

func (*DACodecV4) Version

func (d *DACodecV4) Version() CodecVersion

Version returns the codec version.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL