Compare commits

...

39 Commits

Author SHA1 Message Date
Xinran
11cd211de4 Merge branch 'develop' into multi_verifier 2023-08-15 15:42:31 +08:00
Lawliet-Chan
141a05f2c6 fix lint 2023-08-15 13:15:58 +08:00
Lawliet-Chan
5955329cff fix lint 2023-08-15 11:34:14 +08:00
Lawliet-Chan
3292128919 fix lint 2023-08-15 11:26:25 +08:00
Lawliet-Chan
497fd783a3 fix 2023-08-15 11:23:42 +08:00
Lawliet-Chan
e7d4b10451 fix 2023-08-14 21:42:54 +08:00
Xinran
e7f868b467 Merge branch 'develop' into multi_verifier 2023-08-14 21:01:34 +08:00
Lawliet-Chan
8dd288c22d add logs 2023-08-14 20:57:48 +08:00
Lawliet-Chan
4dce379232 add skip 2023-08-14 19:17:44 +08:00
Lawliet-Chan
d8019b2dfb update scripts 2023-08-14 15:43:29 +08:00
Lawliet-Chan
cf2fdfda9f try 2023-08-14 15:15:31 +08:00
Xinran
02e6f77221 Update common/version/version.go
Co-authored-by: georgehao <haohongfan@gmail.com>
2023-08-14 15:11:02 +08:00
Xinran
3e3f39a3f2 Merge branch 'develop' into multi_verifier 2023-08-14 08:59:28 +08:00
Xinran
00f906f612 Merge branch 'develop' into multi_verifier 2023-08-10 21:51:36 +08:00
Xinran
7f86fe65da Merge branch 'develop' into multi_verifier 2023-08-10 17:59:04 +08:00
Lawliet-Chan
df3fac89ae fix conflicts 2023-08-10 17:14:13 +08:00
Xinran
0892f0f876 Merge branch 'develop' into multi_verifier 2023-08-10 17:13:36 +08:00
Lawliet-Chan
0b9d6d04fa bump 2023-08-10 16:39:52 +08:00
Xinran
0c12773b78 Merge branch 'develop' into multi_verifier 2023-08-10 16:37:15 +08:00
Lawliet-Chan
36a4964aa5 fix 2023-08-10 14:33:32 +08:00
Lawliet-Chan
cd4158c80d try fix 2023-08-10 13:44:04 +08:00
Lawliet-Chan
3e01d3de83 Revert "for debugging"
This reverts commit 5344a73c5b.
2023-08-10 13:43:25 +08:00
Lawliet-Chan
5344a73c5b for debugging 2023-08-10 13:37:50 +08:00
Lawliet-Chan
50829cae9c fix lint 2023-08-10 13:19:42 +08:00
Lawliet-Chan
2044a052ec get jwt proverVersion 2023-08-10 13:10:49 +08:00
Lawliet-Chan
1e2ce2d655 fix mock 2023-08-10 09:11:51 +08:00
Lawliet-Chan
66e802fb55 fix mock 2023-08-10 09:07:44 +08:00
Xinran
716d01fda5 Merge branch 'develop' into multi_verifier 2023-08-10 00:25:40 +08:00
Lawliet-Chan
399404172c bump 2023-08-10 00:22:35 +08:00
Xinran
364a8f8850 Merge branch 'develop' into multi_verifier 2023-08-10 00:08:23 +08:00
Lawliet-Chan
76ba845d0f add Cargo.lock 2023-08-10 00:08:04 +08:00
Lawliet-Chan
f729b8e0ab fix cargo.lock 2023-08-09 23:58:53 +08:00
Lawliet-Chan
e6b0c61878 fix old version 2023-08-09 23:32:39 +08:00
Lawliet-Chan
a7a65b60e5 fix old version 2023-08-09 23:06:49 +08:00
Lawliet-Chan
160287e6cc try fix 2023-08-09 22:29:35 +08:00
Lawliet-Chan
bdc1957f27 fix 2023-08-09 22:21:11 +08:00
Lawliet-Chan
8ee49ed515 fix 2023-08-09 21:40:38 +08:00
Lawliet-Chan
c90d1414d9 fix 2023-08-09 21:33:58 +08:00
Lawliet-Chan
87b1a7a63e multi verifier 2023-08-09 21:31:14 +08:00
12 changed files with 9327 additions and 19 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -28,8 +28,15 @@ var commit = func() string {
// The default `000000-000000` is set for integration test, and will be overwritten by coordinator's & prover's actual compilations (see their Makefiles). // The default `000000-000000` is set for integration test, and will be overwritten by coordinator's & prover's actual compilations (see their Makefiles).
var ZkVersion = "000000-000000" var ZkVersion = "000000-000000"
// Version denote the version of scroll protocol, including the l2geth, relayer, coordinator, prover, contracts and etc. // OldZkVersion is the last version of ZkVersion.
var Version = fmt.Sprintf("%s-%s-%s", tag, commit, ZkVersion) var OldZkVersion = "000000-000000"
var (
// Version denote the version of scroll protocol, including the l2geth, relayer, coordinator, prover, contracts and etc.
Version = fmt.Sprintf("%s-%s-%s", tag, commit, ZkVersion)
// OldVersion is the last version of Version.
OldVersion = fmt.Sprintf("%s-%s-%s", tag, commit, OldZkVersion)
)
// CheckScrollProverVersion check the "scroll-prover" version, if it's different from the local one, return false // CheckScrollProverVersion check the "scroll-prover" version, if it's different from the local one, return false
func CheckScrollProverVersion(proverVersion string) bool { func CheckScrollProverVersion(proverVersion string) bool {

View File

@@ -5,28 +5,38 @@ IMAGE_VERSION=latest
REPO_ROOT_DIR=./.. REPO_ROOT_DIR=./..
ifeq (4.3,$(firstword $(sort $(MAKE_VERSION) 4.3))) ifeq (4.3,$(firstword $(sort $(MAKE_VERSION) 4.3)))
ZKEVM_VERSION=$(shell grep -m 1 "scroll-prover" ../common/libzkp/impl/Cargo.lock | cut -d "#" -f2 | cut -c-7) ZKEVM_VERSION=$(shell grep -m 1 "scroll-prover" ../common/libzkp/impl/Cargo.lock.new | cut -d "#" -f2 | cut -c-7)
HALO2_VERSION=$(shell grep -m 1 "halo2.git" ../common/libzkp/impl/Cargo.lock | cut -d "#" -f2 | cut -c-7) HALO2_VERSION=$(shell grep -m 1 "halo2.git" ../common/libzkp/impl/Cargo.lock.new | cut -d "#" -f2 | cut -c-7)
OLD_ZKEVM_VERSION=$(shell grep -m 1 "scroll-prover" ../common/libzkp/impl/Cargo.lock.old | cut -d "#" -f2 | cut -c-7)
OLD_HALO2_VERSION=$(shell grep -m 1 "halo2.git" ../common/libzkp/impl/Cargo.lock.old | cut -d "#" -f2 | cut -c-7)
else else
ZKEVM_VERSION=$(shell grep -m 1 "scroll-prover" ../common/libzkp/impl/Cargo.lock | cut -d "\#" -f2 | cut -c-7) ZKEVM_VERSION=$(shell grep -m 1 "scroll-prover" ../common/libzkp/impl/Cargo.lock.new | cut -d "\#" -f2 | cut -c-7)
HALO2_VERSION=$(shell grep -m 1 "halo2.git" ../common/libzkp/impl/Cargo.lock | cut -d "\#" -f2 | cut -c-7) HALO2_VERSION=$(shell grep -m 1 "halo2.git" ../common/libzkp/impl/Cargo.lock.new | cut -d "\#" -f2 | cut -c-7)
OLD_ZKEVM_VERSION=$(shell grep -m 1 "scroll-prover" ../common/libzkp/impl/Cargo.lock.old | cut -d "\#" -f2 | cut -c-7)
OLD_HALO2_VERSION=$(shell grep -m 1 "halo2.git" ../common/libzkp/impl/Cargo.lock.old | cut -d "\#" -f2 | cut -c-7)
endif endif
ZK_VERSION=${ZKEVM_VERSION}-${HALO2_VERSION} ZK_VERSION=${ZKEVM_VERSION}-${HALO2_VERSION}
OLD_ZK_VERSION=${OLD_ZKEVM_VERSION}-${OLD_HALO2_VERSION}
pre-upgrade-zk:
cd ../common/libzkp/impl && cp Cargo.lock.old Cargo.lock && cargo clean && cargo build --release && cp ./target/release/libzkp.so ../interface/liboldzkp.so
cp -r ../common/libzkp/interface ./internal/logic/old_verifier/lib && rm ../common/libzkp/interface/liboldzkp.so
find ../common | grep libzktrie.so | xargs -I{} cp {} ./internal/logic/old_verifier/lib/liboldzktrie.so
test: test:
go test -v -race -coverprofile=coverage.txt -covermode=atomic -p 1 $(PWD)/... go test -v -race -coverprofile=coverage.txt -covermode=atomic -p 1 $(PWD)/...
libzkp: libzkp: pre-upgrade-zk
cd ../common/libzkp/impl && cargo clean && cargo build --release && cp ./target/release/libzkp.so ../interface/ cd ../common/libzkp/impl && cp Cargo.lock.new Cargo.lock && cargo clean && cargo build --release && cp ./target/release/libzkp.so ../interface/
rm -rf ./internal/logic/verifier/lib && cp -r ../common/libzkp/interface ./internal/logic/verifier/lib cp -r ../common/libzkp/interface ./internal/logic/verifier/lib
find ../common | grep libzktrie.so | xargs -I{} cp {} ./internal/logic/verifier/lib find ../common | grep libzktrie.so | xargs -I{} cp {} ./internal/logic/verifier/lib
coordinator: libzkp ## Builds the Coordinator instance. coordinator: libzkp ## Builds the Coordinator instance.
go build -ldflags "-X scroll-tech/common/version.ZkVersion=${ZK_VERSION}" -o $(PWD)/build/bin/coordinator ./cmd go build -ldflags "-X scroll-tech/common/version.ZkVersion=${ZK_VERSION} -X scroll-tech/common/version.OldZkVersion=${OLD_ZK_VERSION}" -o $(PWD)/build/bin/coordinator ./cmd
coordinator_skip_libzkp: coordinator_skip_libzkp:
go build -ldflags "-X scroll-tech/common/version.ZkVersion=${ZK_VERSION}" -o $(PWD)/build/bin/coordinator ./cmd go build -ldflags "-X scroll-tech/common/version.ZkVersion=${ZK_VERSION} -X scroll-tech/common/version.OldZkVersion=${OLD_ZK_VERSION}" -o $(PWD)/build/bin/coordinator ./cmd
mock_coordinator: ## Builds the mocked Coordinator instance. mock_coordinator: ## Builds the mocked Coordinator instance.
go build -tags="mock_prover mock_verifier" -o $(PWD)/build/bin/coordinator ./cmd go build -tags="mock_prover mock_verifier" -o $(PWD)/build/bin/coordinator ./cmd

View File

@@ -8,6 +8,11 @@
"params_path": "", "params_path": "",
"assets_path": "" "assets_path": ""
}, },
"old_verifier": {
"mock_mode": true,
"params_path": "",
"assets_path": ""
},
"max_verifier_workers": 4 "max_verifier_workers": 4
}, },
"db": { "db": {

View File

@@ -17,6 +17,8 @@ type ProverManager struct {
SessionAttempts uint8 `json:"session_attempts"` SessionAttempts uint8 `json:"session_attempts"`
// Zk verifier config. // Zk verifier config.
Verifier *VerifierConfig `json:"verifier"` Verifier *VerifierConfig `json:"verifier"`
// Old Zk version config
OldVerifier *VerifierConfig `json:"old_verifier"`
// Proof collection time (in seconds). // Proof collection time (in seconds).
CollectionTimeSec int `json:"collection_time_sec"` CollectionTimeSec int `json:"collection_time_sec"`
// Max number of workers in verifier worker pool // Max number of workers in verifier worker pool

View File

@@ -0,0 +1,35 @@
//go:build mock_verifier
package old_verifier
import (
"scroll-tech/common/types/message"
"scroll-tech/coordinator/internal/config"
)
const InvalidTestProof = "this is a invalid proof"
// OldVerifier represents a mock halo2 verifier.
type OldVerifier struct{}
// NewVerifier Sets up a mock verifier.
func NewOldVerifier(_ *config.VerifierConfig) (*OldVerifier, error) {
return &OldVerifier{}, nil
}
// VerifyChunkProof return a mock verification result for a ChunkProof.
func (v *OldVerifier) VerifyChunkProof(proof *message.ChunkProof) (bool, error) {
if string(proof.Proof) == InvalidTestProof {
return false, nil
}
return true, nil
}
// VerifyBatchProof return a mock verification result for a BatchProof.
func (v *OldVerifier) VerifyBatchProof(proof *message.BatchProof) (bool, error) {
if string(proof.Proof) == InvalidTestProof {
return false, nil
}
return true, nil
}

View File

@@ -0,0 +1,98 @@
//go:build !mock_verifier
package old_verifier
/*
#cgo LDFLAGS: -loldzkp -lm -ldl -loldzktrie -L${SRCDIR}/lib/ -Wl,-rpath=${SRCDIR}/lib
#cgo gpu LDFLAGS: -loldzkp -lm -ldl -lgmp -lstdc++ -lprocps -loldzktrie -L/usr/local/cuda/lib64/ -lcudart -L${SRCDIR}/lib/ -Wl,-rpath=${SRCDIR}/lib
#include <stdlib.h>
#include "./lib/libzkp.h"
*/
import "C" //nolint:typecheck
import (
"encoding/json"
"scroll-tech/common/types/message"
"unsafe"
"scroll-tech/coordinator/internal/logic/verifier"
"github.com/scroll-tech/go-ethereum/log"
"scroll-tech/coordinator/internal/config"
)
// OldVerifier represents a rust ffi to a halo2 verifier.
type OldVerifier struct {
cfg *config.VerifierConfig
}
// NewOldVerifier Sets up a rust ffi to call verify.
func NewOldVerifier(cfg *config.VerifierConfig) (*OldVerifier, error) {
if cfg.MockMode {
return &OldVerifier{cfg: cfg}, nil
}
paramsPathStr := C.CString(cfg.ParamsPath)
assetsPathStr := C.CString(cfg.AssetsPath)
defer func() {
C.free(unsafe.Pointer(paramsPathStr))
C.free(unsafe.Pointer(assetsPathStr))
}()
log.Info("Init old verifier!")
C.init_batch_verifier(paramsPathStr, assetsPathStr)
C.init_chunk_verifier(paramsPathStr, assetsPathStr)
return &OldVerifier{cfg: cfg}, nil
}
// VerifyBatchProof Verify a ZkProof by marshaling it and sending it to the Halo2 OldVerifier.
func (v *OldVerifier) VerifyBatchProof(proof *message.BatchProof) (bool, error) {
if v.cfg.MockMode {
log.Info("Mock mode, batch verifier disabled")
if string(proof.Proof) == verifier.InvalidTestProof {
return false, nil
}
return true, nil
}
buf, err := json.Marshal(proof)
if err != nil {
return false, err
}
proofStr := C.CString(string(buf))
defer func() {
C.free(unsafe.Pointer(proofStr))
}()
log.Info("Start to verify batch proof ...")
verified := C.verify_batch_proof(proofStr)
return verified != 0, nil
}
// VerifyChunkProof Verify a ZkProof by marshaling it and sending it to the Halo2 OldVerifier.
func (v *OldVerifier) VerifyChunkProof(proof *message.ChunkProof) (bool, error) {
if v.cfg.MockMode {
log.Info("Mock mode, verifier disabled")
if string(proof.Proof) == verifier.InvalidTestProof {
return false, nil
}
return true, nil
}
buf, err := json.Marshal(proof)
if err != nil {
return false, err
}
proofStr := C.CString(string(buf))
defer func() {
C.free(unsafe.Pointer(proofStr))
}()
log.Info("Start to verify chunk proof ...")
verified := C.verify_chunk_proof(proofStr)
return verified != 0, nil
}

View File

@@ -5,8 +5,13 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"scroll-tech/common/version"
"time" "time"
"scroll-tech/coordinator/internal/logic/old_verifier"
jwt "github.com/appleboy/gin-jwt/v2"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto" "github.com/prometheus/client_golang/prometheus/promauto"
@@ -27,6 +32,8 @@ var (
ErrValidatorFailureProofMsgStatusNotOk = errors.New("validator failure proof msg status not ok") ErrValidatorFailureProofMsgStatusNotOk = errors.New("validator failure proof msg status not ok")
// ErrValidatorFailureProverTaskEmpty get none prover task // ErrValidatorFailureProverTaskEmpty get none prover task
ErrValidatorFailureProverTaskEmpty = errors.New("validator failure get none prover task for the proof") ErrValidatorFailureProverTaskEmpty = errors.New("validator failure get none prover task for the proof")
// ErrInvalidProverVersion means prover version is invalid.
ErrInvalidProverVersion = errors.New("prover version invalid")
// ErrValidatorFailureProverTaskCannotSubmitTwice prove task can not submit proof twice // ErrValidatorFailureProverTaskCannotSubmitTwice prove task can not submit proof twice
ErrValidatorFailureProverTaskCannotSubmitTwice = errors.New("validator failure prove task cannot submit proof twice") ErrValidatorFailureProverTaskCannotSubmitTwice = errors.New("validator failure prove task cannot submit proof twice")
// ErrValidatorFailureProofTimeout the submit proof is timeout // ErrValidatorFailureProofTimeout the submit proof is timeout
@@ -44,7 +51,8 @@ type ProofReceiverLogic struct {
db *gorm.DB db *gorm.DB
cfg *config.ProverManager cfg *config.ProverManager
verifier *verifier.Verifier verifier *verifier.Verifier
oldVerifier *old_verifier.OldVerifier
proofReceivedTotal prometheus.Counter proofReceivedTotal prometheus.Counter
proofSubmitFailure prometheus.Counter proofSubmitFailure prometheus.Counter
@@ -64,6 +72,10 @@ func NewSubmitProofReceiverLogic(cfg *config.ProverManager, db *gorm.DB, reg pro
if err != nil { if err != nil {
panic("proof receiver new verifier failure") panic("proof receiver new verifier failure")
} }
oldVf, err := old_verifier.NewOldVerifier(cfg.OldVerifier)
if err != nil {
panic("proof receiver new OldVerifier failure")
}
return &ProofReceiverLogic{ return &ProofReceiverLogic{
chunkOrm: orm.NewChunk(db), chunkOrm: orm.NewChunk(db),
batchOrm: orm.NewBatch(db), batchOrm: orm.NewBatch(db),
@@ -72,7 +84,8 @@ func NewSubmitProofReceiverLogic(cfg *config.ProverManager, db *gorm.DB, reg pro
cfg: cfg, cfg: cfg,
db: db, db: db,
verifier: vf, verifier: vf,
oldVerifier: oldVf,
proofReceivedTotal: promauto.With(reg).NewCounter(prometheus.CounterOpts{ proofReceivedTotal: promauto.With(reg).NewCounter(prometheus.CounterOpts{
Name: "coordinator_submit_proof_total", Name: "coordinator_submit_proof_total",
@@ -150,9 +163,9 @@ func (m *ProofReceiverLogic) HandleZkProof(ctx *gin.Context, proofMsg *message.P
var success bool var success bool
var verifyErr error var verifyErr error
if proofMsg.Type == message.ProofTypeChunk { if proofMsg.Type == message.ProofTypeChunk {
success, verifyErr = m.verifier.VerifyChunkProof(proofMsg.ChunkProof) success, verifyErr = m.verifyChunkProof(ctx, proofMsg.ChunkProof)
} else if proofMsg.Type == message.ProofTypeBatch { } else if proofMsg.Type == message.ProofTypeBatch {
success, verifyErr = m.verifier.VerifyBatchProof(proofMsg.BatchProof) success, verifyErr = m.verifyBatchProof(ctx, proofMsg.BatchProof)
} }
if verifyErr != nil || !success { if verifyErr != nil || !success {
@@ -383,3 +396,27 @@ func (m *ProofReceiverLogic) updateProverTaskProof(ctx context.Context, pk strin
} }
return m.proverTaskOrm.UpdateProverTaskProof(ctx, proofMsg.Type, proofMsg.ID, pk, proofBytes) return m.proverTaskOrm.UpdateProverTaskProof(ctx, proofMsg.Type, proofMsg.ID, pk, proofBytes)
} }
func (m *ProofReceiverLogic) verifyChunkProof(c *gin.Context, proof *message.ChunkProof) (bool, error) {
claims := jwt.ExtractClaims(c)
proverVersion := claims[coordinatorType.ProverVersion]
switch proverVersion.(string) {
case version.Version:
return m.verifier.VerifyChunkProof(proof)
case version.OldVersion:
return m.oldVerifier.VerifyChunkProof(proof)
}
return false, ErrInvalidProverVersion
}
func (m *ProofReceiverLogic) verifyBatchProof(c *gin.Context, proof *message.BatchProof) (bool, error) {
claims := jwt.ExtractClaims(c)
proverVersion := claims[coordinatorType.ProverVersion]
switch proverVersion.(string) {
case version.Version:
return m.verifier.VerifyBatchProof(proof)
case version.OldVersion:
return m.oldVerifier.VerifyBatchProof(proof)
}
return false, ErrInvalidProverVersion
}

View File

@@ -41,6 +41,8 @@ func NewVerifier(cfg *config.VerifierConfig) (*Verifier, error) {
C.free(unsafe.Pointer(assetsPathStr)) C.free(unsafe.Pointer(assetsPathStr))
}() }()
log.Info("Init verifier!")
C.init_batch_verifier(paramsPathStr, assetsPathStr) C.init_batch_verifier(paramsPathStr, assetsPathStr)
C.init_chunk_verifier(paramsPathStr, assetsPathStr) C.init_chunk_verifier(paramsPathStr, assetsPathStr)

View File

@@ -109,7 +109,8 @@ func setupCoordinator(t *testing.T, proversPerSession uint8, coordinatorURL stri
} }
func setEnv(t *testing.T) { func setEnv(t *testing.T) {
version.Version = "v1.2.3-aaa-bbb-ccc" version.Version = "v1.2.3-commit-prover-halo2"
version.OldZkVersion = "prover_old"
base = docker.NewDockerApp() base = docker.NewDockerApp()
base.RunDBImage(t) base.RunDBImage(t)

View File

@@ -5,6 +5,7 @@ DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" > /dev/null 2>&1 && pwd)"
PROJ_DIR=$DIR"/.." PROJ_DIR=$DIR"/.."
mkdir -p $PROJ_DIR/assets/params mkdir -p $PROJ_DIR/assets/params
wget https://circuit-release.s3.us-west-2.amazonaws.com/circuit-release/release-1220/test_seed -O $PROJ_DIR/assets/seed wget https://circuit-release.s3.us-west-2.amazonaws.com/setup/params19 -O $PROJ_DIR/assets/params/params19
wget https://circuit-release.s3.us-west-2.amazonaws.com/circuit-release/params-0320/params20 -O $PROJ_DIR/assets/params/params20 wget https://circuit-release.s3.us-west-2.amazonaws.com/setup/params20 -O $PROJ_DIR/assets/params/params20
wget https://circuit-release.s3.us-west-2.amazonaws.com/circuit-release/params-0320/params26 -O $PROJ_DIR/assets/params/params26 wget https://circuit-release.s3.us-west-2.amazonaws.com/setup/params24 -O $PROJ_DIR/assets/params/params24
wget https://circuit-release.s3.us-west-2.amazonaws.com/setup/params25 -O $PROJ_DIR/assets/params/params25