Skip to content

Commit 0247443

Browse files
committed
add challenge digest computation for batch
1 parent 32f5b49 commit 0247443

File tree

2 files changed

+121
-2
lines changed

2 files changed

+121
-2
lines changed

encoding/codecv7_test.go

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/scroll-tech/go-ethereum/common"
1414
"github.com/scroll-tech/go-ethereum/common/hexutil"
1515
"github.com/scroll-tech/go-ethereum/core/types"
16+
"github.com/stretchr/testify/assert"
1617
"github.com/stretchr/testify/require"
1718
)
1819

@@ -831,6 +832,101 @@ func TestDACodecV7JSONFromBytes(t *testing.T) {
831832
}
832833
}
833834

835+
func TestCodecV7BatchBlobDataProofForPointEvaluation(t *testing.T) {
836+
testCases := []struct {
837+
name string
838+
batch *Batch
839+
creationErr string
840+
expectedBlobDataProof string
841+
}{
842+
{
843+
name: "Batch with 1 block, blocktrace 02",
844+
batch: &Batch{
845+
Index: 1,
846+
ParentBatchHash: common.Hash{},
847+
InitialL1MessageIndex: 0,
848+
PrevL1MessageQueueHash: common.Hash{},
849+
PostL1MessageQueueHash: common.Hash{},
850+
Blocks: []*Block{readBlockFromJSON(t, "testdata/blockTrace_02.json")},
851+
},
852+
expectedBlobDataProof: "2781a7620cf0cecb23596d7fee625cc26c61b7d605eb2ff43c7ff98fa4a8f3152bbf1b44bb80d37bdd2a352d25e88ea27377cfc3dd7a818f17fe397942dc6400901bb682fa2d91cca8005e181302e0f6e87553579a2d4b16b94e911f7c8b9703492d84fc5765212bc1c1796583e2b86aac6f758bf87fc1a1055c92e03d7217522e31f337255a63fa2b9573714b1e2af4b5e9ce3ab7c2b93a1acc637663435ef5",
853+
},
854+
{
855+
name: "Batch with 1 block, blocktrace 03",
856+
batch: &Batch{
857+
Index: 1,
858+
ParentBatchHash: common.Hash{},
859+
InitialL1MessageIndex: 0,
860+
PrevL1MessageQueueHash: common.Hash{},
861+
PostL1MessageQueueHash: common.Hash{},
862+
Blocks: []*Block{readBlockFromJSON(t, "testdata/blockTrace_03.json")},
863+
},
864+
expectedBlobDataProof: "42e370c6467ad79b5f7d79050685752fc043d8ff03505aae427bb35c6950d9e4475d546b7166b79e5faee7dd779585846e43de90c67201762ea7f3b6ca9b965b885613949b4e3624a6f8d9f4ec8e03f97d6ad2b3d4ca3462928907ae63189302c75e39974ec2c85e29911b8c3191af2b928bfea24d5c235a4ab0bfd66b6892b0b5a88e4b2cbd7e8dea48fae0a90ed84297dc6149954a2a7245fc5b9f5a258663",
865+
},
866+
{
867+
name: "Batch with 1 block, blocktrace 04",
868+
batch: &Batch{
869+
Index: 1,
870+
ParentBatchHash: common.Hash{1, 2, 3, 4},
871+
InitialL1MessageIndex: 10,
872+
PrevL1MessageQueueHash: common.Hash{1, 2, 3, 4},
873+
PostL1MessageQueueHash: common.HexToHash("0x6250cf03e7f922eefe450e9d4234ec56a1502066cd55eff22939df6100000000"),
874+
Blocks: []*Block{readBlockFromJSON(t, "testdata/blockTrace_04.json")},
875+
},
876+
expectedBlobDataProof: "43c83acecf2100a74f1cce1a7a62101af22a744f1d61aca5bae8a6bd81a0d2040116ade6d71ec98b6208cfe96c1241c092018506893f4d652a43febcc11a1f2dad8549493363f782fd8893ba193e05498e85d7e0cec10b53ff4e7b53e06659d0209a12b663e3807541c3a4ec6ac0561ea44941243065b683efedfe91c2f84cc90ab5251646d6f929899bb6ce74b0320eb22c31bfe460659b1191c99bfc7afdd6",
877+
},
878+
{
879+
name: "Batch with 1 block, blocktrace 05",
880+
batch: &Batch{
881+
Index: 1,
882+
ParentBatchHash: common.Hash{},
883+
InitialL1MessageIndex: 37,
884+
PrevL1MessageQueueHash: common.Hash{5, 6, 7, 8},
885+
PostL1MessageQueueHash: common.HexToHash("0xc31c3ca9a880b80c4e7fcb88844a5e21433bd2801bdd504e1ca4aed900000000"),
886+
Blocks: []*Block{readBlockFromJSON(t, "testdata/blockTrace_05.json")},
887+
},
888+
expectedBlobDataProof: "533782971f05c7a9eb627dc74614984f0c25bea4d2bf5a211360b51b9301dcd327587f1945a25f9063cab01372d4609430c193b66e60a34afe41a5ff341b4673a526889dd5d4c35affcfb513c910d8868deecc52fc40db17ce1eb67b0c1152d56c02dbe5b0f9eb7401649e59d8af6bb7ac69a24a5e2d06ca4ec8b927d0c9b7ceb9e6ef8f71edfa1d5135c183884c88a9d04ae993f006315e5318bb67c15c3b89",
889+
},
890+
{
891+
name: "Batch with 3 blocks, blocktrace 02 + 03 + 04",
892+
batch: &Batch{
893+
Index: 1,
894+
ParentBatchHash: common.Hash{},
895+
InitialL1MessageIndex: 10,
896+
PrevL1MessageQueueHash: common.Hash{9, 10, 11},
897+
PostL1MessageQueueHash: common.HexToHash("0x20f1c72064552d63fb7e1352b7815a9f8231a028220bf63d27b24bec00000000"),
898+
Blocks: []*Block{readBlockFromJSON(t, "testdata/blockTrace_02.json"), readBlockFromJSON(t, "testdata/blockTrace_03.json"), replaceBlockNumber(readBlockFromJSON(t, "testdata/blockTrace_04.json"), 4)},
899+
},
900+
expectedBlobDataProof: "009064652841cb148bc7516a4e5835e8ecc0e1e6e11c9b57378ed90e74e845056dde6e9763ffeab8fc5c8cfcbb33a23a80558429f38cb0e8ef9e2a8c62718b1aa9068ee04e998fdec84a3d6681b70696ccd99dd0ab20cfea19e52d91de68b4f73a0da2ceeb1c64131c4a20b9de632d188fe355ae8a9ab57e3bf8792a99a605b088abbfb656cca16758cf301c7863140b3578867cb03bb42956462808e7c72171",
901+
},
902+
{
903+
name: "Batch with 3 blocks, blocktrace 02 + 05 (L1 messages only) + 03",
904+
batch: &Batch{
905+
Index: 3,
906+
ParentBatchHash: common.Hash{2},
907+
InitialL1MessageIndex: 37,
908+
PrevL1MessageQueueHash: common.Hash{},
909+
PostL1MessageQueueHash: common.HexToHash("0x3d35d6b71c2769de1a4eb8f603e20f539c53a10c6764a6f5836cf13100000000"),
910+
Blocks: []*Block{readBlockFromJSON(t, "testdata/blockTrace_02.json"), replaceBlockNumber(readBlockFromJSON(t, "testdata/blockTrace_05.json"), 3), replaceBlockNumber(readBlockFromJSON(t, "testdata/blockTrace_03.json"), 4)},
911+
},
912+
expectedBlobDataProof: "5e52251386a249e9f8e6c458125fe3347d2358190ee03aa81b0d37128521a75e10c7f2f975cb37f42098a1d173feeaa867da04ecffbdcb6459c5d492a5b0ff048014b94261a8c345d86762e5a96d7f461083d34533175e30ec4ac5ab6cb7360c092822225fd9e5522be341b5f7ad88229394ef2568cd55a8dc60ec62ba818843d8acd83d0642203a19931fea4242cca9ec277b9ae16709b23d65376b85971e2f",
913+
},
914+
}
915+
916+
codecV7, err := CodecFromVersion(CodecV7)
917+
require.NoError(t, err)
918+
919+
for _, tc := range testCases {
920+
t.Run(tc.name, func(t *testing.T) {
921+
daBatch, err := codecV7.NewDABatch(tc.batch)
922+
require.NoError(t, err)
923+
verifyData, err := daBatch.BlobDataProofForPointEvaluation()
924+
require.NoError(t, err)
925+
assert.Equal(t, tc.expectedBlobDataProof, hex.EncodeToString(verifyData))
926+
})
927+
}
928+
}
929+
834930
func assertEqualDABlocks(t *testing.T, expected, actual DABlock) {
835931
require.Equal(t, expected.Number(), actual.Number())
836932
require.Equal(t, expected.NumTransactions(), actual.NumTransactions())

encoding/codecv7_types.go

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package encoding
33
import (
44
"bytes"
55
"encoding/binary"
6+
"encoding/hex"
67
"encoding/json"
78
"fmt"
89
"math/big"
@@ -136,9 +137,31 @@ func (b *daBatchV7) Hash() common.Hash {
136137
}
137138

138139
// BlobDataProofForPointEvaluation computes the abi-encoded blob verification data.
139-
// Note: This method is not implemented for daBatchV7.
140140
func (b *daBatchV7) BlobDataProofForPointEvaluation() ([]byte, error) {
141-
return nil, nil
141+
challengeDigest := crypto.Keccak256Hash(crypto.Keccak256(b.blobBytes), b.blobVersionedHash.Bytes())
142+
143+
// z = challengeDigest % BLS_MODULUS
144+
pointBigInt := new(big.Int).Mod(new(big.Int).SetBytes(challengeDigest[:]), blsModulus)
145+
pointBytes := pointBigInt.Bytes()
146+
147+
var z kzg4844.Point
148+
if len(pointBytes) > kzgPointByteSize {
149+
return nil, fmt.Errorf("pointBytes length exceeds %d bytes, got %d bytes", kzgPointByteSize, len(pointBytes))
150+
}
151+
start := kzgPointByteSize - len(pointBytes)
152+
copy(z[start:], pointBytes)
153+
154+
commitment, err := kzg4844.BlobToCommitment(b.blob)
155+
if err != nil {
156+
return nil, fmt.Errorf("failed to create blob commitment: %w", err)
157+
}
158+
159+
proof, y, err := kzg4844.ComputeProof(b.blob, z)
160+
if err != nil {
161+
return nil, fmt.Errorf("failed to create KZG proof at point, err: %w, z: %v", err, hex.EncodeToString(z[:]))
162+
}
163+
164+
return blobDataProofFromValues(z, y, commitment, proof), nil
142165
}
143166

144167
// Blob returns the blob of the batch.

0 commit comments

Comments
 (0)