From db46ce408d34f7f93dccfdc08db6cf0468f50e79 Mon Sep 17 00:00:00 2001 From: HAOYUatHZ <37070449+HAOYUatHZ@users.noreply.github.com> Date: Wed, 23 Aug 2023 21:37:29 +0800 Subject: [PATCH] feat(coordinator): hardcode tag validation (#864) Co-authored-by: HAOYUatHZ --- common/version/version.go | 39 ++++++++++++++++++- .../logic/provertask/batch_prover_task.go | 7 +++- .../logic/provertask/chunk_prover_task.go | 7 +++- coordinator/test/api_test.go | 2 +- 4 files changed, 49 insertions(+), 6 deletions(-) diff --git a/common/version/version.go b/common/version/version.go index 7dc1ffc9a8..3542fbd4e2 100644 --- a/common/version/version.go +++ b/common/version/version.go @@ -3,10 +3,11 @@ package version import ( "fmt" "runtime/debug" + "strconv" "strings" ) -var tag = "v4.1.96" +var tag = "v4.1.97" var commit = func() string { if info, ok := debug.ReadBuildInfo(); ok { @@ -46,3 +47,39 @@ 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 { + return false + } + if remoteTagPatch < 96 { + return false + } + return true +} diff --git a/coordinator/internal/logic/provertask/batch_prover_task.go b/coordinator/internal/logic/provertask/batch_prover_task.go index c2ff70b828..9832015203 100644 --- a/coordinator/internal/logic/provertask/batch_prover_task.go +++ b/coordinator/internal/logic/provertask/batch_prover_task.go @@ -70,8 +70,11 @@ func (bp *BatchProverTask) Assign(ctx *gin.Context, getTaskParameter *coordinato if !proverVersionExist { return nil, fmt.Errorf("get prover version from context failed") } - if getTaskParameter.VK != "" && // allow vk being empty, because for the first time the prover may not know its vk - getTaskParameter.VK != bp.vk { + 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 + 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 != bp.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") } diff --git a/coordinator/internal/logic/provertask/chunk_prover_task.go b/coordinator/internal/logic/provertask/chunk_prover_task.go index cd25483ad7..9166fa4105 100644 --- a/coordinator/internal/logic/provertask/chunk_prover_task.go +++ b/coordinator/internal/logic/provertask/chunk_prover_task.go @@ -70,8 +70,11 @@ func (cp *ChunkProverTask) Assign(ctx *gin.Context, getTaskParameter *coordinato if !proverVersionExist { return nil, fmt.Errorf("get prover version from context failed") } - if getTaskParameter.VK != "" && // allow vk being empty, because for the first time the prover may not know its vk - getTaskParameter.VK != cp.vk { + 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 + 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 != cp.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") } diff --git a/coordinator/test/api_test.go b/coordinator/test/api_test.go index 8b133f2978..db07ee84ee 100644 --- a/coordinator/test/api_test.go +++ b/coordinator/test/api_test.go @@ -110,7 +110,7 @@ func setupCoordinator(t *testing.T, proversPerSession uint8, coordinatorURL stri } func setEnv(t *testing.T) { - version.Version = "v1.2.3-aaa-bbb-ccc" + version.Version = "v4.1.97-aaa-bbb-ccc" base = docker.NewDockerApp() base.RunDBImage(t)