Skip to content

Commit 09129b6

Browse files
committed
adjust
1 parent 4eac6d1 commit 09129b6

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

encoding/codecv7_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,45 @@ func TestDecodeAllDeadlock(t *testing.T) {
4848
}
4949
}
5050

51+
// TestChunkHashUnique tests that the hashes of any two different chunks are different.
52+
func TestChunkHashUnique(t *testing.T) {
53+
// construct a chunk with a single, empty block
54+
chunk1 := newDAChunkV7([]DABlock{&daBlockV7{
55+
daBlockV0: daBlockV0{
56+
number: 1,
57+
timestamp: 0,
58+
baseFee: big.NewInt(0),
59+
gasLimit: 0,
60+
numTransactions: 0,
61+
numL1Messages: 0,
62+
},
63+
lowestL1MessageQueueIndex: 0,
64+
}}, [][]*types.TransactionData{{}})
65+
66+
chunkHash1, err := chunk1.Hash()
67+
require.NoError(t, err)
68+
69+
// construct a 2nd chunk with a single, empty block,
70+
// the only difference is the block number.
71+
chunk2 := newDAChunkV7([]DABlock{&daBlockV7{
72+
daBlockV0: daBlockV0{
73+
number: 2,
74+
timestamp: 0,
75+
baseFee: big.NewInt(0),
76+
gasLimit: 0,
77+
numTransactions: 0,
78+
numL1Messages: 0,
79+
},
80+
lowestL1MessageQueueIndex: 0,
81+
}}, [][]*types.TransactionData{{}})
82+
83+
chunkHash2, err := chunk2.Hash()
84+
require.NoError(t, err)
85+
86+
require.NotEqual(t, chunkHash1, chunkHash2)
87+
88+
}
89+
5190
// TestCodecV7DABlockEncodeDecode tests the encoding and decoding of daBlockV7.
5291
func TestCodecV7DABlockEncodeDecode(t *testing.T) {
5392
codecV7, err := CodecFromVersion(CodecV7)

encoding/codecv7_types.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,16 +447,24 @@ func newDAChunkV7(blocks []DABlock, transactions [][]*types.TransactionData) *da
447447
}
448448

449449
// Hash computes the hash of the DAChunk data.
450+
// Note: Starting from v7, the chunk hash is not used in
451+
// the protocol anymore, it is simply a unique identifier.
450452
func (c *daChunkV7) Hash() (common.Hash, error) {
451453
var dataBytes []byte
452454

453455
// concatenate block contexts
454456
for _, block := range c.blocks {
457+
// append block number
458+
var tmp [8]byte
459+
binary.BigEndian.PutUint64(tmp[:], block.Number())
460+
dataBytes = append(dataBytes, tmp[:]...)
461+
462+
// append encoded block context
455463
encodedBlock := block.Encode()
456464
dataBytes = append(dataBytes, encodedBlock...)
457465
}
458466

459-
// concatenate l1 tx hashes
467+
// concatenate tx hashes
460468
for _, blockTxs := range c.transactions {
461469
for _, txData := range blockTxs {
462470
hashBytes := common.FromHex(txData.TxHash)

0 commit comments

Comments
 (0)