|
7 | 7 | "github.com/scroll-tech/go-ethereum/core/types" |
8 | 8 | ) |
9 | 9 |
|
10 | | -// ConstructSkippedBitmap constructs skipped L1 message bitmap of the batch. |
11 | | -func ConstructSkippedBitmap(batchIndex uint64, chunks []*Chunk, totalL1MessagePoppedBefore uint64) ([]byte, uint64, error) { |
| 10 | +// constructSkippedBitmap constructs skipped L1 message bitmap of the batch. |
| 11 | +func constructSkippedBitmap(batchIndex uint64, chunks []*Chunk, totalL1MessagePoppedBefore uint64) ([]byte, uint64, error) { |
12 | 12 | // skipped L1 message bitmap, an array of 256-bit bitmaps |
13 | 13 | var skippedBitmap []*big.Int |
14 | 14 |
|
@@ -54,39 +54,29 @@ func ConstructSkippedBitmap(batchIndex uint64, chunks []*Chunk, totalL1MessagePo |
54 | 54 | } |
55 | 55 | } |
56 | 56 |
|
57 | | - bitmapBytes := make([]byte, len(skippedBitmap)*32) |
| 57 | + skippedL1MessageBitmap := make([]byte, len(skippedBitmap)*skippedL1MessageBitmapByteSize) |
58 | 58 | for ii, num := range skippedBitmap { |
59 | 59 | bytes := num.Bytes() |
60 | | - padding := 32 - len(bytes) |
61 | | - copy(bitmapBytes[32*ii+padding:], bytes) |
| 60 | + padding := skippedL1MessageBitmapByteSize - len(bytes) |
| 61 | + copy(skippedL1MessageBitmap[skippedL1MessageBitmapByteSize*ii+padding:], bytes) |
62 | 62 | } |
63 | 63 |
|
64 | | - return bitmapBytes, nextIndex, nil |
| 64 | + return skippedL1MessageBitmap, nextIndex, nil |
65 | 65 | } |
66 | 66 |
|
67 | | -// DecodeBitmap decodes skipped L1 message bitmap of the batch from bytes to big.Int's |
68 | | -func DecodeBitmap(skippedL1MessageBitmap []byte, totalL1MessagePopped int) ([]*big.Int, error) { |
| 67 | +// decodeBitmap decodes skipped L1 message bitmap of the batch from bytes to big.Int's. |
| 68 | +func decodeBitmap(skippedL1MessageBitmap []byte, totalL1MessagePopped int) ([]*big.Int, error) { |
69 | 69 | 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) |
72 | 72 | } |
73 | 73 | if length*8 < totalL1MessagePopped { |
74 | 74 | return nil, fmt.Errorf("skippedL1MessageBitmap length is too small, skippedL1MessageBitmap length should be at least %v, length of skippedL1MessageBitmap: %v", (totalL1MessagePopped+7)/8, length) |
75 | 75 | } |
76 | 76 | 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]) |
79 | 79 | skippedBitmap = append(skippedBitmap, bitmap) |
80 | 80 | } |
81 | 81 | return skippedBitmap, nil |
82 | 82 | } |
83 | | - |
84 | | -// IsL1MessageSkipped checks if index is skipped in bitmap |
85 | | -func IsL1MessageSkipped(skippedBitmap []*big.Int, index uint64) bool { |
86 | | - if index > uint64(len(skippedBitmap))*256 { |
87 | | - return false |
88 | | - } |
89 | | - quo := index / 256 |
90 | | - rem := index % 256 |
91 | | - return skippedBitmap[quo].Bit(int(rem)) != 0 |
92 | | -} |
0 commit comments