Skip to content

Commit

Permalink
zkCircuits: fix BaseDir handling
Browse files Browse the repository at this point in the history
until now, voconed didn't put the files inside VOCONED_DIR

now:
* `go test ./...` uses ~/.cache/vocdoni/zkCircuits/
* `node` uses ~/.vocdoni/zkCircuits/
* `voconed` uses ~/.voconed/zkCircuits/

and both `node` and `voconed` use `/app/run/zkCircuits` when inside docker
  • Loading branch information
altergui committed Oct 9, 2023
1 parent 0a35fad commit 7c854c5
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion cmd/node/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ func main() {

// Overwrite the default path to download the zksnarks circuits artifacts
// using the global datadir as parent folder.
circuit.BaseDir = filepath.Join(globalCfg.DataDir, circuit.BaseDir)
circuit.BaseDir = filepath.Join(globalCfg.DataDir, "zkCircuits")

// Ensure we can have at least 8k open files. This is necessary, since
// many components like IPFS and Tendermint require keeping many active
Expand Down
5 changes: 5 additions & 0 deletions cmd/voconed/voconed.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/spf13/viper"
"go.vocdoni.io/dvote/api/faucet"
"go.vocdoni.io/dvote/crypto/ethereum"
"go.vocdoni.io/dvote/crypto/zk/circuit"
"go.vocdoni.io/dvote/internal"
"go.vocdoni.io/dvote/log"
"go.vocdoni.io/dvote/vochain/state"
Expand Down Expand Up @@ -178,6 +179,10 @@ func main() {

log.Infof("using data directory at %s", config.dir)

// Overwrite the default path to download the zksnarks circuits artifacts
// using the global datadir as parent folder.
circuit.BaseDir = filepath.Join(config.dir, "zkCircuits")

mngKey := ethereum.SignKeys{}
if err := mngKey.AddHexKey(config.keymanager); err != nil {
log.Fatal(err)
Expand Down
20 changes: 8 additions & 12 deletions crypto/zk/circuit/circuit.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,17 @@ var downloadCircuitsTimeout = time.Minute * 5

// BaseDir is where the artifact cache is expected to be found.
// If the artifacts are not found there, they will be downloaded and stored.
// If unset ("") it will default to ~/.cache/vocdoni/zkCircuits/
//
// Defaults to ~/.cache/vocdoni/zkCircuits/
//
// In any case, the LocalDir path associated with the circuit config will be appended at the end
var BaseDir = ""

func init() {
// if base dir is unset, default to ~/.cache/vocdoni/
if BaseDir == "" {
home, err := os.UserHomeDir()
if err != nil {
panic(err)
}
BaseDir = home + "/.cache/vocdoni/zkCircuits"
var BaseDir = func() string {
home, err := os.UserHomeDir()
if err != nil {
panic(err)
}
}
return filepath.Join(home, ".cache", "vocdoni", "zkCircuits")
}()

// ZkCircuit struct wraps the circuit configuration and contains the file
// content of the circuit artifacts (provingKey, verificationKey and wasm)
Expand Down
1 change: 1 addition & 0 deletions dockerfiles/vocone/.env
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
IMAGE_TAG=main
# VOCONED_KEYMANAGER=571063b70545d01b8c130bb411b5f0220e06b8db236bb12e77ae478f7078b77b
VOCONED_DIR=/app/run
VOCONED_PORT=9090
VOCONED_URLPATH=/v2
VOCONED_BLOCKPERIOD=5
Expand Down

0 comments on commit 7c854c5

Please sign in to comment.