mirror of
https://github.com/scroll-tech/scroll.git
synced 2026-01-11 23:18:07 -05:00
Compare commits
3 Commits
libzkp/deb
...
tool-get-b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ee5f377667 | ||
|
|
2205493112 | ||
|
|
68c237bdd7 |
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/scroll-tech/go-ethereum/common"
|
||||
"github.com/scroll-tech/go-ethereum/log"
|
||||
"github.com/urfave/cli/v2"
|
||||
|
||||
@@ -50,7 +51,7 @@ func action(ctx *cli.Context) error {
|
||||
}()
|
||||
|
||||
batchOrm := orm.NewBatch(db)
|
||||
taskID := "fa9a290c8f1a46dc626fa67d626fadfe4803968ce776383996f3ae12504a2591"
|
||||
taskID := "9078d06d248f5ee7c910db6191809e4f4c9712ec236e27a5c03cfd50dfe69add"
|
||||
batches, err := batchOrm.GetBatchesByBundleHash(ctx.Context, taskID)
|
||||
if err != nil {
|
||||
log.Error("failed to get batch proofs for batch", "task_id", taskID, "error", err)
|
||||
@@ -62,9 +63,11 @@ func action(ctx *cli.Context) error {
|
||||
return fmt.Errorf("failed to get batch proofs for bundle task id:%s, no batch found", taskID)
|
||||
}
|
||||
|
||||
hardForkName := "darwinV2"
|
||||
|
||||
var batchProofs []message.BatchProof
|
||||
for _, batch := range batches {
|
||||
proof := message.NewBatchProof("darwinV2")
|
||||
proof := message.NewBatchProof(hardForkName)
|
||||
if encodeErr := json.Unmarshal(batch.Proof, &proof); encodeErr != nil {
|
||||
log.Error("failed to unmarshal batch proof")
|
||||
return fmt.Errorf("failed to unmarshal proof: %w, bundle hash: %v, batch hash: %v", encodeErr, taskID, batch.Hash)
|
||||
@@ -76,16 +79,41 @@ func action(ctx *cli.Context) error {
|
||||
BatchProofs: batchProofs,
|
||||
}
|
||||
|
||||
if hardForkName == message.EuclidV2Fork {
|
||||
taskDetail.ForkName = message.EuclidV2ForkNameForProver
|
||||
} else if hardForkName == message.EuclidFork {
|
||||
taskDetail.ForkName = message.EuclidForkNameForProver
|
||||
}
|
||||
|
||||
parentBatch, err := batchOrm.GetBatchByHash(ctx, batches[0].ParentBatchHash)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get parent batch for batch task id:%s err:%w", taskID, err)
|
||||
}
|
||||
|
||||
taskDetail.BundleInfo = &message.OpenVMBundleInfo{
|
||||
ChainID: 534352,
|
||||
PrevStateRoot: common.HexToHash(parentBatch.StateRoot),
|
||||
PostStateRoot: common.HexToHash(batches[len(batches)-1].StateRoot),
|
||||
WithdrawRoot: common.HexToHash(batches[len(batches)-1].WithdrawRoot),
|
||||
NumBatches: uint32(len(batches)),
|
||||
PrevBatchHash: common.HexToHash(batches[0].ParentBatchHash),
|
||||
BatchHash: common.HexToHash(batches[len(batches)-1].Hash),
|
||||
}
|
||||
|
||||
if hardForkName == message.EuclidV2Fork {
|
||||
taskDetail.BundleInfo.MsgQueueHash = common.HexToHash(batches[len(batches)-1].PostL1MessageQueueHash)
|
||||
}
|
||||
|
||||
batchProofsBytes, err := json.Marshal(taskDetail)
|
||||
if err != nil {
|
||||
log.Error("failed to marshal batch proof")
|
||||
return fmt.Errorf("failed to marshal batch proofs, taskID:%s err:%w", taskID, err)
|
||||
}
|
||||
|
||||
taskMsg := &coordinatorType.GetTaskSchema{
|
||||
TaskID: taskID,
|
||||
TaskType: int(message.ProofTypeBundle),
|
||||
TaskData: string(batchProofsBytes),
|
||||
TaskID: taskID,
|
||||
TaskType: int(message.ProofTypeBundle),
|
||||
TaskData: string(batchProofsBytes),
|
||||
HardForkName: hardForkName,
|
||||
}
|
||||
|
||||
log.Info("task_msg", "data", taskMsg)
|
||||
|
||||
160
coordinator/internal/orm/batch_task_detail_script/main.go
Normal file
160
coordinator/internal/orm/batch_task_detail_script/main.go
Normal file
@@ -0,0 +1,160 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math/big"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/scroll-tech/da-codec/encoding"
|
||||
"github.com/scroll-tech/go-ethereum/common"
|
||||
"github.com/scroll-tech/go-ethereum/common/hexutil"
|
||||
"github.com/scroll-tech/go-ethereum/log"
|
||||
"gorm.io/gorm"
|
||||
|
||||
"scroll-tech/common/database"
|
||||
"scroll-tech/common/types/message"
|
||||
"scroll-tech/coordinator/internal/orm"
|
||||
)
|
||||
|
||||
func main() {
|
||||
glogger := log.NewGlogHandler(log.StreamHandler(os.Stderr, log.LogfmtFormat()))
|
||||
glogger.Verbosity(log.LvlInfo)
|
||||
log.Root().SetHandler(glogger)
|
||||
|
||||
if len(os.Args) < 2 {
|
||||
log.Crit("no batch index range provided")
|
||||
return
|
||||
}
|
||||
|
||||
indexRange := os.Args[1]
|
||||
indices := strings.Split(indexRange, "-")
|
||||
if len(indices) != 2 {
|
||||
log.Crit("invalid batch index range format. Use start-end", "providedRange", indexRange)
|
||||
return
|
||||
}
|
||||
|
||||
startIndex, err := strconv.Atoi(indices[0])
|
||||
endIndex, err2 := strconv.Atoi(indices[1])
|
||||
if err != nil || err2 != nil || startIndex > endIndex {
|
||||
log.Crit("invalid batch index range", "start", indices[0], "end", indices[1], "err", err, "err2", err2)
|
||||
return
|
||||
}
|
||||
|
||||
db, err := database.InitDB(&database.Config{
|
||||
DriverName: "postgres",
|
||||
DSN: os.Getenv("DB_DSN"),
|
||||
MaxOpenNum: 200,
|
||||
MaxIdleNum: 20,
|
||||
})
|
||||
if err != nil {
|
||||
log.Crit("failed to init db", "err", err)
|
||||
}
|
||||
defer func() {
|
||||
if deferErr := database.CloseDB(db); deferErr != nil {
|
||||
log.Error("failed to close db", "err", err)
|
||||
}
|
||||
}()
|
||||
|
||||
for i := startIndex; i <= endIndex; i++ {
|
||||
batchIndex := uint64(i)
|
||||
resultBytes, err := getBatchTask(db, batchIndex)
|
||||
if err != nil {
|
||||
log.Crit("failed to get batch task", "batchIndex", batchIndex, "err", err)
|
||||
continue
|
||||
}
|
||||
|
||||
outputFilename := fmt.Sprintf("batch_task_%d.json", batchIndex)
|
||||
if err = os.WriteFile(outputFilename, resultBytes, 0644); err != nil {
|
||||
log.Crit("failed to write output file", "filename", outputFilename, "err", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func getBatchTask(db *gorm.DB, batchIndex uint64) ([]byte, error) {
|
||||
batch, err := orm.NewBatch(db).GetBatchByIndex(context.Background(), batchIndex)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("failed to get batch hash by index: %d err: %w ", batchIndex, err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
chunks, err := orm.NewChunk(db).GetChunksByBatchHash(context.Background(), batch.Hash)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("failed to get chunk proofs for batch task id: %s err: %w ", batch.Hash, err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var chunkProofs []message.ChunkProof
|
||||
var chunkInfos []*message.ChunkInfo
|
||||
for _, chunk := range chunks {
|
||||
fmt.Println("chunk index: ", chunk.Index)
|
||||
fmt.Print("chunk proof: ", chunk.Proof)
|
||||
proof := message.NewChunkProof("euclidV2")
|
||||
if encodeErr := json.Unmarshal(chunk.Proof, &proof); encodeErr != nil {
|
||||
return nil, fmt.Errorf("Chunk.GetProofsByBatchHash unmarshal proof error: %w, batch hash: %v, chunk hash: %v", encodeErr, batch.Hash, chunk.Hash)
|
||||
}
|
||||
chunkProofs = append(chunkProofs, proof)
|
||||
|
||||
chunkInfo := message.ChunkInfo{
|
||||
ChainID: 534352,
|
||||
PrevStateRoot: common.HexToHash(chunk.ParentChunkStateRoot),
|
||||
PostStateRoot: common.HexToHash(chunk.StateRoot),
|
||||
WithdrawRoot: common.HexToHash(chunk.WithdrawRoot),
|
||||
DataHash: common.HexToHash(chunk.Hash),
|
||||
PrevMsgQueueHash: common.HexToHash(chunk.PrevL1MessageQueueHash),
|
||||
PostMsgQueueHash: common.HexToHash(chunk.PostL1MessageQueueHash),
|
||||
IsPadding: false,
|
||||
}
|
||||
if openvmProof, ok := proof.(*message.OpenVMChunkProof); ok {
|
||||
chunkInfo.InitialBlockNumber = openvmProof.MetaData.ChunkInfo.InitialBlockNumber
|
||||
chunkInfo.BlockCtxs = openvmProof.MetaData.ChunkInfo.BlockCtxs
|
||||
chunkInfo.TxDataLength = openvmProof.MetaData.ChunkInfo.TxDataLength
|
||||
}
|
||||
chunkInfos = append(chunkInfos, &chunkInfo)
|
||||
}
|
||||
|
||||
taskDetail, err := getBatchTaskDetail(batch, chunkInfos, chunkProofs)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get batch task detail, taskID:%s err:%w", batch.Hash, err)
|
||||
}
|
||||
|
||||
chunkProofsBytes, err := json.MarshalIndent(taskDetail, "", " ")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to marshal chunk proofs, taskID:%s err:%w", batch.Hash, err)
|
||||
}
|
||||
|
||||
return chunkProofsBytes, nil
|
||||
}
|
||||
|
||||
func getBatchTaskDetail(dbBatch *orm.Batch, chunkInfos []*message.ChunkInfo, chunkProofs []message.ChunkProof) (*message.BatchTaskDetail, error) {
|
||||
taskDetail := &message.BatchTaskDetail{
|
||||
ChunkInfos: chunkInfos,
|
||||
ChunkProofs: chunkProofs,
|
||||
}
|
||||
|
||||
taskDetail.ForkName = message.EuclidV2ForkNameForProver
|
||||
|
||||
codec, err := encoding.CodecFromVersion(encoding.CodecVersion(dbBatch.CodecVersion))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get codec from version %d, err: %w", dbBatch.CodecVersion, err)
|
||||
}
|
||||
|
||||
batchHeader, decodeErr := codec.NewDABatchFromBytes(dbBatch.BatchHeader)
|
||||
if decodeErr != nil {
|
||||
return nil, fmt.Errorf("failed to decode batch header version %d: %w", dbBatch.CodecVersion, decodeErr)
|
||||
}
|
||||
taskDetail.BatchHeader = batchHeader
|
||||
taskDetail.BlobBytes = dbBatch.BlobBytes
|
||||
taskDetail.ChallengeDigest = common.HexToHash(dbBatch.ChallengeDigest)
|
||||
// Memory layout of `BlobDataProof`: used in Codec.BlobDataProofForPointEvaluation()
|
||||
// | z | y | kzg_commitment | kzg_proof |
|
||||
// |---------|---------|----------------|-----------|
|
||||
// | bytes32 | bytes32 | bytes48 | bytes48 |
|
||||
taskDetail.KzgProof = message.Byte48{Big: hexutil.Big(*new(big.Int).SetBytes(dbBatch.BlobDataProof[112:160]))}
|
||||
taskDetail.KzgCommitment = message.Byte48{Big: hexutil.Big(*new(big.Int).SetBytes(dbBatch.BlobDataProof[64:112]))}
|
||||
|
||||
return taskDetail, nil
|
||||
}
|
||||
123
coordinator/internal/orm/bundle_task_detail_script/main.go
Normal file
123
coordinator/internal/orm/bundle_task_detail_script/main.go
Normal file
@@ -0,0 +1,123 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/scroll-tech/go-ethereum/common"
|
||||
"github.com/scroll-tech/go-ethereum/log"
|
||||
|
||||
"scroll-tech/common/database"
|
||||
"scroll-tech/common/types/message"
|
||||
"scroll-tech/coordinator/internal/orm"
|
||||
coordinatorType "scroll-tech/coordinator/internal/types"
|
||||
)
|
||||
|
||||
func main() {
|
||||
glogger := log.NewGlogHandler(log.StreamHandler(os.Stderr, log.LogfmtFormat()))
|
||||
glogger.Verbosity(log.LvlInfo)
|
||||
log.Root().SetHandler(glogger)
|
||||
|
||||
dbDSN := os.Getenv("DB_DSN")
|
||||
if dbDSN == "" {
|
||||
log.Crit("DB_DSN environment variable is not set")
|
||||
return
|
||||
}
|
||||
|
||||
db, err := database.InitDB(&database.Config{
|
||||
DriverName: "postgres",
|
||||
DSN: dbDSN,
|
||||
MaxOpenNum: 200,
|
||||
MaxIdleNum: 20,
|
||||
})
|
||||
if err != nil {
|
||||
log.Crit("failed to init db connection", "err", err)
|
||||
return
|
||||
}
|
||||
defer func() {
|
||||
if err = database.CloseDB(db); err != nil {
|
||||
log.Error("can not close db connection", "error", err)
|
||||
}
|
||||
}()
|
||||
|
||||
taskID := "7591df9c01efb7efc25359cee4600edce7e307f4d8806837a05cf510067a2819"
|
||||
hardForkName := "euclidV2"
|
||||
|
||||
log.Info("Processing bundle", "taskID", taskID, "hardForkName", hardForkName)
|
||||
|
||||
batchOrm := orm.NewBatch(db)
|
||||
batches, err := batchOrm.GetBatchesByBundleHash(context.Background(), taskID)
|
||||
if err != nil {
|
||||
log.Error("failed to get batch proofs for batch", "task_id", taskID, "error", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if len(batches) == 0 {
|
||||
log.Error("failed to get batch proofs for bundle, not found batch", "task_id", taskID)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
var batchProofs []message.BatchProof
|
||||
for _, batch := range batches {
|
||||
proof := message.NewBatchProof(hardForkName)
|
||||
if encodeErr := json.Unmarshal(batch.Proof, &proof); encodeErr != nil {
|
||||
log.Error("failed to unmarshal batch proof", "error", encodeErr)
|
||||
os.Exit(1)
|
||||
}
|
||||
batchProofs = append(batchProofs, proof)
|
||||
}
|
||||
|
||||
taskDetail := message.BundleTaskDetail{
|
||||
BatchProofs: batchProofs,
|
||||
}
|
||||
|
||||
if hardForkName == message.EuclidV2Fork {
|
||||
taskDetail.ForkName = message.EuclidV2ForkNameForProver
|
||||
} else if hardForkName == message.EuclidFork {
|
||||
taskDetail.ForkName = message.EuclidForkNameForProver
|
||||
}
|
||||
|
||||
parentBatch, err := batchOrm.GetBatchByHash(context.Background(), batches[0].ParentBatchHash)
|
||||
if err != nil {
|
||||
log.Error("failed to get parent batch", "task_id", taskID, "error", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
taskDetail.BundleInfo = &message.OpenVMBundleInfo{
|
||||
ChainID: 534352,
|
||||
PrevStateRoot: common.HexToHash(parentBatch.StateRoot),
|
||||
PostStateRoot: common.HexToHash(batches[len(batches)-1].StateRoot),
|
||||
WithdrawRoot: common.HexToHash(batches[len(batches)-1].WithdrawRoot),
|
||||
NumBatches: uint32(len(batches)),
|
||||
PrevBatchHash: common.HexToHash(batches[0].ParentBatchHash),
|
||||
BatchHash: common.HexToHash(batches[len(batches)-1].Hash),
|
||||
}
|
||||
|
||||
if hardForkName == message.EuclidV2Fork {
|
||||
taskDetail.BundleInfo.MsgQueueHash = common.HexToHash(batches[len(batches)-1].PostL1MessageQueueHash)
|
||||
}
|
||||
|
||||
batchProofsBytes, err := json.Marshal(taskDetail)
|
||||
if err != nil {
|
||||
log.Error("failed to marshal batch proofs", "task_id", taskID, "error", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
taskMsg := &coordinatorType.GetTaskSchema{
|
||||
TaskID: taskID,
|
||||
TaskType: int(message.ProofTypeBundle),
|
||||
TaskData: string(batchProofsBytes),
|
||||
HardForkName: hardForkName,
|
||||
}
|
||||
|
||||
outputFilename := fmt.Sprintf("bundle_task_%s.json", taskID)
|
||||
if err = os.WriteFile(outputFilename, batchProofsBytes, 0644); err != nil {
|
||||
log.Error("failed to write output file", "filename", outputFilename, "error", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
log.Info("Task details saved to file", "filename", outputFilename)
|
||||
log.Info("Task message", "data", taskMsg)
|
||||
}
|
||||
@@ -707,6 +707,7 @@ github.com/cloudflare/cloudflare-go v0.14.0/go.mod h1:EnwdgGMaFOruiPZRFSgn+TsQ3h
|
||||
github.com/cloudflare/cloudflare-go v0.79.0/go.mod h1:gkHQf9xEubaQPEuerBuoinR9P8bf8a05Lq0X6WKy1Oc=
|
||||
github.com/cloudflare/redoctober v0.0.0-20211013234631-6a74ccc611f6 h1:QKzett0dn5FhjcIHNKSClEilabfhWCnsdijq3ftm9Ms=
|
||||
github.com/cloudflare/redoctober v0.0.0-20211013234631-6a74ccc611f6/go.mod h1:Ikt4Wfpln1YOrak+auA8BNxgiilj0Y2y7nO+aN2eMzk=
|
||||
github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY=
|
||||
github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
|
||||
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
|
||||
github.com/cncf/udpa/go v0.0.0-20220112060539-c52dc94e7fbe h1:QQ3GSy+MqSHxm/d8nCtnAiZdYFd45cYZPs8vOOIYKfk=
|
||||
@@ -1357,8 +1358,6 @@ github.com/scroll-tech/da-codec v0.1.1-0.20241014152913-2703f226fb0b h1:5H6V6yba
|
||||
github.com/scroll-tech/da-codec v0.1.1-0.20241014152913-2703f226fb0b/go.mod h1:48uxaqVgpD8ulH8p+nrBtfeLHZ9tX82bVVdPNkW3rPE=
|
||||
github.com/scroll-tech/da-codec v0.1.3-0.20250227072756-a1482833595f h1:YYbhuUwjowqI4oyXtECRofck7Fyj18e1tcRjuQlZpJE=
|
||||
github.com/scroll-tech/da-codec v0.1.3-0.20250227072756-a1482833595f/go.mod h1:xECEHZLVzbdUn+tNbRJhRIjLGTOTmnFQuTgUTeVLX58=
|
||||
github.com/scroll-tech/da-codec v0.1.3-0.20250401062930-9f9f53898493 h1:Ioc01J0WEMxuwFvEPGJeBKXdf2KY4Yc3XbFky/IxLlI=
|
||||
github.com/scroll-tech/da-codec v0.1.3-0.20250401062930-9f9f53898493/go.mod h1:yhTS9OVC0xQGhg7DN5iV5KZJvnSIlFWAxDdp+6jxQtY=
|
||||
github.com/scroll-tech/go-ethereum v1.10.14-0.20240607130425-e2becce6a1a4/go.mod h1:byf/mZ8jLYUCnUePTicjJWn+RvKdxDn7buS6glTnMwQ=
|
||||
github.com/scroll-tech/go-ethereum v1.10.14-0.20240821074444-b3fa00861e5e/go.mod h1:swB5NSp8pKNDuYsTxfR08bHS6L56i119PBx8fxvV8Cs=
|
||||
github.com/scroll-tech/go-ethereum v1.10.14-0.20241010064814-3d88e870ae22/go.mod h1:r9FwtxCtybMkTbWYCyBuevT9TW3zHmOTHqD082Uh+Oo=
|
||||
|
||||
Reference in New Issue
Block a user