Adds separate path for circuit files

This commit is contained in:
Ben 2024-03-29 15:58:40 +01:00
parent 61ea685d4a
commit 4bd14a498c
No known key found for this signature in database
GPG Key ID: 541B9D8C9F1426A1
3 changed files with 27 additions and 19 deletions

View File

@ -62,6 +62,7 @@ const
codex_enable_log_counter* {.booldefine.} = false
DefaultDataDir* = defaultDataDir()
DefaultCircuitDir* = defaultDataDir() / "circuits"
type
StartUpCmd* {.pure.} = enum
@ -125,6 +126,13 @@ type
abbr: "d"
name: "data-dir" }: OutDir
circuitDir* {.
desc: "Directory where Codex will store proof circuit data"
defaultValue: DefaultCircuitDir
defaultValueDesc: $DefaultCircuitDir
abbr: "cd"
name: "circuit-dir" }: OutDir
listenAddrs* {.
desc: "Multi Addresses to listen on"
defaultValue: @[

View File

@ -31,16 +31,16 @@ proc initializeFromConfig(
$config.circomZkey))
proc r1csFilePath(config: CodexConf): string =
config.dataDir / "proof_main.r1cs"
config.circuitDir / "proof_main.r1cs"
proc wasmFilePath(config: CodexConf): string =
config.dataDir / "proof_main.wasm"
config.circuitDir / "proof_main.wasm"
proc zkeyFilePath(config: CodexConf): string =
config.dataDir / "proof_main.zkey"
config.circuitDir / "proof_main.zkey"
proc zipFilePath(config: CodexConf): string =
config.dataDir / "circuit.zip"
config.circuitDir / "circuit.zip"
proc initializeFromCeremonyFiles(
config: CodexConf,
@ -73,7 +73,7 @@ proc unzipCeremonyFile(
config: CodexConf,
utils: BackendUtils): ?!void =
trace "Unzipping..."
return utils.unzipFile(config.zipFilePath, $config.dataDir)
return utils.unzipFile(config.zipFilePath, $config.circuitDir)
proc initializeFromCeremonyHash(
config: CodexConf,

View File

@ -63,13 +63,13 @@ method unzipFile*(
suite "Test BackendFactory":
let
utilsMock = BackendUtilsMock()
datadir = "testdatadir"
circuitDir = "testecircuitdir"
setup:
createDir(datadir)
createDir(circuitDir)
teardown:
removeDir(datadir)
removeDir(circuitDir)
test "Should create backend from cli config":
let
@ -105,18 +105,18 @@ suite "Test BackendFactory":
metricsAddress: ValidIpAddress.init("127.0.0.1"),
persistenceCmd: PersistenceCmd.prover,
# Set the datadir such that the tests/circuits/fixtures/ files
# Set the circuitDir such that the tests/circuits/fixtures/ files
# will be picked up as local files:
dataDir: OutDir("tests/circuits/fixtures")
circuitDir: OutDir("tests/circuits/fixtures")
)
ceremonyHash = string.none
backend = (await initializeBackend(config, ceremonyHash, utilsMock)).tryGet
check:
backend.vkp != nil
utilsMock.argR1csFile == config.dataDir / "proof_main.r1cs"
utilsMock.argWasmFile == config.dataDir / "proof_main.wasm"
utilsMock.argZKeyFile == config.dataDir / "proof_main.zkey"
utilsMock.argR1csFile == config.circuitDir / "proof_main.r1cs"
utilsMock.argWasmFile == config.circuitDir / "proof_main.wasm"
utilsMock.argZKeyFile == config.circuitDir / "proof_main.zkey"
isEmptyOrWhitespace(utilsMock.argUrl)
isEmptyOrWhitespace(utilsMock.argFilepath)
isEmptyOrWhitespace(utilsMock.argZipFile)
@ -125,7 +125,7 @@ suite "Test BackendFactory":
test "Should download and unzip ceremony file if not available":
let
ceremonyHash = some "12345"
expectedZip = datadir / "circuit.zip"
expectedZip = circuitDir / "circuit.zip"
expectedUrl = "https://circuit.codex.storage/proving-key/" & !ceremonyHash
config = CodexConf(
cmd: StartUpCmd.persistence,
@ -133,17 +133,17 @@ suite "Test BackendFactory":
discoveryIp: ValidIpAddress.init(IPv4_any()),
metricsAddress: ValidIpAddress.init("127.0.0.1"),
persistenceCmd: PersistenceCmd.prover,
dataDir: OutDir(datadir)
circuitDir: OutDir(circuitDir)
)
backend = (await initializeBackend(config, ceremonyHash, utilsMock)).tryGet
check:
backend.vkp != nil
utilsMock.argR1csFile == config.dataDir / "proof_main.r1cs"
utilsMock.argWasmFile == config.dataDir / "proof_main.wasm"
utilsMock.argZKeyFile == config.dataDir / "proof_main.zkey"
utilsMock.argR1csFile == config.circuitDir / "proof_main.r1cs"
utilsMock.argWasmFile == config.circuitDir / "proof_main.wasm"
utilsMock.argZKeyFile == config.circuitDir / "proof_main.zkey"
utilsMock.argUrl == expectedUrl
utilsMock.argFilepath == expectedZip
utilsMock.argZipFile == expectedZip
utilsMock.argOutputDir == datadir
utilsMock.argOutputDir == circuitDir