Skip to content

Commit

Permalink
feat(coordinator): hardcode tag validation (scroll-tech#864)
Browse files Browse the repository at this point in the history
Co-authored-by: HAOYUatHZ <[email protected]>
  • Loading branch information
0xmountaintop and HAOYUatHZ authored Aug 23, 2023
1 parent 3d1a837 commit db46ce4
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 6 deletions.
39 changes: 38 additions & 1 deletion common/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
7 changes: 5 additions & 2 deletions coordinator/internal/logic/provertask/batch_prover_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
7 changes: 5 additions & 2 deletions coordinator/internal/logic/provertask/chunk_prover_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
2 changes: 1 addition & 1 deletion coordinator/test/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit db46ce4

Please sign in to comment.