Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
2 changes: 1 addition & 1 deletion encoding/codecv7.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func (d *DACodecV7) checkCompressedDataCompatibility(payloadBytes []byte) ([]byt
return nil, false, fmt.Errorf("failed to compress blob payload: %w", err)
}

if err = checkCompressedDataCompatibility(compressedPayloadBytes); err != nil {
if err = checkCompressedDataCompatibilityV7(compressedPayloadBytes); err != nil {
log.Warn("Compressed data compatibility check failed", "err", err, "payloadBytes", hex.EncodeToString(payloadBytes), "compressedPayloadBytes", hex.EncodeToString(compressedPayloadBytes))
return nil, false, nil
}
Expand Down
24 changes: 0 additions & 24 deletions encoding/codecv7_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,18 +384,6 @@ func TestCodecV7BatchStandardTestCasesEnableCompression(t *testing.T) {
})
}

repeat := func(element byte, count int) string {
result := make([]byte, 0, count)
for i := 0; i < count; i++ {
result = append(result, element)
}
return "0x" + common.Bytes2Hex(result)
}

// Taking into consideration compression, we allow up to 5x of max blob bytes minus 5 byte for the blob envelope header.
// We subtract 74 bytes for the blobPayloadV7 metadata.
//compressableAvailableBytes := maxEffectiveBlobBytes*5 - 5 - blobPayloadV7MinEncodedLength
maxAvailableBytesCompressable := 5*maxEffectiveBlobBytes - 5 - blobPayloadV7MinEncodedLength
maxAvailableBytesIncompressable := maxEffectiveBlobBytes - 5 - blobPayloadV7MinEncodedLength
// 52 bytes for each block as per daBlockV7 encoding.
bytesPerBlock := 52
Expand Down Expand Up @@ -455,18 +443,6 @@ func TestCodecV7BatchStandardTestCasesEnableCompression(t *testing.T) {
txData: []string{generateRandomData(maxAvailableBytesIncompressable/2 - bytesPerBlock*2)},
expectedBlobVersionedHash: "0x017d7f0d569464b5c74175679e5f2bc880fcf5966c3e1928c9675c942b5274f0",
},
{
name: "single block, single tx, full blob repeat data",
numBlocks: 1,
txData: []string{repeat(0x12, maxAvailableBytesCompressable-bytesPerBlock)},
expectedBlobVersionedHash: "0x01f5d7bbfe7deb429bcbdd7347606359bca75cb93b9198e8f089b82e45f92b43",
},
{
name: "2 blocks, single 2, full blob random data",
numBlocks: 2,
txData: []string{repeat(0x12, maxAvailableBytesCompressable/2-bytesPerBlock*2), repeat(0x13, maxAvailableBytesCompressable/2-bytesPerBlock*2)},
expectedBlobVersionedHash: "0x01dccca3859640c50e0058fd42eaf14f942070e6497a4e2ba507b4546280a772",
},
{
name: "single block, single tx, full blob random data -> error because 1 byte too big",
numBlocks: 1,
Expand Down
46 changes: 46 additions & 0 deletions encoding/da.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,52 @@ func checkCompressedDataCompatibility(data []byte) error {
return nil
}

// Fast testing if the compressed data (v7) is compatible with our circuit
// (require specified frame header and each block is compressed)
func checkCompressedDataCompatibilityV7(data []byte) error {
if len(data) < 16 {
return fmt.Errorf("too small size (0x%x), what is it?", data)
}

fheader := data[0]
// it is not the encoding type we expected in our zstd header
if fheader&63 != 32 {
return fmt.Errorf("unexpected header type (%x)", fheader)
}

// skip content size
switch fheader >> 6 {
case 0:
data = data[2:]
case 1:
data = data[3:]
case 2:
data = data[5:]
case 3:
data = data[9:]
default:
panic("impossible")
}

isLast := false
// scan each block until done
for len(data) > 3 && !isLast {
isLast = (data[0] & 1) == 1
blkSize := (uint(data[2])*65536 + uint(data[1])*256 + uint(data[0])) >> 3
if len(data) < 3+int(blkSize) {
return fmt.Errorf("wrong data len {%d}, expect min {%d}", len(data), 3+blkSize)
}
data = data[3+blkSize:]
}

// Should we return invalid if isLast is still false?
if !isLast {
return fmt.Errorf("unexpected end before last block")
}

return nil
}

// makeBlobCanonical converts the raw blob data into the canonical blob representation of 4096 BLSFieldElements.
// The canonical blob representation is a 32-byte array where every 31 bytes are prepended with 1 zero byte.
// The kzg4844.Blob is a 4096-byte array, thus 0s are padded to the end of the array.
Expand Down