diff --git a/common/types/message/message.go b/common/types/message/message.go index 2fb833c2bc..1b2478d896 100644 --- a/common/types/message/message.go +++ b/common/types/message/message.go @@ -18,7 +18,7 @@ const ( StatusProofError ) -// ProofType represents the type of prover. +// ProofType represents the type of task. type ProofType uint8 func (r ProofType) String() string { diff --git a/coordinator/internal/logic/auth/login.go b/coordinator/internal/logic/auth/login.go index a2f04ebeb4..0fd13f4211 100644 --- a/coordinator/internal/logic/auth/login.go +++ b/coordinator/internal/logic/auth/login.go @@ -8,7 +8,6 @@ import ( "github.com/scroll-tech/go-ethereum/log" "gorm.io/gorm" - "scroll-tech/common/types/message" "scroll-tech/common/version" "scroll-tech/coordinator/internal/config" @@ -17,12 +16,6 @@ import ( "scroll-tech/coordinator/internal/types" ) -var ( - proofChunkTypeString = fmt.Sprintf("%d", message.ProofTypeChunk) - proofBatchTypeString = fmt.Sprintf("%d", message.ProofTypeBatch) - proofBundleTypeString = fmt.Sprintf("%d", message.ProofTypeBundle) -) - // LoginLogic the auth logic type LoginLogic struct { cfg *config.Config @@ -78,20 +71,20 @@ func (l *LoginLogic) Check(login *types.LoginParameter) error { if len(login.Message.ProverTypes) > 0 { vks := make(map[string]struct{}) for _, proverType := range login.Message.ProverTypes { - if proverType == proofChunkTypeString { + switch proverType { + case types.ProverTypeChunk: for vk := range l.chunkVks { vks[vk] = struct{}{} } - } - if proverType == proofBatchTypeString { + case types.ProverTypeBatch: for vk := range l.batchVKs { vks[vk] = struct{}{} } - } - if proverType == proofBundleTypeString { for vk := range l.bundleVks { vks[vk] = struct{}{} } + default: + log.Error("invalid prover_type", "value", proverType) } } diff --git a/coordinator/internal/logic/verifier/verifier.go b/coordinator/internal/logic/verifier/verifier.go index 03c5f87811..478c737c87 100644 --- a/coordinator/internal/logic/verifier/verifier.go +++ b/coordinator/internal/logic/verifier/verifier.go @@ -50,7 +50,11 @@ func NewVerifier(cfg *config.VerifierConfig) (*Verifier, error) { BatchVKMap: make(map[string]string), } - batchVK, err := v.readVK(path.Join(cfg.AssetsPath, "agg_vk.vkey")) + bundleVK, err := v.readVK(path.Join(cfg.AssetsPath, "bundle_vk.vkey")) + if err != nil { + return nil, err + } + batchVK, err := v.readVK(path.Join(cfg.AssetsPath, "batch_vk.vkey")) if err != nil { return nil, err } @@ -58,6 +62,7 @@ func NewVerifier(cfg *config.VerifierConfig) (*Verifier, error) { if err != nil { return nil, err } + v.BundleVkMap[cfg.ForkName] = bundleVK v.BatchVKMap[cfg.ForkName] = batchVK v.ChunkVKMap[cfg.ForkName] = chunkVK @@ -147,7 +152,7 @@ func (v *Verifier) loadEmbedVK() error { return err } - v.BatchVKMap["bernoulli"] = base64.StdEncoding.EncodeToString(batchVKBytes) - v.ChunkVKMap["bernoulli"] = base64.StdEncoding.EncodeToString(chunkVkBytes) + v.BatchVKMap["curie"] = base64.StdEncoding.EncodeToString(batchVKBytes) + v.ChunkVKMap["curie"] = base64.StdEncoding.EncodeToString(chunkVkBytes) return nil } diff --git a/coordinator/internal/types/auth.go b/coordinator/internal/types/auth.go index d58fd41e10..faa980fa8a 100644 --- a/coordinator/internal/types/auth.go +++ b/coordinator/internal/types/auth.go @@ -28,11 +28,11 @@ type LoginSchema struct { // Message the login message struct type Message struct { - Challenge string `form:"challenge" json:"challenge" binding:"required"` - ProverVersion string `form:"prover_version" json:"prover_version" binding:"required"` - ProverName string `form:"prover_name" json:"prover_name" binding:"required"` - ProverTypes []string `form:"prover_types" json:"prover_types"` - VKs []string `form:"vks" json:"vks"` + Challenge string `form:"challenge" json:"challenge" binding:"required"` + ProverVersion string `form:"prover_version" json:"prover_version" binding:"required"` + ProverName string `form:"prover_name" json:"prover_name" binding:"required"` + ProverTypes []ProverType `form:"prover_types" json:"prover_types"` + VKs []string `form:"vks" json:"vks"` } // LoginParameter for /login api diff --git a/coordinator/internal/types/auth_test.go b/coordinator/internal/types/auth_test.go index c65a17c256..eaaddf3ca6 100644 --- a/coordinator/internal/types/auth_test.go +++ b/coordinator/internal/types/auth_test.go @@ -2,14 +2,11 @@ package types import ( "encoding/hex" - "fmt" "testing" "github.com/scroll-tech/go-ethereum/common" "github.com/scroll-tech/go-ethereum/crypto" "github.com/stretchr/testify/assert" - - "scroll-tech/common/types/message" ) func TestAuthMessageSignAndVerify(t *testing.T) { @@ -24,7 +21,7 @@ func TestAuthMessageSignAndVerify(t *testing.T) { ProverName: "test1", ProverVersion: "v0.0.1", Challenge: "abcdef", - ProverTypes: []string{"2"}, + ProverTypes: []ProverType{ProverTypeBatch}, VKs: []string{"vk1", "vk2"}, }, PublicKey: publicKeyHex, @@ -65,7 +62,7 @@ func TestGenerateSignature(t *testing.T) { ProverName: "test", ProverVersion: "v4.1.115-4dd11c6-000000-000000", Challenge: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MTk1NjkyNDAsIm9yaWdfaWF0IjoxNzE5NTY1NjQwLCJyYW5kb20iOiJPRExnNEZtUW1MOEwzTDRvZ3BMcnl6c09EN1ZXd0FoNmd3bVpzVURJV3M0PSJ9.3Oq7fDtFnKGbPyjc8fslzfftyzreQbi-lAr0_HFy54w", - ProverTypes: []string{fmt.Sprintf("%d", message.ProofTypeChunk)}, + ProverTypes: []ProverType{ProverTypeChunk}, VKs: []string{"mock_chunk_vk"}, }, PublicKey: publicKeyHex, diff --git a/coordinator/internal/types/prover.go b/coordinator/internal/types/prover.go new file mode 100644 index 0000000000..b7ce464f76 --- /dev/null +++ b/coordinator/internal/types/prover.go @@ -0,0 +1,26 @@ +package types + +import "fmt" + +// ProverType represents the type of prover. +type ProverType uint8 + +func (r ProverType) String() string { + switch r { + case ProverTypeChunk: + return "prover type chunk" + case ProverTypeBatch: + return "prover type batch" + default: + return fmt.Sprintf("illegal prover type: %d", r) + } +} + +const ( + // ProverTypeUndefined is an unknown prover type + ProverTypeUndefined ProverType = iota + // ProverTypeChunk signals it's a chunk prover, which can prove chunk_tasks + ProverTypeChunk + // ProverTypeBatch signals it's a batch prover, which can prove batch_tasks and bundle_tasks + ProverTypeBatch +)