Skip to content

Commit 9f125c9

Browse files
authored
fix: use codec v1 for validium encoding (#1739)
1 parent bae85be commit 9f125c9

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

rollup/internal/controller/relayer/l2_relayer.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1040,7 +1040,15 @@ func (r *Layer2Relayer) constructCommitBatchPayloadValidium(batch *dbBatchWithCh
10401040
lastChunk := batch.Chunks[len(batch.Chunks)-1]
10411041
commitment := common.HexToHash(lastChunk.EndBlockHash)
10421042

1043-
version := encoding.CodecVersion(batch.Batch.CodecVersion)
1043+
var version uint8
1044+
if encoding.CodecVersion(batch.Batch.CodecVersion) == encoding.CodecV8 {
1045+
// Validium version line starts with v1,
1046+
// but rollup-relayer behavior follows v8.
1047+
version = 1
1048+
} else {
1049+
return nil, 0, 0, fmt.Errorf("unexpected codec version %d for validium mode", batch.Batch.CodecVersion)
1050+
}
1051+
10441052
calldata, err := r.validiumABI.Pack("commitBatch", version, common.HexToHash(batch.Batch.ParentBatchHash), common.HexToHash(batch.Batch.StateRoot), common.HexToHash(batch.Batch.WithdrawRoot), commitment[:])
10451053
if err != nil {
10461054
return nil, 0, 0, fmt.Errorf("failed to pack commitBatch: %w", err)

rollup/internal/utils/utils.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,19 @@ func encodeBatchHeaderValidium(b *encoding.Batch, codecVersion encoding.CodecVer
164164
commitmentOffset = withdrawRootOffset + withdrawRootSize
165165
)
166166

167-
batchBytes[versionOffset] = uint8(codecVersion) // version
167+
var version uint8
168+
if codecVersion == encoding.CodecV8 {
169+
// Validium version line starts with v1,
170+
// but rollup-relayer behavior follows v8.
171+
version = 1
172+
} else if codecVersion == encoding.CodecV0 {
173+
// Special case for genesis batch
174+
version = 0
175+
} else {
176+
return nil, common.Hash{}, fmt.Errorf("unexpected codec version %d for batch %v in validium mode", codecVersion, b.Index)
177+
}
178+
179+
batchBytes[versionOffset] = version // version
168180
binary.BigEndian.PutUint64(batchBytes[indexOffset:indexOffset+indexSize], b.Index) // batch index
169181
copy(batchBytes[parentHashOffset:parentHashOffset+parentHashSize], b.ParentBatchHash[0:parentHashSize]) // parentBatchHash
170182
copy(batchBytes[stateRootOffset:stateRootOffset+stateRootSize], b.StateRoot().Bytes()[0:stateRootSize]) // postStateRoot

0 commit comments

Comments
 (0)