feat(prover, coordinator): update vk handling logic (#931)

Co-authored-by: Steven Gu <asongala@163.com>
Co-authored-by: HAOYUatHZ <HAOYUatHZ@users.noreply.github.com>
This commit is contained in:
HAOYUatHZ
2023-09-07 10:59:47 +08:00
committed by GitHub
parent 2b6a3c9874
commit cd456ee3db
7 changed files with 21 additions and 71 deletions

View File

@@ -1,7 +1,6 @@
package version
import (
"strconv"
"strings"
)
@@ -20,36 +19,3 @@ func CheckScrollProverVersion(proverVersion string) bool {
// compare the `scroll_prover` version
return remote[2] == local[2]
}
// CheckScrollProverVersionTag check the "scroll-prover" version's tag, if it's too old, return false
func CheckScrollProverVersionTag(proverVersion string) bool {
// note the the version is in fact in the format of "tag-commit-scroll_prover-halo2",
// so split-by-'-' length should be 4
remote := strings.Split(proverVersion, "-")
if len(remote) != 4 {
return false
}
remoteTagNums := strings.Split(strings.TrimPrefix(remote[0], "v"), ".")
if len(remoteTagNums) != 3 {
return false
}
remoteTagMajor, err := strconv.Atoi(remoteTagNums[0])
if err != nil {
return false
}
remoteTagMinor, err := strconv.Atoi(remoteTagNums[1])
if err != nil {
return false
}
remoteTagPatch, err := strconv.Atoi(remoteTagNums[2])
if err != nil {
return false
}
if remoteTagMajor < 4 {
return false
}
if remoteTagMinor == 1 && remoteTagPatch < 98 {
return false
}
return true
}

View File

@@ -5,7 +5,7 @@ import (
"runtime/debug"
)
var tag = "v4.3.0"
var tag = "v4.3.1"
var commit = func() string {
if info, ok := debug.ReadBuildInfo(); ok {

View File

@@ -63,7 +63,8 @@ func (bp *BatchProverTask) Assign(ctx *gin.Context, getTaskParameter *coordinato
maxTotalAttempts := bp.cfg.ProverManager.SessionAttempts
batchTask, err := bp.batchOrm.UpdateBatchAttemptsReturning(ctx, maxActiveAttempts, maxTotalAttempts)
if err != nil {
return nil, fmt.Errorf("failed to get unassigned batch proving tasks, error:%w", err)
log.Error("failed to get unassigned batch proving tasks", "err", err)
return nil, ErrCoordinatorInternalFailure
}
if batchTask == nil {

View File

@@ -58,16 +58,14 @@ func (b *BaseProverTask) checkParameter(ctx *gin.Context, getTaskParameter *coor
}
ptc.ProverVersion = proverVersion.(string)
if getTaskParameter.VK == "" { // allow vk being empty, because for the first time the prover may not know its vk
if !version.CheckScrollProverVersionTag(proverVersion.(string)) { // but reject too-old provers
// if the prover has a different vk
if getTaskParameter.VK != b.vk {
// if the prover reports a different prover version
if !version.CheckScrollProverVersion(proverVersion.(string)) {
return nil, fmt.Errorf("incompatible prover version. please upgrade your prover, expect version: %s, actual version: %s", version.Version, proverVersion.(string))
}
} else if getTaskParameter.VK != b.vk { // non-empty vk but different
if version.CheckScrollProverVersion(proverVersion.(string)) { // same prover version but different vks
return nil, fmt.Errorf("incompatible vk. please check your params files or config files")
}
// different prover versions and different vks
return nil, fmt.Errorf("incompatible prover version. please upgrade your prover, expect version: %s, actual version: %s", version.Version, proverVersion.(string))
// if the prover reports a same prover version
return nil, fmt.Errorf("incompatible vk. please check your params files or config files")
}
isAssigned, err := b.proverTaskOrm.IsProverAssigned(ctx, publicKey.(string))

View File

@@ -16,6 +16,7 @@ import (
// ProverCore sends block-traces to rust-prover through socket and get back the zk-proof.
type ProverCore struct {
cfg *config.ProverCoreConfig
VK string
}
// NewProverCore inits a ProverCore object.
@@ -42,7 +43,3 @@ func (p *ProverCore) ProveBatch(taskID string, chunkInfos []*message.ChunkInfo,
Vk: _empty[:],
}, nil
}
func (p *ProverCore) GetVk() string {
return ""
}

View File

@@ -28,7 +28,7 @@ import (
// ProverCore sends block-traces to rust-prover through ffi and get back the zk-proof.
type ProverCore struct {
cfg *config.ProverCoreConfig
vk string
VK string
}
// NewProverCore inits a ProverCore object.
@@ -40,10 +40,18 @@ func NewProverCore(cfg *config.ProverCoreConfig) (*ProverCore, error) {
C.free(unsafe.Pointer(assetsPathStr))
}()
var vk string
var rawVK *C.char
if cfg.ProofType == message.ProofTypeBatch {
C.init_batch_prover(paramsPathStr, assetsPathStr)
rawVK = C.get_batch_vk()
} else if cfg.ProofType == message.ProofTypeChunk {
C.init_chunk_prover(paramsPathStr, assetsPathStr)
rawVK = C.get_chunk_vk()
}
if rawVK != nil {
vk = C.GoString(rawVK)
}
if cfg.DumpDir != "" {
@@ -54,27 +62,7 @@ func NewProverCore(cfg *config.ProverCoreConfig) (*ProverCore, error) {
log.Info("Enabled dump_proof", "dir", cfg.DumpDir)
}
return &ProverCore{cfg: cfg}, nil
}
// GetVk get Base64 format of vk.
func (p *ProverCore) GetVk() string {
if p.vk != "" { // cached
return p.vk
}
var raw *C.char
if p.cfg.ProofType == message.ProofTypeBatch {
raw = C.get_batch_vk()
} else if p.cfg.ProofType == message.ProofTypeChunk {
raw = C.get_chunk_vk()
}
if raw != nil {
p.vk = C.GoString(raw) // cache it
}
return p.vk
return &ProverCore{cfg: cfg, VK: vk}, nil
}
// ProveBatch call rust ffi to generate batch proof.

View File

@@ -181,7 +181,7 @@ func (r *Prover) fetchTaskFromCoordinator() (*store.ProvingTask, error) {
TaskType: r.Type(),
// we may not be able to get the vk at the first time, so we should pass vk to the coordinator every time we getTask
// instead of passing vk when we login
VK: r.proverCore.GetVk(),
VK: r.proverCore.VK,
}
if req.TaskType == message.ProofTypeChunk {