Skip to content

Commit

Permalink
add ProverType && fix vks
Browse files Browse the repository at this point in the history
  • Loading branch information
amoylan2 committed Jul 3, 2024
1 parent 0b4bca6 commit 9e233c5
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 26 deletions.
2 changes: 1 addition & 1 deletion common/types/message/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
17 changes: 5 additions & 12 deletions coordinator/internal/logic/auth/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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)
}
}

Expand Down
11 changes: 8 additions & 3 deletions coordinator/internal/logic/verifier/verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,19 @@ 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
}
chunkVK, err := v.readVK(path.Join(cfg.AssetsPath, "chunk_vk.vkey"))
if err != nil {
return nil, err
}
v.BundleVkMap[cfg.ForkName] = bundleVK
v.BatchVKMap[cfg.ForkName] = batchVK
v.ChunkVKMap[cfg.ForkName] = chunkVK

Expand Down Expand Up @@ -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
}
10 changes: 5 additions & 5 deletions coordinator/internal/types/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 2 additions & 5 deletions coordinator/internal/types/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
26 changes: 26 additions & 0 deletions coordinator/internal/types/prover.go
Original file line number Diff line number Diff line change
@@ -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
)

0 comments on commit 9e233c5

Please sign in to comment.