sets up three paths for backend initialization
This commit is contained in:
parent
828484a646
commit
63ab4c5064
|
@ -178,7 +178,9 @@ proc start*(s: CodexServer) {.async.} =
|
|||
let proofCeremonyUrl = await s.bootstrapInteractions()
|
||||
|
||||
if prover =? s.codexNode.prover:
|
||||
prover.start(s.config, proofCeremonyUrl)
|
||||
if err =? (await prover.start(s.config, proofCeremonyUrl)).errorOption:
|
||||
error "Failed to start prover", msg = err.msg
|
||||
return # should we abort start-up this way?
|
||||
|
||||
await s.codexNode.start()
|
||||
s.restServer.start()
|
||||
|
@ -289,12 +291,10 @@ proc new*(
|
|||
$config.circomZkey
|
||||
else: ""
|
||||
|
||||
echo "Prover is some!"
|
||||
some Prover.new(
|
||||
store,
|
||||
config.numProofSamples)
|
||||
else:
|
||||
echo "Prover is none!"
|
||||
none Prover
|
||||
|
||||
codexNode = CodexNodeRef.new(
|
||||
|
|
|
@ -44,7 +44,7 @@ type
|
|||
|
||||
AnyProofInputs* = ProofInputs[Poseidon2Hash]
|
||||
Prover* = ref object of RootObj
|
||||
backend: AnyBackend
|
||||
backend: ?AnyBackend
|
||||
store: BlockStore
|
||||
nSamples: int
|
||||
|
||||
|
@ -63,24 +63,27 @@ proc prove*(
|
|||
|
||||
trace "Received proof challenge"
|
||||
|
||||
without builder =? AnyBuilder.new(self.store, manifest), err:
|
||||
error "Unable to create slots builder", err = err.msg
|
||||
return failure(err)
|
||||
if backend =? self.backend:
|
||||
without builder =? AnyBuilder.new(self.store, manifest), err:
|
||||
error "Unable to create slots builder", err = err.msg
|
||||
return failure(err)
|
||||
|
||||
without sampler =? AnySampler.new(slotIdx, self.store, builder), err:
|
||||
error "Unable to create data sampler", err = err.msg
|
||||
return failure(err)
|
||||
without sampler =? AnySampler.new(slotIdx, self.store, builder), err:
|
||||
error "Unable to create data sampler", err = err.msg
|
||||
return failure(err)
|
||||
|
||||
without proofInput =? await sampler.getProofInput(challenge, self.nSamples), err:
|
||||
error "Unable to get proof input for slot", err = err.msg
|
||||
return failure(err)
|
||||
without proofInput =? await sampler.getProofInput(challenge, self.nSamples), err:
|
||||
error "Unable to get proof input for slot", err = err.msg
|
||||
return failure(err)
|
||||
|
||||
# prove slot
|
||||
without proof =? self.backend.prove(proofInput), err:
|
||||
error "Unable to prove slot", err = err.msg
|
||||
return failure(err)
|
||||
# prove slot
|
||||
without proof =? backend.prove(proofInput), err:
|
||||
error "Unable to prove slot", err = err.msg
|
||||
return failure(err)
|
||||
|
||||
success (proofInput, proof)
|
||||
success (proofInput, proof)
|
||||
else:
|
||||
return failure("Prover was not started")
|
||||
|
||||
proc verify*(
|
||||
self: Prover,
|
||||
|
@ -89,16 +92,49 @@ proc verify*(
|
|||
## Prove a statement using backend.
|
||||
## Returns a future that resolves to a proof.
|
||||
|
||||
self.backend.verify(proof, inputs)
|
||||
if backend =? self.backend:
|
||||
return backend.verify(proof, inputs)
|
||||
else:
|
||||
return failure("Prover was not started")
|
||||
|
||||
proc initializeFromConfig(
|
||||
self: Prover,
|
||||
config: CodexConf): ?!void =
|
||||
|
||||
# check provided files exist
|
||||
# initialize backend with files
|
||||
# or failure
|
||||
|
||||
self.backend = some CircomCompat.init($config.circomR1cs, $config.circomWasm, $config.circomZkey)
|
||||
success()
|
||||
|
||||
proc initializeFromCeremonyFiles(
|
||||
self: Prover): ?!void =
|
||||
|
||||
# initialize from previously-downloaded files if they exist
|
||||
echo "todo"
|
||||
success()
|
||||
|
||||
proc initializeFromCeremonyUrl(
|
||||
self: Prover,
|
||||
proofCeremonyUrl: ?string): Future[?!void] {.async.} =
|
||||
|
||||
# download the ceremony url
|
||||
# unzip it
|
||||
return self.initializeFromCeremonyFiles()
|
||||
|
||||
proc start*(
|
||||
self: Prover,
|
||||
config: CodexConf,
|
||||
proofCeremonyUrl: ?string
|
||||
) =
|
||||
echo "prover start!"
|
||||
echo proofCeremonyUrl
|
||||
self.backend = CircomCompat.init($config.circomR1cs, $config.circomWasm, $config.circomZkey)
|
||||
proofCeremonyUrl: ?string): Future[?!void] {.async.} =
|
||||
if cliErr =? self.initializeFromConfig(config).errorOption:
|
||||
info "Could not initialize prover backend from CLI options...", msg = cliErr.msg
|
||||
if localErr =? self.initializeFromCeremonyFiles().errorOption:
|
||||
info "Could not initialize prover backend from local files...", msg = localErr.msg
|
||||
if urlErr =? (await self.initializeFromCeremonyUrl(proofCeremonyUrl)).errorOption:
|
||||
warn "Could not initialize prover backend from ceremony url...", msg = urlErr.msg
|
||||
return failure(urlErr)
|
||||
return success()
|
||||
|
||||
proc new*(
|
||||
_: type Prover,
|
||||
|
@ -107,4 +143,5 @@ proc new*(
|
|||
|
||||
Prover(
|
||||
store: store,
|
||||
backend: none AnyBackend,
|
||||
nSamples: nSamples)
|
||||
|
|
Loading…
Reference in New Issue