mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-24 13:46:43 +00:00
fix(rollup-verifier): hardcode genesis codec version as codecv0 and sync codecv1 implementation (#699)
* fix(rollup-verifier): update codecv1 * fix genesis batch codec check * bump version
This commit is contained in:
parent
85447ec9a4
commit
5115f1342d
3 changed files with 19 additions and 16 deletions
|
|
@ -24,7 +24,7 @@ import (
|
||||||
const (
|
const (
|
||||||
VersionMajor = 5 // Major version component of the current release
|
VersionMajor = 5 // Major version component of the current release
|
||||||
VersionMinor = 2 // Minor version component of the current release
|
VersionMinor = 2 // Minor version component of the current release
|
||||||
VersionPatch = 0 // Patch version component of the current release
|
VersionPatch = 1 // Patch version component of the current release
|
||||||
VersionMeta = "mainnet" // Version metadata to append to the version string
|
VersionMeta = "mainnet" // Version metadata to append to the version string
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -415,7 +415,7 @@ func validateBatch(event *L1FinalizeBatchEvent, parentBatchMeta *rawdb.Finalized
|
||||||
}
|
}
|
||||||
|
|
||||||
var localBatchHash common.Hash
|
var localBatchHash common.Hash
|
||||||
if !chainCfg.IsBernoulli(startBlock.Header.Number) {
|
if startBlock.Header.Number.Uint64() == 0 || !chainCfg.IsBernoulli(startBlock.Header.Number) { // codecv0: genesis batch or batches before Bernoulli
|
||||||
daBatch, err := codecv0.NewDABatch(batch)
|
daBatch, err := codecv0.NewDABatch(batch)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, nil, fmt.Errorf("failed to create codecv0 DA batch, batch index: %v, err: %w", event.BatchIndex.Uint64(), err)
|
return 0, nil, fmt.Errorf("failed to create codecv0 DA batch, batch index: %v, err: %w", event.BatchIndex.Uint64(), err)
|
||||||
|
|
|
||||||
|
|
@ -244,18 +244,11 @@ func NewDABatch(batch *encoding.Batch) (*DABatch, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// blob payload
|
// blob payload
|
||||||
blob, z, err := constructBlobPayload(batch.Chunks)
|
blob, blobVersionedHash, z, err := constructBlobPayload(batch.Chunks)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// blob versioned hash
|
|
||||||
c, err := kzg4844.BlobToCommitment(*blob)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to create blob commitment")
|
|
||||||
}
|
|
||||||
blobVersionedHash := kzg4844.CalcBlobHashV1(sha256.New(), &c)
|
|
||||||
|
|
||||||
daBatch := DABatch{
|
daBatch := DABatch{
|
||||||
Version: CodecV1Version,
|
Version: CodecV1Version,
|
||||||
BatchIndex: batch.Index,
|
BatchIndex: batch.Index,
|
||||||
|
|
@ -298,7 +291,7 @@ func computeBatchDataHash(chunks []*encoding.Chunk, totalL1MessagePoppedBefore u
|
||||||
}
|
}
|
||||||
|
|
||||||
// constructBlobPayload constructs the 4844 blob payload.
|
// constructBlobPayload constructs the 4844 blob payload.
|
||||||
func constructBlobPayload(chunks []*encoding.Chunk) (*kzg4844.Blob, *kzg4844.Point, error) {
|
func constructBlobPayload(chunks []*encoding.Chunk) (*kzg4844.Blob, common.Hash, *kzg4844.Point, error) {
|
||||||
// metadata consists of num_chunks (2 bytes) and chunki_size (4 bytes per chunk)
|
// metadata consists of num_chunks (2 bytes) and chunki_size (4 bytes per chunk)
|
||||||
metadataLength := 2 + MaxNumChunks*4
|
metadataLength := 2 + MaxNumChunks*4
|
||||||
|
|
||||||
|
|
@ -306,8 +299,8 @@ func constructBlobPayload(chunks []*encoding.Chunk) (*kzg4844.Blob, *kzg4844.Poi
|
||||||
blobBytes := make([]byte, metadataLength)
|
blobBytes := make([]byte, metadataLength)
|
||||||
|
|
||||||
// challenge digest preimage
|
// challenge digest preimage
|
||||||
// 1 hash for metadata and 1 for each chunk
|
// 1 hash for metadata, 1 hash for each chunk, 1 hash for blob versioned hash
|
||||||
challengePreimage := make([]byte, (1+MaxNumChunks)*32)
|
challengePreimage := make([]byte, (1+MaxNumChunks+1)*32)
|
||||||
|
|
||||||
// the chunk data hash used for calculating the challenge preimage
|
// the chunk data hash used for calculating the challenge preimage
|
||||||
var chunkDataHash common.Hash
|
var chunkDataHash common.Hash
|
||||||
|
|
@ -326,7 +319,7 @@ func constructBlobPayload(chunks []*encoding.Chunk) (*kzg4844.Blob, *kzg4844.Poi
|
||||||
// encode L2 txs into blob payload
|
// encode L2 txs into blob payload
|
||||||
rlpTxData, err := encoding.ConvertTxDataToRLPEncoding(tx)
|
rlpTxData, err := encoding.ConvertTxDataToRLPEncoding(tx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, common.Hash{}, nil, err
|
||||||
}
|
}
|
||||||
blobBytes = append(blobBytes, rlpTxData...)
|
blobBytes = append(blobBytes, rlpTxData...)
|
||||||
}
|
}
|
||||||
|
|
@ -358,9 +351,19 @@ func constructBlobPayload(chunks []*encoding.Chunk) (*kzg4844.Blob, *kzg4844.Poi
|
||||||
// convert raw data to BLSFieldElements
|
// convert raw data to BLSFieldElements
|
||||||
blob, err := makeBlobCanonical(blobBytes)
|
blob, err := makeBlobCanonical(blobBytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, common.Hash{}, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// compute blob versioned hash
|
||||||
|
c, err := kzg4844.BlobToCommitment(*blob)
|
||||||
|
if err != nil {
|
||||||
|
return nil, common.Hash{}, nil, fmt.Errorf("failed to create blob commitment")
|
||||||
|
}
|
||||||
|
blobVersionedHash := kzg4844.CalcBlobHashV1(sha256.New(), &c)
|
||||||
|
|
||||||
|
// challenge: append blob versioned hash
|
||||||
|
copy(challengePreimage[(1+MaxNumChunks)*32:], blobVersionedHash[:])
|
||||||
|
|
||||||
// compute z = challenge_digest % BLS_MODULUS
|
// compute z = challenge_digest % BLS_MODULUS
|
||||||
challengeDigest := crypto.Keccak256Hash(challengePreimage)
|
challengeDigest := crypto.Keccak256Hash(challengePreimage)
|
||||||
pointBigInt := new(big.Int).Mod(new(big.Int).SetBytes(challengeDigest[:]), BLSModulus)
|
pointBigInt := new(big.Int).Mod(new(big.Int).SetBytes(challengeDigest[:]), BLSModulus)
|
||||||
|
|
@ -371,7 +374,7 @@ func constructBlobPayload(chunks []*encoding.Chunk) (*kzg4844.Blob, *kzg4844.Poi
|
||||||
start := 32 - len(pointBytes)
|
start := 32 - len(pointBytes)
|
||||||
copy(z[start:], pointBytes)
|
copy(z[start:], pointBytes)
|
||||||
|
|
||||||
return blob, &z, nil
|
return blob, blobVersionedHash, &z, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// makeBlobCanonical converts the raw blob data into the canonical blob representation of 4096 BLSFieldElements.
|
// makeBlobCanonical converts the raw blob data into the canonical blob representation of 4096 BLSFieldElements.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue