mirror of
https://github.com/status-im/nim-codex.git
synced 2025-02-16 20:56:52 +00:00
Implements loading backend from cli files or previously downloaded local files
This commit is contained in:
parent
83e1347038
commit
c67c2e7cd7
@ -269,28 +269,6 @@ proc new*(
|
|||||||
engine = BlockExcEngine.new(repoStore, wallet, network, blockDiscovery, peerStore, pendingBlocks)
|
engine = BlockExcEngine.new(repoStore, wallet, network, blockDiscovery, peerStore, pendingBlocks)
|
||||||
store = NetworkStore.new(engine, repoStore)
|
store = NetworkStore.new(engine, repoStore)
|
||||||
prover = if config.prover:
|
prover = if config.prover:
|
||||||
if not fileAccessible($config.circomR1cs, {AccessFlags.Read}) and
|
|
||||||
endsWith($config.circomR1cs, ".r1cs"):
|
|
||||||
error "Circom R1CS file not accessible"
|
|
||||||
raise (ref Defect)(
|
|
||||||
msg: "r1cs file not readable, doesn't exist or wrong extension (.r1cs)")
|
|
||||||
|
|
||||||
if not fileAccessible($config.circomWasm, {AccessFlags.Read}) and
|
|
||||||
endsWith($config.circomWasm, ".wasm"):
|
|
||||||
error "Circom wasm file not accessible"
|
|
||||||
raise (ref Defect)(
|
|
||||||
msg: "wasm file not readable, doesn't exist or wrong extension (.wasm)")
|
|
||||||
|
|
||||||
let zkey = if not config.circomNoZkey:
|
|
||||||
if not fileAccessible($config.circomZkey, {AccessFlags.Read}) and
|
|
||||||
endsWith($config.circomZkey, ".zkey"):
|
|
||||||
error "Circom zkey file not accessible"
|
|
||||||
raise (ref Defect)(
|
|
||||||
msg: "zkey file not readable, doesn't exist or wrong extension (.zkey)")
|
|
||||||
|
|
||||||
$config.circomZkey
|
|
||||||
else: ""
|
|
||||||
|
|
||||||
some Prover.new(
|
some Prover.new(
|
||||||
store,
|
store,
|
||||||
config.numProofSamples)
|
config.numProofSamples)
|
||||||
|
@ -1,32 +1,66 @@
|
|||||||
|
import os
|
||||||
import pkg/chronos
|
import pkg/chronos
|
||||||
import pkg/questionable
|
import pkg/questionable
|
||||||
import pkg/confutils/defs
|
import pkg/confutils/defs
|
||||||
|
import pkg/stew/io2
|
||||||
|
|
||||||
import ../../conf
|
import ../../conf
|
||||||
import ./backends
|
import ./backends
|
||||||
|
|
||||||
|
proc initializeCircomBackend(
|
||||||
|
r1csFile: string,
|
||||||
|
wasmFile: string,
|
||||||
|
zKeyFile: string
|
||||||
|
): AnyBackend =
|
||||||
|
CircomCompat.init(r1csFile, wasmFile, zKeyFile)
|
||||||
|
|
||||||
proc initializeFromConfig(
|
proc initializeFromConfig(
|
||||||
config: CodexConf): ?!AnyBackend =
|
config: CodexConf): ?!AnyBackend =
|
||||||
|
if not fileAccessible($config.circomR1cs, {AccessFlags.Read}) and
|
||||||
|
endsWith($config.circomR1cs, ".r1cs"):
|
||||||
|
return failure("Circom R1CS file not accessible")
|
||||||
|
|
||||||
# check provided files exist
|
if not fileAccessible($config.circomWasm, {AccessFlags.Read}) and
|
||||||
# initialize backend with files
|
endsWith($config.circomWasm, ".wasm"):
|
||||||
# or failure
|
return failure("Circom wasm file not accessible")
|
||||||
|
|
||||||
success(CircomCompat.init($config.circomR1cs, $config.circomWasm, $config.circomZkey))
|
if not fileAccessible($config.circomZkey, {AccessFlags.Read}) and
|
||||||
|
endsWith($config.circomZkey, ".zkey"):
|
||||||
|
return failure("Circom zkey file not accessible")
|
||||||
|
|
||||||
proc initializeFromCeremonyFiles(): ?!AnyBackend =
|
success(initializeCircomBackend(
|
||||||
|
$config.circomR1cs,
|
||||||
|
$config.circomWasm,
|
||||||
|
$config.circomZkey))
|
||||||
|
|
||||||
# initialize from previously-downloaded files if they exist
|
proc r1csFilePath(config: CodexConf): string =
|
||||||
echo "todo"
|
config.dataDir / "circuit.r1cs"
|
||||||
failure("todo")
|
|
||||||
|
proc wasmFilePath(config: CodexConf): string =
|
||||||
|
config.dataDir / "circuit.wasm"
|
||||||
|
|
||||||
|
proc zkeyFilePath(config: CodexConf): string =
|
||||||
|
config.dataDir / "circuit.zkey"
|
||||||
|
|
||||||
|
proc initializeFromCeremonyFiles(config: CodexConf): ?!AnyBackend =
|
||||||
|
if fileExists(config.r1csFilePath) and
|
||||||
|
fileExists(config.wasmFilePath) and
|
||||||
|
fileExists(config.zkeyFilePath):
|
||||||
|
return success(initializeCircomBackend(
|
||||||
|
config.r1csFilePath,
|
||||||
|
config.wasmFilePath,
|
||||||
|
config.zkeyFilePath))
|
||||||
|
|
||||||
|
failure("Ceremony files not found")
|
||||||
|
|
||||||
proc initializeFromCeremonyUrl(
|
proc initializeFromCeremonyUrl(
|
||||||
|
config: CodexConf,
|
||||||
proofCeremonyUrl: ?string): Future[?!AnyBackend] {.async.} =
|
proofCeremonyUrl: ?string): Future[?!AnyBackend] {.async.} =
|
||||||
|
|
||||||
# download the ceremony url
|
# download the ceremony url
|
||||||
# unzip it
|
# unzip it
|
||||||
|
|
||||||
without backend =? initializeFromCeremonyFiles(), err:
|
without backend =? initializeFromCeremonyFiles(config), err:
|
||||||
return failure(err)
|
return failure(err)
|
||||||
return success(backend)
|
return success(backend)
|
||||||
|
|
||||||
@ -36,9 +70,9 @@ proc initializeBackend*(
|
|||||||
|
|
||||||
without backend =? initializeFromConfig(config), cliErr:
|
without backend =? initializeFromConfig(config), cliErr:
|
||||||
info "Could not initialize prover backend from CLI options...", msg = cliErr.msg
|
info "Could not initialize prover backend from CLI options...", msg = cliErr.msg
|
||||||
without backend =? initializeFromCeremonyFiles(), localErr:
|
without backend =? initializeFromCeremonyFiles(config), localErr:
|
||||||
info "Could not initialize prover backend from local files...", msg = localErr.msg
|
info "Could not initialize prover backend from local files...", msg = localErr.msg
|
||||||
without backend =? (await initializeFromCeremonyUrl(proofCeremonyUrl)), urlErr:
|
without backend =? (await initializeFromCeremonyUrl(config, proofCeremonyUrl)), urlErr:
|
||||||
warn "Could not initialize prover backend from ceremony url...", msg = urlErr.msg
|
warn "Could not initialize prover backend from ceremony url...", msg = urlErr.msg
|
||||||
return failure(urlErr)
|
return failure(urlErr)
|
||||||
return success(backend)
|
return success(backend)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user