Skip to content

Commit 4f78d1a

Browse files
author
colinlyguo
committed
address comments
1 parent 886365d commit 4f78d1a

File tree

9 files changed

+112
-149
lines changed

9 files changed

+112
-149
lines changed

encoding/bitmap.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ func constructSkippedBitmap(batchIndex uint64, chunks []*Chunk, totalL1MessagePo
5454
}
5555
}
5656

57-
bitmapBytes := make([]byte, len(skippedBitmap)*32)
57+
bitmapBytes := make([]byte, len(skippedBitmap)*skippedL1MessageBitmapByteSize)
5858
for ii, num := range skippedBitmap {
5959
bytes := num.Bytes()
60-
padding := 32 - len(bytes)
61-
copy(bitmapBytes[32*ii+padding:], bytes)
60+
padding := skippedL1MessageBitmapByteSize - len(bytes)
61+
copy(bitmapBytes[skippedL1MessageBitmapByteSize*ii+padding:], bytes)
6262
}
6363

6464
return bitmapBytes, nextIndex, nil
@@ -67,15 +67,15 @@ func constructSkippedBitmap(batchIndex uint64, chunks []*Chunk, totalL1MessagePo
6767
// decodeBitmap decodes skipped L1 message bitmap of the batch from bytes to big.Int's.
6868
func decodeBitmap(skippedL1MessageBitmap []byte, totalL1MessagePopped int) ([]*big.Int, error) {
6969
length := len(skippedL1MessageBitmap)
70-
if length%32 != 0 {
71-
return nil, fmt.Errorf("skippedL1MessageBitmap length doesn't match, skippedL1MessageBitmap length should be equal 0 modulo 32, length of skippedL1MessageBitmap: %v", length)
70+
if length%skippedL1MessageBitmapByteSize != 0 {
71+
return nil, fmt.Errorf("skippedL1MessageBitmap length doesn't match, skippedL1MessageBitmap length should be equal 0 modulo %v, length of skippedL1MessageBitmap: %v", skippedL1MessageBitmapByteSize, length)
7272
}
7373
if length*8 < totalL1MessagePopped {
7474
return nil, fmt.Errorf("skippedL1MessageBitmap length is too small, skippedL1MessageBitmap length should be at least %v, length of skippedL1MessageBitmap: %v", (totalL1MessagePopped+7)/8, length)
7575
}
7676
var skippedBitmap []*big.Int
77-
for index := 0; index < length/32; index++ {
78-
bitmap := big.NewInt(0).SetBytes(skippedL1MessageBitmap[index*32 : index*32+32])
77+
for index := 0; index < length/skippedL1MessageBitmapByteSize; index++ {
78+
bitmap := big.NewInt(0).SetBytes(skippedL1MessageBitmap[index*skippedL1MessageBitmapByteSize : index*skippedL1MessageBitmapByteSize+skippedL1MessageBitmapByteSize])
7979
skippedBitmap = append(skippedBitmap, bitmap)
8080
}
8181
return skippedBitmap, nil

encoding/codecv0.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ func (d *DACodecV0) EstimateBlockL1CommitCalldataSize(b *Block) (uint64, error)
230230
if txData.Type == types.L1MessageTxType {
231231
continue
232232
}
233-
size += 4 // 4 bytes payload length
233+
size += payloadLengthBytes
234234
txPayloadLength, err := getTxPayloadLength(txData)
235235
if err != nil {
236236
return 0, err
@@ -263,17 +263,17 @@ func (d *DACodecV0) EstimateBlockL1CommitGas(b *Block) (uint64, error) {
263263
total += calldataNonZeroByteGas * blockContextByteSize
264264

265265
// sload
266-
total += 2100 * numL1Messages // numL1Messages times cold sload in L1MessageQueue
266+
total += coldSloadGas * numL1Messages // numL1Messages times cold sload in L1MessageQueue
267267

268268
// staticcall
269-
total += 100 * numL1Messages // numL1Messages times call to L1MessageQueue
270-
total += 100 * numL1Messages // numL1Messages times warm address access to L1MessageQueue
269+
total += warmAddressAccessGas * numL1Messages // numL1Messages times call to L1MessageQueue
270+
total += warmAddressAccessGas * numL1Messages // numL1Messages times warm address access to L1MessageQueue
271271

272-
total += getMemoryExpansionCost(36) * numL1Messages // staticcall to proxy
273-
total += 100 * numL1Messages // read admin in proxy
274-
total += 100 * numL1Messages // read impl in proxy
275-
total += 100 * numL1Messages // access impl
276-
total += getMemoryExpansionCost(36) * numL1Messages // delegatecall to impl
272+
total += getMemoryExpansionCost(functionSignatureBytes+defaultParameterBytes) * numL1Messages // staticcall to proxy
273+
total += warmAddressAccessGas * numL1Messages // read admin in proxy
274+
total += warmAddressAccessGas * numL1Messages // read impl in proxy
275+
total += warmAddressAccessGas * numL1Messages // access impl
276+
total += getMemoryExpansionCost(functionSignatureBytes+defaultParameterBytes) * numL1Messages // delegatecall to impl
277277

278278
return total, nil
279279
}
@@ -305,10 +305,10 @@ func (d *DACodecV0) EstimateChunkL1CommitGas(c *Chunk) (uint64, error) {
305305
}
306306

307307
numBlocks := uint64(len(c.Blocks))
308-
totalL1CommitGas += 100 * numBlocks // numBlocks times warm sload
309-
totalL1CommitGas += calldataNonZeroByteGas // numBlocks field of chunk encoding in calldata
308+
totalL1CommitGas += warmSloadGas * numBlocks // numBlocks times warm sload
309+
totalL1CommitGas += calldataNonZeroByteGas // numBlocks field of chunk encoding in calldata
310310

311-
totalL1CommitGas += getKeccak256Gas(58*numBlocks + 32*totalTxNum) // chunk hash
311+
totalL1CommitGas += getKeccak256Gas(blockContextBytesForHashing*numBlocks + common.HashLength*totalTxNum) // chunk hash
312312
return totalL1CommitGas, nil
313313
}
314314

@@ -317,22 +317,22 @@ func (d *DACodecV0) EstimateBatchL1CommitGas(b *Batch) (uint64, error) {
317317
var totalL1CommitGas uint64
318318

319319
// Add extra gas costs
320-
totalL1CommitGas += 100000 // constant to account for ops like _getAdmin, _implementation, _requireNotPaused, etc
321-
totalL1CommitGas += 4 * 2100 // 4 one-time cold sload for commitBatch
322-
totalL1CommitGas += 20000 // 1 time sstore
323-
totalL1CommitGas += 21000 // base fee for tx
320+
totalL1CommitGas += extraGasCost // constant to account for ops like _getAdmin, _implementation, _requireNotPaused, etc
321+
totalL1CommitGas += 4 * coldSloadGas // 4 one-time cold sload for commitBatch
322+
totalL1CommitGas += sstoreGas // 1 time sstore
323+
totalL1CommitGas += baseTxGas // base gas for tx
324324
totalL1CommitGas += calldataNonZeroByteGas // version in calldata
325325

326326
// adjusting gas:
327327
// add 1 time cold sload (2100 gas) for L1MessageQueue
328328
// add 1 time cold address access (2600 gas) for L1MessageQueue
329329
// minus 1 time warm sload (100 gas) & 1 time warm address access (100 gas)
330-
totalL1CommitGas += (2100 + 2600 - 100 - 100)
331-
totalL1CommitGas += getKeccak256Gas(89 + 32) // parent batch header hash, length is estimated as 89 (constant part)+ 32 (1 skippedL1MessageBitmap)
332-
totalL1CommitGas += calldataNonZeroByteGas * (89 + 32) // parent batch header in calldata
330+
totalL1CommitGas += (coldSloadGas + coldAddressAccessGas - warmSloadGas - warmAddressAccessGas)
331+
totalL1CommitGas += getKeccak256Gas(daBatchV0EncodedMinLength + skippedL1MessageBitmapByteSize) // parent batch header hash, length is estimated as (constant part) + (1 skippedL1MessageBitmap)
332+
totalL1CommitGas += calldataNonZeroByteGas * (daBatchV0EncodedMinLength + skippedL1MessageBitmapByteSize) // parent batch header in calldata
333333

334334
// adjust batch data hash gas cost
335-
totalL1CommitGas += getKeccak256Gas(uint64(32 * len(b.Chunks)))
335+
totalL1CommitGas += getKeccak256Gas(uint64(common.HashLength * len(b.Chunks)))
336336

337337
totalL1MessagePoppedBefore := b.TotalL1MessagePoppedBefore
338338

@@ -346,8 +346,8 @@ func (d *DACodecV0) EstimateBatchL1CommitGas(b *Batch) (uint64, error) {
346346
totalL1MessagePoppedInChunk := chunk.NumL1Messages(totalL1MessagePoppedBefore)
347347
totalL1MessagePoppedBefore += totalL1MessagePoppedInChunk
348348

349-
totalL1CommitGas += calldataNonZeroByteGas * (32 * (totalL1MessagePoppedInChunk + 255) / 256)
350-
totalL1CommitGas += getKeccak256Gas(89 + 32*(totalL1MessagePoppedInChunk+255)/256)
349+
totalL1CommitGas += calldataNonZeroByteGas * (skippedL1MessageBitmapByteSize * (totalL1MessagePoppedInChunk + 255) / 256)
350+
totalL1CommitGas += getKeccak256Gas(daBatchV0EncodedMinLength + skippedL1MessageBitmapByteSize*(totalL1MessagePoppedInChunk+255)/256)
351351

352352
chunkL1CommitCalldataSize, err := d.EstimateChunkL1CommitCalldataSize(chunk)
353353
if err != nil {

encoding/codecv0_types.go

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ import (
1313
"github.com/scroll-tech/go-ethereum/crypto/kzg4844"
1414
)
1515

16+
const (
17+
numberOffset = 0
18+
timestampOffset = numberOffset + 8
19+
baseFeeOffset = timestampOffset + 8
20+
gasLimitOffset = baseFeeOffset + 32
21+
numTransactionsOffset = gasLimitOffset + 8
22+
numL1MessagesOffset = numTransactionsOffset + 2
23+
)
24+
1625
// daBlockV0 represents a Data Availability Block.
1726
type daBlockV0 struct {
1827
number uint64
@@ -38,14 +47,14 @@ func newDABlockV0(number uint64, timestamp uint64, baseFee *big.Int, gasLimit ui
3847
// Encode serializes the DABlock into a slice of bytes.
3948
func (b *daBlockV0) Encode() []byte {
4049
bytes := make([]byte, blockContextByteSize)
41-
binary.BigEndian.PutUint64(bytes[0:], b.number)
42-
binary.BigEndian.PutUint64(bytes[8:], b.timestamp)
50+
binary.BigEndian.PutUint64(bytes[numberOffset:timestampOffset], b.number)
51+
binary.BigEndian.PutUint64(bytes[timestampOffset:baseFeeOffset], b.timestamp)
4352
if b.baseFee != nil {
44-
binary.BigEndian.PutUint64(bytes[40:], b.baseFee.Uint64())
53+
b.baseFee.FillBytes(bytes[baseFeeOffset:gasLimitOffset])
4554
}
46-
binary.BigEndian.PutUint64(bytes[48:], b.gasLimit)
47-
binary.BigEndian.PutUint16(bytes[56:], b.numTransactions)
48-
binary.BigEndian.PutUint16(bytes[58:], b.numL1Messages)
55+
binary.BigEndian.PutUint64(bytes[gasLimitOffset:numTransactionsOffset], b.gasLimit)
56+
binary.BigEndian.PutUint16(bytes[numTransactionsOffset:numL1MessagesOffset], b.numTransactions)
57+
binary.BigEndian.PutUint16(bytes[numL1MessagesOffset:], b.numL1Messages)
4958
return bytes
5059
}
5160

@@ -55,12 +64,12 @@ func (b *daBlockV0) Decode(bytes []byte) error {
5564
return errors.New("block encoding is not blockContextByteSize bytes long")
5665
}
5766

58-
b.number = binary.BigEndian.Uint64(bytes[0:8])
59-
b.timestamp = binary.BigEndian.Uint64(bytes[8:16])
60-
b.baseFee = new(big.Int).SetUint64(binary.BigEndian.Uint64(bytes[40:48]))
61-
b.gasLimit = binary.BigEndian.Uint64(bytes[48:56])
62-
b.numTransactions = binary.BigEndian.Uint16(bytes[56:58])
63-
b.numL1Messages = binary.BigEndian.Uint16(bytes[58:60])
67+
b.number = binary.BigEndian.Uint64(bytes[numberOffset:timestampOffset])
68+
b.timestamp = binary.BigEndian.Uint64(bytes[timestampOffset:baseFeeOffset])
69+
b.baseFee = new(big.Int).SetBytes(bytes[baseFeeOffset:gasLimitOffset])
70+
b.gasLimit = binary.BigEndian.Uint64(bytes[gasLimitOffset:numTransactionsOffset])
71+
b.numTransactions = binary.BigEndian.Uint16(bytes[numTransactionsOffset:numL1MessagesOffset])
72+
b.numL1Messages = binary.BigEndian.Uint16(bytes[numL1MessagesOffset:])
6473

6574
return nil
6675
}
@@ -163,7 +172,7 @@ func (c *daChunkV0) Hash() (common.Hash, error) {
163172
var dataBytes []byte
164173
for i := 0; i < int(numBlocks); i++ {
165174
start := 1 + blockContextByteSize*i
166-
end := start + blockContextByteSize - 2 // last 2 bytes of each BlockContext are not used in hashing
175+
end := start + blockContextBytesForHashing
167176
if end > len(chunkBytes) {
168177
return common.Hash{}, fmt.Errorf("unexpected end index: %d, chunkBytes length: %d", end, len(chunkBytes))
169178
}

encoding/codecv1.go

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func (d *DACodecV1) constructBlobPayload(chunks []*Chunk, maxNumChunksPerBatch i
157157

158158
// challenge digest preimage
159159
// 1 hash for metadata, 1 hash for each chunk, 1 hash for blob versioned hash
160-
challengePreimage := make([]byte, (1+maxNumChunksPerBatch+1)*32)
160+
challengePreimage := make([]byte, (1+maxNumChunksPerBatch+1)*common.HashLength)
161161

162162
// the chunk data hash used for calculating the challenge preimage
163163
var chunkDataHash common.Hash
@@ -191,15 +191,15 @@ func (d *DACodecV1) constructBlobPayload(chunks []*Chunk, maxNumChunksPerBatch i
191191

192192
// challenge: compute chunk data hash
193193
chunkDataHash = crypto.Keccak256Hash(blobBytes[currentChunkStartIndex:])
194-
copy(challengePreimage[32+chunkID*32:], chunkDataHash[:])
194+
copy(challengePreimage[common.HashLength+chunkID*common.HashLength:], chunkDataHash[:])
195195
}
196196

197197
// if we have fewer than maxNumChunksPerBatch chunks, the rest
198198
// of the blob metadata is correctly initialized to 0,
199199
// but we need to add padding to the challenge preimage
200200
for chunkID := len(chunks); chunkID < maxNumChunksPerBatch; chunkID++ {
201201
// use the last chunk's data hash as padding
202-
copy(challengePreimage[32+chunkID*32:], chunkDataHash[:])
202+
copy(challengePreimage[common.HashLength+chunkID*common.HashLength:], chunkDataHash[:])
203203
}
204204

205205
// challenge: compute metadata hash
@@ -220,7 +220,7 @@ func (d *DACodecV1) constructBlobPayload(chunks []*Chunk, maxNumChunksPerBatch i
220220
blobVersionedHash := kzg4844.CalcBlobHashV1(sha256.New(), &c)
221221

222222
// challenge: append blob versioned hash
223-
copy(challengePreimage[(1+maxNumChunksPerBatch)*32:], blobVersionedHash[:])
223+
copy(challengePreimage[(1+maxNumChunksPerBatch)*common.HashLength:], blobVersionedHash[:])
224224

225225
// compute z = challenge_digest % BLS_MODULUS
226226
challengeDigest := crypto.Keccak256Hash(challengePreimage)
@@ -295,17 +295,17 @@ func (d *DACodecV1) EstimateBlockL1CommitGas(b *Block) (uint64, error) {
295295
total += calldataNonZeroByteGas * blockContextByteSize
296296

297297
// sload
298-
total += 2100 * numL1Messages // numL1Messages times cold sload in L1MessageQueue
298+
total += coldSloadGas * numL1Messages // numL1Messages times cold sload in L1MessageQueue
299299

300300
// staticcall
301-
total += 100 * numL1Messages // numL1Messages times call to L1MessageQueue
302-
total += 100 * numL1Messages // numL1Messages times warm address access to L1MessageQueue
301+
total += warmAddressAccessGas * numL1Messages // numL1Messages times call to L1MessageQueue
302+
total += warmAddressAccessGas * numL1Messages // numL1Messages times warm address access to L1MessageQueue
303303

304-
total += getMemoryExpansionCost(36) * numL1Messages // staticcall to proxy
305-
total += 100 * numL1Messages // read admin in proxy
306-
total += 100 * numL1Messages // read impl in proxy
307-
total += 100 * numL1Messages // access impl
308-
total += getMemoryExpansionCost(36) * numL1Messages // delegatecall to impl
304+
total += getMemoryExpansionCost(functionSignatureBytes+defaultParameterBytes) * numL1Messages // staticcall to proxy
305+
total += warmAddressAccessGas * numL1Messages // read admin in proxy
306+
total += warmAddressAccessGas * numL1Messages // read impl in proxy
307+
total += warmAddressAccessGas * numL1Messages // access impl
308+
total += getMemoryExpansionCost(functionSignatureBytes+defaultParameterBytes) * numL1Messages // delegatecall to impl
309309

310310
return total, nil
311311
}
@@ -329,10 +329,10 @@ func (d *DACodecV1) EstimateChunkL1CommitGas(c *Chunk) (uint64, error) {
329329
}
330330

331331
numBlocks := uint64(len(c.Blocks))
332-
totalL1CommitGas += 100 * numBlocks // numBlocks times warm sload
333-
totalL1CommitGas += calldataNonZeroByteGas // numBlocks field of chunk encoding in calldata
332+
totalL1CommitGas += warmSloadGas * numBlocks // numBlocks times warm sload
333+
totalL1CommitGas += calldataNonZeroByteGas // numBlocks field of chunk encoding in calldata
334334

335-
totalL1CommitGas += getKeccak256Gas(58*numBlocks + 32*totalNonSkippedL1Messages) // chunk hash
335+
totalL1CommitGas += getKeccak256Gas(58*numBlocks + common.HashLength*totalNonSkippedL1Messages) // chunk hash
336336
return totalL1CommitGas, nil
337337
}
338338

@@ -341,22 +341,22 @@ func (d *DACodecV1) EstimateBatchL1CommitGas(b *Batch) (uint64, error) {
341341
var totalL1CommitGas uint64
342342

343343
// Add extra gas costs
344-
totalL1CommitGas += 100000 // constant to account for ops like _getAdmin, _implementation, _requireNotPaused, etc
345-
totalL1CommitGas += 4 * 2100 // 4 one-time cold sload for commitBatch
346-
totalL1CommitGas += 20000 // 1 time sstore
347-
totalL1CommitGas += 21000 // base fee for tx
344+
totalL1CommitGas += extraGasCost // constant to account for ops like _getAdmin, _implementation, _requireNotPaused, etc
345+
totalL1CommitGas += 4 * coldSloadGas // 4 one-time cold sload for commitBatch
346+
totalL1CommitGas += sstoreGas // 1 time sstore
347+
totalL1CommitGas += baseTxGas // base gas for tx
348348
totalL1CommitGas += calldataNonZeroByteGas // version in calldata
349349

350350
// adjusting gas:
351351
// add 1 time cold sload (2100 gas) for L1MessageQueue
352352
// add 1 time cold address access (2600 gas) for L1MessageQueue
353353
// minus 1 time warm sload (100 gas) & 1 time warm address access (100 gas)
354-
totalL1CommitGas += (2100 + 2600 - 100 - 100)
355-
totalL1CommitGas += getKeccak256Gas(89 + 32) // parent batch header hash, length is estimated as 89 (constant part)+ 32 (1 skippedL1MessageBitmap)
356-
totalL1CommitGas += calldataNonZeroByteGas * (89 + 32) // parent batch header in calldata
354+
totalL1CommitGas += (coldSloadGas + coldAddressAccessGas - warmSloadGas - warmAddressAccessGas)
355+
totalL1CommitGas += getKeccak256Gas(daBatchV0EncodedMinLength + skippedL1MessageBitmapByteSize) // parent batch header hash, length is estimated as (constant part) + (1 skippedL1MessageBitmap)
356+
totalL1CommitGas += calldataNonZeroByteGas * (daBatchV0EncodedMinLength + skippedL1MessageBitmapByteSize) // parent batch header in calldata
357357

358358
// adjust batch data hash gas cost
359-
totalL1CommitGas += getKeccak256Gas(uint64(32 * len(b.Chunks)))
359+
totalL1CommitGas += getKeccak256Gas(uint64(common.HashLength * len(b.Chunks)))
360360

361361
totalL1MessagePoppedBefore := b.TotalL1MessagePoppedBefore
362362

@@ -370,8 +370,8 @@ func (d *DACodecV1) EstimateBatchL1CommitGas(b *Batch) (uint64, error) {
370370
totalL1MessagePoppedInChunk := chunk.NumL1Messages(totalL1MessagePoppedBefore)
371371
totalL1MessagePoppedBefore += totalL1MessagePoppedInChunk
372372

373-
totalL1CommitGas += calldataNonZeroByteGas * (32 * (totalL1MessagePoppedInChunk + 255) / 256)
374-
totalL1CommitGas += getKeccak256Gas(89 + 32*(totalL1MessagePoppedInChunk+255)/256)
373+
totalL1CommitGas += calldataNonZeroByteGas * (skippedL1MessageBitmapByteSize * (totalL1MessagePoppedInChunk + 255) / 256)
374+
totalL1CommitGas += getKeccak256Gas(daBatchV3OffsetParentBatchHash + skippedL1MessageBitmapByteSize*(totalL1MessagePoppedInChunk+255)/256)
375375

376376
chunkL1CommitCalldataSize, err := d.EstimateChunkL1CommitCalldataSize(chunk)
377377
if err != nil {

encoding/codecv1_types.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ func (c *daChunkV1) Hash() (common.Hash, error) {
4343
// concatenate block contexts
4444
for _, block := range c.blocks {
4545
encodedBlock := block.Encode()
46-
// only the first 58 bytes are used in the hashing process
47-
dataBytes = append(dataBytes, encodedBlock[:58]...)
46+
dataBytes = append(dataBytes, encodedBlock[:blockContextBytesForHashing]...)
4847
}
4948

5049
// concatenate l1 tx hashes

encoding/codecv2.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func (d *DACodecV2) constructBlobPayload(chunks []*Chunk, maxNumChunksPerBatch i
104104

105105
// challenge digest preimage
106106
// 1 hash for metadata, 1 hash for each chunk, 1 hash for blob versioned hash
107-
challengePreimage := make([]byte, (1+maxNumChunksPerBatch+1)*32)
107+
challengePreimage := make([]byte, (1+maxNumChunksPerBatch+1)*common.HashLength)
108108

109109
// the chunk data hash used for calculating the challenge preimage
110110
var chunkDataHash common.Hash
@@ -138,15 +138,15 @@ func (d *DACodecV2) constructBlobPayload(chunks []*Chunk, maxNumChunksPerBatch i
138138

139139
// challenge: compute chunk data hash
140140
chunkDataHash = crypto.Keccak256Hash(batchBytes[currentChunkStartIndex:])
141-
copy(challengePreimage[32+chunkID*32:], chunkDataHash[:])
141+
copy(challengePreimage[common.HashLength+chunkID*common.HashLength:], chunkDataHash[:])
142142
}
143143

144144
// if we have fewer than maxNumChunksPerBatch chunks, the rest
145145
// of the blob metadata is correctly initialized to 0,
146146
// but we need to add padding to the challenge preimage
147147
for chunkID := len(chunks); chunkID < maxNumChunksPerBatch; chunkID++ {
148148
// use the last chunk's data hash as padding
149-
copy(challengePreimage[32+chunkID*32:], chunkDataHash[:])
149+
copy(challengePreimage[common.HashLength+chunkID*common.HashLength:], chunkDataHash[:])
150150
}
151151

152152
// challenge: compute metadata hash
@@ -187,7 +187,7 @@ func (d *DACodecV2) constructBlobPayload(chunks []*Chunk, maxNumChunksPerBatch i
187187
blobVersionedHash := kzg4844.CalcBlobHashV1(sha256.New(), &c)
188188

189189
// challenge: append blob versioned hash
190-
copy(challengePreimage[(1+maxNumChunksPerBatch)*32:], blobVersionedHash[:])
190+
copy(challengePreimage[(1+maxNumChunksPerBatch)*common.HashLength:], blobVersionedHash[:])
191191

192192
// compute z = challenge_digest % BLS_MODULUS
193193
challengeDigest := crypto.Keccak256Hash(challengePreimage)

0 commit comments

Comments
 (0)