Skip to content

Commit

Permalink
add : fix user verify need confog.json
Browse files Browse the repository at this point in the history
  • Loading branch information
GitTsewell committed Sep 15, 2023
1 parent 7a01899 commit 817b953
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 26 deletions.
17 changes: 1 addition & 16 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,28 +1,13 @@
package main

import (
"encoding/json"
"fmt"
"gate-zkmerkle-proof/client"
"gate-zkmerkle-proof/config"
"gate-zkmerkle-proof/global"
"github.com/spf13/cobra"
"io/ioutil"
"os"
)

func main() {
// load file
global.Cfg = &config.Config{}
jsonFile, err := ioutil.ReadFile("./config/config.json")
if err != nil {
panic(fmt.Sprintf("load config err : %s", err.Error()))
}
err = json.Unmarshal(jsonFile, global.Cfg)
if err != nil {
panic(err.Error())
}

rootCmd := &cobra.Command{
Use: "gproof",
Short: "Command line interface for interacting with gate-zkmerkle-proof",
Expand All @@ -37,7 +22,7 @@ func main() {
client.ToolCommand(),
)

if err = rootCmd.Execute(); err != nil {
if err := rootCmd.Execute(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
Expand Down
14 changes: 14 additions & 0 deletions service/keygen_service/service.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
package keygen_service

import (
"encoding/json"
"fmt"
"gate-zkmerkle-proof/circuit"
"gate-zkmerkle-proof/config"
"gate-zkmerkle-proof/global"
"gate-zkmerkle-proof/utils"
"github.com/consensys/gnark-crypto/ecc"
"github.com/consensys/gnark/backend/groth16"
"github.com/consensys/gnark/frontend"
"github.com/consensys/gnark/frontend/cs/r1cs"
"io/ioutil"
"runtime"
"strconv"
"time"
)

func Handler() {
global.Cfg = &config.Config{}
jsonFile, err := ioutil.ReadFile("./config/config.json")
if err != nil {
panic(fmt.Sprintf("load config err : %s", err.Error()))
}
err = json.Unmarshal(jsonFile, global.Cfg)
if err != nil {
panic(err.Error())
}

cir := circuit.NewBatchCreateUserCircuit(utils.AssetCounts, utils.BatchCreateUserOpsCounts)
oR1cs, err := frontend.Compile(ecc.BN254, r1cs.NewBuilder, cir, frontend.IgnoreUnconstrainedInputs())
if err != nil {
Expand Down
18 changes: 17 additions & 1 deletion service/prover_service/service.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
package prover_server

import "gate-zkmerkle-proof/global"
import (
"encoding/json"
"fmt"
"gate-zkmerkle-proof/config"
"gate-zkmerkle-proof/global"
"io/ioutil"
)

func Handler() {
global.Cfg = &config.Config{}
jsonFile, err := ioutil.ReadFile("./config/config.json")
if err != nil {
panic(fmt.Sprintf("load config err : %s", err.Error()))
}
err = json.Unmarshal(jsonFile, global.Cfg)
if err != nil {
panic(err.Error())
}

prover := NewProver(global.Cfg)
prover.Run(false)
}
32 changes: 32 additions & 0 deletions service/tool_service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"gate-zkmerkle-proof/config"
"gate-zkmerkle-proof/global"
prover_server "gate-zkmerkle-proof/service/prover_service"
"gate-zkmerkle-proof/service/witness_service"
Expand All @@ -12,12 +13,23 @@ import (
"gorm.io/driver/mysql"
"gorm.io/gorm"
"gorm.io/gorm/logger"
"io/ioutil"
"log"
"os"
"time"
)

func CleanKvrocks() {
global.Cfg = &config.Config{}
jsonFile, err := ioutil.ReadFile("./config/config.json")
if err != nil {
panic(fmt.Sprintf("load config err : %s", err.Error()))
}
err = json.Unmarshal(jsonFile, global.Cfg)
if err != nil {
panic(err.Error())
}

dbtoolConfig := global.Cfg
client := redis.NewClient(&redis.Options{
Addr: dbtoolConfig.TreeDB.Option.Addr,
Expand All @@ -36,6 +48,16 @@ func CleanKvrocks() {
}

func CheckProverStatus() {
global.Cfg = &config.Config{}
jsonFile, err := ioutil.ReadFile("./config/config.json")
if err != nil {
panic(fmt.Sprintf("load config err : %s", err.Error()))
}
err = json.Unmarshal(jsonFile, global.Cfg)
if err != nil {
panic(err.Error())
}

dbtoolConfig := global.Cfg
newLogger := logger.New(
log.New(os.Stdout, "\r\n", log.LstdFlags), // io writer
Expand Down Expand Up @@ -65,6 +87,16 @@ func CheckProverStatus() {
}

func QueryCexAssets() {
global.Cfg = &config.Config{}
jsonFile, err := ioutil.ReadFile("./config/config.json")
if err != nil {
panic(fmt.Sprintf("load config err : %s", err.Error()))
}
err = json.Unmarshal(jsonFile, global.Cfg)
if err != nil {
panic(err.Error())
}

dbtoolConfig := global.Cfg
db, err := gorm.Open(mysql.Open(dbtoolConfig.MysqlDataSource))
if err != nil {
Expand Down
11 changes: 11 additions & 0 deletions service/userproof_service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"gorm.io/driver/mysql"
"gorm.io/gorm"
"gorm.io/gorm/logger"
"io/ioutil"
"log"
"os"
"time"
Expand Down Expand Up @@ -101,6 +102,16 @@ func CalculateAccountTreeRoot(accountLeaves <-chan AccountLeave, accountTree *zk
}

func Handler() {
global.Cfg = &config.Config{}
jsonFile, err := ioutil.ReadFile("./config/config.json")
if err != nil {
panic(fmt.Sprintf("load config err : %s", err.Error()))
}
err = json.Unmarshal(jsonFile, global.Cfg)
if err != nil {
panic(err.Error())
}

userProofConfig := global.Cfg
accountTree, err := utils.NewAccountTree(userProofConfig.TreeDB.Driver, userProofConfig.TreeDB.Option.Addr)
accounts := HandleUserData(userProofConfig)
Expand Down
12 changes: 12 additions & 0 deletions service/witness_service/service.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
package witness_service

import (
"encoding/json"
"fmt"
"gate-zkmerkle-proof/config"
"gate-zkmerkle-proof/global"
"gate-zkmerkle-proof/utils"
zk_smt "github.com/gatechain/gate-zk-smt"
"io/ioutil"
)

func Handler() {
global.Cfg = &config.Config{}
jsonFile, err := ioutil.ReadFile("./config/config.json")
if err != nil {
panic(fmt.Sprintf("load config err : %s", err.Error()))
}
err = json.Unmarshal(jsonFile, global.Cfg)
if err != nil {
panic(err.Error())
}

accounts, cexAssetsInfo, accountTree := accountTree(global.Cfg)
witnessService := NewWitness(accountTree, uint32(len(accounts)), accounts, cexAssetsInfo, global.Cfg)
witnessService.Run()
Expand Down
18 changes: 9 additions & 9 deletions utils/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ var (
Uint64MaxValueFr = new(fr.Element).SetBigInt(Uint64MaxValueBigInt)
Uint64MaxValueFrSquare = new(fr.Element).SetBigInt(Uint64MaxValueBigIntSquare)
AssetTypeForTwoDigits = map[string]bool{
"BTTC": true,
"SHIB": true,
"LUNC": true,
"XEC": true,
"WIN": true,
"BIDR": true,
"SPELL": true,
"HOT": true,
"DOGE": true,
"bttc": true,
"shib": true,
"lunc": true,
"xec": true,
"win": true,
"bidr": true,
"spell": true,
"hot": true,
"doge": true,
}
)

0 comments on commit 817b953

Please sign in to comment.