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

feat: support conditional compress #23

Merged
merged 12 commits into from
Aug 22, 2024
5 changes: 1 addition & 4 deletions encoding/codecv1/codecv1.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ import (
"github.com/scroll-tech/da-codec/encoding/codecv0"
)

// BLSModulus is the BLS modulus defined in EIP-4844.
var BLSModulus = new(big.Int).SetBytes(common.FromHex("0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001"))

// MaxNumChunks is the maximum number of chunks that a batch can contain.
const MaxNumChunks = 15

Expand Down Expand Up @@ -280,7 +277,7 @@ func constructBlobPayload(chunks []*encoding.Chunk, useMockTxData bool) (*kzg484

// compute z = challenge_digest % BLS_MODULUS
challengeDigest := crypto.Keccak256Hash(challengePreimage)
pointBigInt := new(big.Int).Mod(new(big.Int).SetBytes(challengeDigest[:]), BLSModulus)
pointBigInt := new(big.Int).Mod(new(big.Int).SetBytes(challengeDigest[:]), encoding.BLSModulus)
pointBytes := pointBigInt.Bytes()

// the challenge point z
Expand Down
10 changes: 6 additions & 4 deletions encoding/codecv2/codecv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ import (
"github.com/scroll-tech/da-codec/encoding/codecv1"
)

// BLSModulus is the BLS modulus defined in EIP-4844.
var BLSModulus = codecv1.BLSModulus

// MaxNumChunks is the maximum number of chunks that a batch can contain.
const MaxNumChunks = 45

Expand Down Expand Up @@ -193,6 +190,11 @@ func ConstructBlobPayload(chunks []*encoding.Chunk, useMockTxData bool) (*kzg484
}
}

if len(blobBytes) > 126976 {
log.Error("ConstructBlobPayload: Blob payload exceeds maximum size", "size", len(blobBytes), "blobBytes", hex.EncodeToString(blobBytes))
return nil, common.Hash{}, nil, errors.New("Blob payload exceeds maximum size")
}

// convert raw data to BLSFieldElements
blob, err := MakeBlobCanonical(blobBytes)
if err != nil {
Expand All @@ -211,7 +213,7 @@ func ConstructBlobPayload(chunks []*encoding.Chunk, useMockTxData bool) (*kzg484

// compute z = challenge_digest % BLS_MODULUS
challengeDigest := crypto.Keccak256Hash(challengePreimage)
pointBigInt := new(big.Int).Mod(new(big.Int).SetBytes(challengeDigest[:]), BLSModulus)
pointBigInt := new(big.Int).Mod(new(big.Int).SetBytes(challengeDigest[:]), encoding.BLSModulus)
pointBytes := pointBigInt.Bytes()

// the challenge point z
Expand Down
8 changes: 4 additions & 4 deletions encoding/codecv2/codecv2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,17 @@ func TestCodecV2BlockEncode(t *testing.T) {
encoded = hex.EncodeToString(block.Encode())
assert.Equal(t, "000000000000001100000000646b6ed0000000000000000000000000000000000000000000000000000000000000000000000000007a120001010101", encoded)

// sanity check: v0 and v1 block encodings are identical
// sanity check: v0 and v2 block encodings are identical
for _, trace := range []*encoding.Block{trace2, trace3, trace4, trace5, trace6, trace7} {
blockv0, err := codecv0.NewDABlock(trace, 0)
assert.NoError(t, err)
encodedv0 := hex.EncodeToString(blockv0.Encode())

blockv1, err := NewDABlock(trace, 0)
blockv2, err := NewDABlock(trace, 0)
assert.NoError(t, err)
encodedv1 := hex.EncodeToString(blockv1.Encode())
encodedv2 := hex.EncodeToString(blockv2.Encode())

assert.Equal(t, encodedv0, encodedv1)
assert.Equal(t, encodedv0, encodedv2)
}
}

Expand Down
8 changes: 4 additions & 4 deletions encoding/codecv3/codecv3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,17 @@ func TestCodecV3BlockEncode(t *testing.T) {
encoded = hex.EncodeToString(block.Encode())
assert.Equal(t, "000000000000001100000000646b6ed0000000000000000000000000000000000000000000000000000000000000000000000000007a120001010101", encoded)

// sanity check: v0 and v1 block encodings are identical
// sanity check: v0 and v3 block encodings are identical
for _, trace := range []*encoding.Block{trace2, trace3, trace4, trace5, trace6, trace7} {
blockv0, err := codecv0.NewDABlock(trace, 0)
assert.NoError(t, err)
encodedv0 := hex.EncodeToString(blockv0.Encode())

blockv1, err := NewDABlock(trace, 0)
blockv3, err := NewDABlock(trace, 0)
assert.NoError(t, err)
encodedv1 := hex.EncodeToString(blockv1.Encode())
encodedv3 := hex.EncodeToString(blockv3.Encode())

assert.Equal(t, encodedv0, encodedv1)
assert.Equal(t, encodedv0, encodedv3)
}
}

Expand Down
Loading
Loading