Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: abstract codec versions into common interfaces #25

Merged
merged 128 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from 119 commits
Commits
Show all changes
128 commits
Select commit Hold shift + click to select a range
ad42cd9
feat: support conditional encode
colinlyguo Aug 14, 2024
62758c8
move append conditionalEncode flag after validity check
colinlyguo Aug 14, 2024
6901956
update da-codec
colinlyguo Aug 18, 2024
e4bf12e
align naming
colinlyguo Aug 18, 2024
030349d
add ConvertBlobToBlobBytes utility functions
colinlyguo Aug 19, 2024
ed4de9e
kept blob bytes
colinlyguo Aug 19, 2024
c6af3bb
rename enableEncode to enableCompress
colinlyguo Aug 19, 2024
a5691d4
refactor: move some common functions to encoding (#24)
colinlyguo Aug 20, 2024
9532963
move symbol replace script to zstd folder
colinlyguo Aug 20, 2024
990bdb3
refactor: move some util functions to public package
colinlyguo Aug 20, 2024
6b86866
fix CI
colinlyguo Aug 20, 2024
3ad692a
add interfaces of codec
colinlyguo Aug 20, 2024
a5c6430
add SetCompression
colinlyguo Aug 20, 2024
43f56e6
move interface to encoding
colinlyguo Aug 20, 2024
cd280de
refactor
colinlyguo Aug 20, 2024
879bb98
add dablock.go
colinlyguo Aug 21, 2024
77aafd4
add dachunk.go
colinlyguo Aug 21, 2024
6ee5c19
add dabatch.go
colinlyguo Aug 21, 2024
79422a2
move computeBatchDataHash to codecv
colinlyguo Aug 21, 2024
296880e
fix
colinlyguo Aug 21, 2024
c038850
add DABatchBase
colinlyguo Aug 21, 2024
4499e2c
add GetCodecVersion
colinlyguo Aug 21, 2024
8e763dd
add BlobVersionedHashes
colinlyguo Aug 21, 2024
98d5635
rename encoding.go to interfaces.go
colinlyguo Aug 22, 2024
bdb98f8
add NewDABatchWithExpectedBlobVersionedHashes
colinlyguo Aug 22, 2024
f3f0fbd
Merge branch 'main' into refactor-move-some-util-functions-to-public-…
colinlyguo Aug 22, 2024
08d60a3
tweak
colinlyguo Aug 22, 2024
2d425d8
fix a bug
colinlyguo Aug 24, 2024
c1e4a0d
add more logs
colinlyguo Aug 24, 2024
e5df846
add DecodeDAChunks
colinlyguo Sep 5, 2024
ecaca71
add BlockRange interface
colinlyguo Sep 5, 2024
484fa59
fix
colinlyguo Sep 5, 2024
f1fe4c8
add version check
colinlyguo Sep 5, 2024
97711e2
add Version
colinlyguo Sep 5, 2024
2a63797
remove DABatchBase
colinlyguo Sep 5, 2024
87c4537
add DABlock
colinlyguo Sep 5, 2024
2ac7825
fixes
colinlyguo Sep 5, 2024
8a6c35f
fix
colinlyguo Sep 5, 2024
83f6b62
add CodecFromVersion and CodecFromConfig
colinlyguo Sep 5, 2024
c4a2495
remove GetCodecVersion
colinlyguo Sep 5, 2024
10af8e7
fix typos
colinlyguo Sep 18, 2024
1594e0f
make Block fields internal
colinlyguo Sep 22, 2024
1f9facd
make chunk fields internal
colinlyguo Sep 22, 2024
451eb68
make batch fields internal and add some tweaks
colinlyguo Sep 22, 2024
955f375
add JSONFromBytes
colinlyguo Sep 22, 2024
f73c63e
fix a typo
colinlyguo Sep 30, 2024
cf9f084
use register mode
colinlyguo Oct 1, 2024
5ef6c5f
Merge branch 'main' into refactor-move-some-util-functions-to-public-…
colinlyguo Oct 3, 2024
7eb1dc0
fix CI
colinlyguo Oct 3, 2024
91ac897
remove register mode
colinlyguo Oct 4, 2024
e6c8965
add common functions
colinlyguo Oct 5, 2024
ba853e3
add EstimateBlockL1CommitCalldataSize
colinlyguo Oct 5, 2024
aca0bef
add dabatch interfaces
colinlyguo Oct 5, 2024
95d2bc7
update interface implementations
colinlyguo Oct 6, 2024
75812c4
add data hash
colinlyguo Oct 6, 2024
78588e4
fix codecv3 & codecv4 estimate gas
colinlyguo Oct 7, 2024
45548e1
fix
colinlyguo Oct 7, 2024
4469219
fix bugs
colinlyguo Oct 7, 2024
6934f3d
tweak
colinlyguo Oct 7, 2024
0079225
add CheckChunkCompressedDataCompatibility & CheckBatchCompressedDataC…
colinlyguo Oct 7, 2024
3f774d2
fix
colinlyguo Oct 7, 2024
669b454
add BlobDataProofForPointEvaluation
colinlyguo Oct 7, 2024
09127a5
add nil check in NewDAChunk
colinlyguo Oct 10, 2024
1c519d6
make some util functions internal
colinlyguo Oct 11, 2024
d2350ff
remove GetMaxChunksPerBatch
colinlyguo Oct 11, 2024
b885af8
fix CI
colinlyguo Oct 11, 2024
986850d
change receiver mark from o to d
colinlyguo Oct 11, 2024
e222406
remove SetCompression
colinlyguo Oct 11, 2024
ef5ea6e
fix
colinlyguo Oct 11, 2024
9d9fd89
add GetChunkEnableCompression & GetBatchEnableCompression
colinlyguo Oct 11, 2024
df76a9d
fix
colinlyguo Oct 11, 2024
6e28644
update l2geth dependency
colinlyguo Oct 11, 2024
233b006
make types internal
colinlyguo Oct 11, 2024
8dbf796
embed codecv0 <- codecv1 <- codecv2 <- codecv3 <- codecv4
colinlyguo Oct 11, 2024
7891503
remove dablock.go dachunk.go dabatch.go
colinlyguo Oct 11, 2024
2703f22
trigger ci
colinlyguo Oct 14, 2024
443f126
tweak
colinlyguo Oct 14, 2024
db77317
tweaks
colinlyguo Oct 15, 2024
05e42d9
add back TxsToTxsData
colinlyguo Oct 15, 2024
35a7d9b
fix
colinlyguo Oct 15, 2024
1ab5de1
fix
colinlyguo Oct 15, 2024
ca48609
fix
colinlyguo Oct 15, 2024
7a81bc2
fix
colinlyguo Oct 15, 2024
ca3a6d4
fix
colinlyguo Oct 15, 2024
e36ee98
fix
colinlyguo Oct 15, 2024
931bb50
tweak
colinlyguo Oct 15, 2024
5c3c055
add back test block encode and test chunk encode unit tests
colinlyguo Oct 15, 2024
3e092dd
replace some constants with meaningful vars
colinlyguo Oct 16, 2024
558d029
rename daBatchV2 to daBatchV3
colinlyguo Oct 16, 2024
24da905
add chunk hash unit tests
colinlyguo Oct 16, 2024
aa46689
add batch encode
colinlyguo Oct 16, 2024
22c3772
add batch hash unit tests
colinlyguo Oct 16, 2024
86a2092
add batch data hash & json marshal unit tests
colinlyguo Oct 16, 2024
99231ac
add calldata size unit tests
colinlyguo Oct 16, 2024
c62b2d0
add commit gas estimation
colinlyguo Oct 16, 2024
7df1b27
add BatchSizeAndBlobSizeEstimation unit tests
colinlyguo Oct 16, 2024
f3cb3a2
add L1MessagePopped unit tests
colinlyguo Oct 16, 2024
4709903
add BlobEncodingAndHashing unit tests
colinlyguo Oct 16, 2024
ec82682
add blob data proof unit tests
colinlyguo Oct 16, 2024
d69f8cc
add TestDecodeBitmap
colinlyguo Oct 16, 2024
79ee6f7
add BlobCompressDecompress unit tests
colinlyguo Oct 16, 2024
d9c8119
tweaks and bug fixes
colinlyguo Oct 16, 2024
386a24e
fix goimport
colinlyguo Oct 16, 2024
5135ec3
add StandardTestCases
colinlyguo Oct 16, 2024
87e3f15
edge cases
colinlyguo Oct 16, 2024
6eb38e5
fixes
colinlyguo Oct 16, 2024
8432d41
address ai's comments
colinlyguo Oct 16, 2024
54ddf8d
address ai's comments
colinlyguo Oct 16, 2024
c89d7ae
address ai's comments
colinlyguo Oct 16, 2024
5aa90e8
address comments
colinlyguo Oct 17, 2024
901e082
address ai's comment
colinlyguo Oct 17, 2024
1eea8ce
remove some constants
colinlyguo Oct 17, 2024
1452109
address comments
colinlyguo Oct 17, 2024
43824ff
add more logs
colinlyguo Oct 17, 2024
886365d
address comments
colinlyguo Oct 17, 2024
4f78d1a
address comments
colinlyguo Oct 17, 2024
ef5f1a6
address comments
colinlyguo Oct 17, 2024
3faa778
address comments
colinlyguo Oct 18, 2024
1e07a66
add simple and nil functions unit tests
colinlyguo Oct 18, 2024
24eb594
add uncompressed case unit tests of DecodeTxsFromBlob
colinlyguo Oct 18, 2024
4b5b636
add interface unit tests
colinlyguo Oct 18, 2024
e18a147
add codecv2 & codecv3 CompressedDataCompatibilityCheck unit tests
colinlyguo Oct 18, 2024
42af292
remove mock flag
colinlyguo Oct 18, 2024
e6cfa7d
add JSONFromBytes unit tests
colinlyguo Oct 18, 2024
102d4a3
add codecv4 CompressedDataCompatibilityCheck unit tests
colinlyguo Oct 18, 2024
715e673
add NewDABatchFromBytes unit tests
colinlyguo Oct 18, 2024
60b9362
fix golint
colinlyguo Oct 18, 2024
0e831aa
tweaks
colinlyguo Oct 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 11 additions & 21 deletions encoding/bitmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"github.com/scroll-tech/go-ethereum/core/types"
)

// ConstructSkippedBitmap constructs skipped L1 message bitmap of the batch.
func ConstructSkippedBitmap(batchIndex uint64, chunks []*Chunk, totalL1MessagePoppedBefore uint64) ([]byte, uint64, error) {
// constructSkippedBitmap constructs skipped L1 message bitmap of the batch.
func constructSkippedBitmap(batchIndex uint64, chunks []*Chunk, totalL1MessagePoppedBefore uint64) ([]byte, uint64, error) {
// skipped L1 message bitmap, an array of 256-bit bitmaps
var skippedBitmap []*big.Int

Expand Down Expand Up @@ -54,39 +54,29 @@ func ConstructSkippedBitmap(batchIndex uint64, chunks []*Chunk, totalL1MessagePo
}
}

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

return bitmapBytes, nextIndex, nil
}

// DecodeBitmap decodes skipped L1 message bitmap of the batch from bytes to big.Int's
func DecodeBitmap(skippedL1MessageBitmap []byte, totalL1MessagePopped int) ([]*big.Int, error) {
// decodeBitmap decodes skipped L1 message bitmap of the batch from bytes to big.Int's.
func decodeBitmap(skippedL1MessageBitmap []byte, totalL1MessagePopped int) ([]*big.Int, error) {
length := len(skippedL1MessageBitmap)
if length%32 != 0 {
return nil, fmt.Errorf("skippedL1MessageBitmap length doesn't match, skippedL1MessageBitmap length should be equal 0 modulo 32, length of skippedL1MessageBitmap: %v", length)
if length%skippedL1MessageBitmapByteSize != 0 {
return nil, fmt.Errorf("skippedL1MessageBitmap length doesn't match, skippedL1MessageBitmap length should be equal 0 modulo %v, length of skippedL1MessageBitmap: %v", skippedL1MessageBitmapByteSize, length)
}
if length*8 < totalL1MessagePopped {
return nil, fmt.Errorf("skippedL1MessageBitmap length is too small, skippedL1MessageBitmap length should be at least %v, length of skippedL1MessageBitmap: %v", (totalL1MessagePopped+7)/8, length)
}
var skippedBitmap []*big.Int
for index := 0; index < length/32; index++ {
bitmap := big.NewInt(0).SetBytes(skippedL1MessageBitmap[index*32 : index*32+32])
for index := 0; index < length/skippedL1MessageBitmapByteSize; index++ {
bitmap := big.NewInt(0).SetBytes(skippedL1MessageBitmap[index*skippedL1MessageBitmapByteSize : index*skippedL1MessageBitmapByteSize+skippedL1MessageBitmapByteSize])
skippedBitmap = append(skippedBitmap, bitmap)
}
return skippedBitmap, nil
}

// IsL1MessageSkipped checks if index is skipped in bitmap
func IsL1MessageSkipped(skippedBitmap []*big.Int, index uint64) bool {
if index > uint64(len(skippedBitmap))*256 {
return false
}
quo := index / 256
rem := index % 256
return skippedBitmap[quo].Bit(int(rem)) != 0
}
44 changes: 44 additions & 0 deletions encoding/bitmap_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package encoding

import (
"encoding/hex"
"math/big"
"testing"

"github.com/stretchr/testify/assert"
)

func TestDecodeBitmap(t *testing.T) {
bitmapHex := "0000000000000000000000000000000000000000000000000000001ffffffbff"
skippedL1MessageBitmap, err := hex.DecodeString(bitmapHex)
assert.NoError(t, err)

decodedBitmap, err := decodeBitmap(skippedL1MessageBitmap, 42)
assert.NoError(t, err)

isL1MessageSkipped := func(skippedBitmap []*big.Int, index uint64) bool {
if index >= uint64(len(skippedBitmap))*256 {
return false
}
quo := index / 256
rem := index % 256
return skippedBitmap[quo].Bit(int(rem)) == 1
}

assert.True(t, isL1MessageSkipped(decodedBitmap, 0))
assert.True(t, isL1MessageSkipped(decodedBitmap, 9))
assert.False(t, isL1MessageSkipped(decodedBitmap, 10))
assert.True(t, isL1MessageSkipped(decodedBitmap, 11))
assert.True(t, isL1MessageSkipped(decodedBitmap, 36))
assert.False(t, isL1MessageSkipped(decodedBitmap, 37))
assert.False(t, isL1MessageSkipped(decodedBitmap, 38))
assert.False(t, isL1MessageSkipped(decodedBitmap, 39))
assert.False(t, isL1MessageSkipped(decodedBitmap, 40))
assert.False(t, isL1MessageSkipped(decodedBitmap, 41))

_, err = decodeBitmap([]byte{0x00}, 8)
assert.Error(t, err)

_, err = decodeBitmap([]byte{0x00, 0x00, 0x00, 0x00}, 33)
assert.Error(t, err)
colinlyguo marked this conversation as resolved.
Show resolved Hide resolved
}
Loading
Loading