From 832442684f9410adea38cf227b135f8968156b14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Garamv=C3=B6lgyi?= Date: Tue, 16 Sep 2025 13:40:47 +0200 Subject: [PATCH] fix: use codec v1 for validium encoding --- rollup/internal/controller/relayer/l2_relayer.go | 10 +++++++++- rollup/internal/utils/utils.go | 14 +++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/rollup/internal/controller/relayer/l2_relayer.go b/rollup/internal/controller/relayer/l2_relayer.go index 5489596ce5..b255a23db6 100644 --- a/rollup/internal/controller/relayer/l2_relayer.go +++ b/rollup/internal/controller/relayer/l2_relayer.go @@ -1040,7 +1040,15 @@ func (r *Layer2Relayer) constructCommitBatchPayloadValidium(batch *dbBatchWithCh lastChunk := batch.Chunks[len(batch.Chunks)-1] commitment := common.HexToHash(lastChunk.EndBlockHash) - version := encoding.CodecVersion(batch.Batch.CodecVersion) + var version uint8 + if encoding.CodecVersion(batch.Batch.CodecVersion) == encoding.CodecV8 { + // Validium version line starts with v1, + // but rollup-relayer behavior follows v8. + version = 1 + } else { + return nil, 0, 0, fmt.Errorf("unexpected codec version %d for validium mode", batch.Batch.CodecVersion) + } + calldata, err := r.validiumABI.Pack("commitBatch", version, common.HexToHash(batch.Batch.ParentBatchHash), common.HexToHash(batch.Batch.StateRoot), common.HexToHash(batch.Batch.WithdrawRoot), commitment[:]) if err != nil { return nil, 0, 0, fmt.Errorf("failed to pack commitBatch: %w", err) diff --git a/rollup/internal/utils/utils.go b/rollup/internal/utils/utils.go index 9a55b93e21..5150b96081 100644 --- a/rollup/internal/utils/utils.go +++ b/rollup/internal/utils/utils.go @@ -164,7 +164,19 @@ func encodeBatchHeaderValidium(b *encoding.Batch, codecVersion encoding.CodecVer commitmentOffset = withdrawRootOffset + withdrawRootSize ) - batchBytes[versionOffset] = uint8(codecVersion) // version + var version uint8 + if codecVersion == encoding.CodecV8 { + // Validium version line starts with v1, + // but rollup-relayer behavior follows v8. + version = 1 + } else if codecVersion == encoding.CodecV0 { + // Special case for genesis batch + version = 0 + } else { + return nil, common.Hash{}, fmt.Errorf("unexpected codec version %d for batch %v in validium mode", codecVersion, b.Index) + } + + batchBytes[versionOffset] = version // version binary.BigEndian.PutUint64(batchBytes[indexOffset:indexOffset+indexSize], b.Index) // batch index copy(batchBytes[parentHashOffset:parentHashOffset+parentHashSize], b.ParentBatchHash[0:parentHashSize]) // parentBatchHash copy(batchBytes[stateRootOffset:stateRootOffset+stateRootSize], b.StateRoot().Bytes()[0:stateRootSize]) // postStateRoot