From 01efe0d43dea32fd83add39c3bf38f3f895febd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Garamv=C3=B6lgyi?= Date: Fri, 22 Aug 2025 17:16:08 +0200 Subject: [PATCH 1/3] fix: Consider all transactions in chunk hash --- encoding/codecv7_types.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/encoding/codecv7_types.go b/encoding/codecv7_types.go index 2096040..41148a6 100644 --- a/encoding/codecv7_types.go +++ b/encoding/codecv7_types.go @@ -460,10 +460,6 @@ func (c *daChunkV7) Hash() (common.Hash, error) { // concatenate l1 tx hashes for _, blockTxs := range c.transactions { for _, txData := range blockTxs { - if txData.Type != types.L1MessageTxType { - continue - } - hashBytes := common.FromHex(txData.TxHash) if len(hashBytes) != common.HashLength { return common.Hash{}, fmt.Errorf("unexpected hash: %s", txData.TxHash) From 09129b60e408114c2b23e6730889f98010e2fb31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Garamv=C3=B6lgyi?= Date: Mon, 25 Aug 2025 16:26:33 +0200 Subject: [PATCH 2/3] adjust --- encoding/codecv7_test.go | 39 +++++++++++++++++++++++++++++++++++++++ encoding/codecv7_types.go | 10 +++++++++- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/encoding/codecv7_test.go b/encoding/codecv7_test.go index 12bf8d0..c1c778b 100644 --- a/encoding/codecv7_test.go +++ b/encoding/codecv7_test.go @@ -48,6 +48,45 @@ func TestDecodeAllDeadlock(t *testing.T) { } } +// TestChunkHashUnique tests that the hashes of any two different chunks are different. +func TestChunkHashUnique(t *testing.T) { + // construct a chunk with a single, empty block + chunk1 := newDAChunkV7([]DABlock{&daBlockV7{ + daBlockV0: daBlockV0{ + number: 1, + timestamp: 0, + baseFee: big.NewInt(0), + gasLimit: 0, + numTransactions: 0, + numL1Messages: 0, + }, + lowestL1MessageQueueIndex: 0, + }}, [][]*types.TransactionData{{}}) + + chunkHash1, err := chunk1.Hash() + require.NoError(t, err) + + // construct a 2nd chunk with a single, empty block, + // the only difference is the block number. + chunk2 := newDAChunkV7([]DABlock{&daBlockV7{ + daBlockV0: daBlockV0{ + number: 2, + timestamp: 0, + baseFee: big.NewInt(0), + gasLimit: 0, + numTransactions: 0, + numL1Messages: 0, + }, + lowestL1MessageQueueIndex: 0, + }}, [][]*types.TransactionData{{}}) + + chunkHash2, err := chunk2.Hash() + require.NoError(t, err) + + require.NotEqual(t, chunkHash1, chunkHash2) + +} + // TestCodecV7DABlockEncodeDecode tests the encoding and decoding of daBlockV7. func TestCodecV7DABlockEncodeDecode(t *testing.T) { codecV7, err := CodecFromVersion(CodecV7) diff --git a/encoding/codecv7_types.go b/encoding/codecv7_types.go index 2d1d751..af180c1 100644 --- a/encoding/codecv7_types.go +++ b/encoding/codecv7_types.go @@ -447,16 +447,24 @@ func newDAChunkV7(blocks []DABlock, transactions [][]*types.TransactionData) *da } // Hash computes the hash of the DAChunk data. +// Note: Starting from v7, the chunk hash is not used in +// the protocol anymore, it is simply a unique identifier. func (c *daChunkV7) Hash() (common.Hash, error) { var dataBytes []byte // concatenate block contexts for _, block := range c.blocks { + // append block number + var tmp [8]byte + binary.BigEndian.PutUint64(tmp[:], block.Number()) + dataBytes = append(dataBytes, tmp[:]...) + + // append encoded block context encodedBlock := block.Encode() dataBytes = append(dataBytes, encodedBlock...) } - // concatenate l1 tx hashes + // concatenate tx hashes for _, blockTxs := range c.transactions { for _, txData := range blockTxs { hashBytes := common.FromHex(txData.TxHash) From 9e1dd6cc16cb16aca0f6c7e211b20086523fd3e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Garamv=C3=B6lgyi?= Date: Mon, 25 Aug 2025 16:27:13 +0200 Subject: [PATCH 3/3] nit --- encoding/codecv7_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/encoding/codecv7_test.go b/encoding/codecv7_test.go index c1c778b..9ed0fec 100644 --- a/encoding/codecv7_test.go +++ b/encoding/codecv7_test.go @@ -84,7 +84,6 @@ func TestChunkHashUnique(t *testing.T) { require.NoError(t, err) require.NotEqual(t, chunkHash1, chunkHash2) - } // TestCodecV7DABlockEncodeDecode tests the encoding and decoding of daBlockV7.