diff --git a/codex/codex.nim b/codex/codex.nim index df1e0565..b61842c5 100644 --- a/codex/codex.nim +++ b/codex/codex.nim @@ -272,9 +272,7 @@ proc new*( engine = BlockExcEngine.new(repoStore, wallet, network, blockDiscovery, peerStore, pendingBlocks) store = NetworkStore.new(engine, repoStore) prover = if config.prover: - some Prover.new( - store, - config.numProofSamples) + some Prover.new(store, config).expect("Unable to create prover.") else: none Prover diff --git a/codex/node.nim b/codex/node.nim index de9b7461..19065c99 100644 --- a/codex/node.nim +++ b/codex/node.nim @@ -740,11 +740,6 @@ proc start*(self: CodexNodeRef) {.async.} = error "Unable to start validator contract interactions: ", error=error.msg self.contracts.validator = ValidatorInteractions.none - if prover =? s.codexNode.prover: - if err =? (await prover.start(s.config)).errorOption: - error "Failed to start prover", msg = err.msg - raise err - self.networkId = self.switch.peerInfo.peerId notice "Started codex node", id = self.networkId, addrs = self.switch.peerInfo.addrs diff --git a/codex/slots/proofs/backendfactory.nim b/codex/slots/proofs/backendfactory.nim index 151c05f5..64bf76ef 100644 --- a/codex/slots/proofs/backendfactory.nim +++ b/codex/slots/proofs/backendfactory.nim @@ -5,6 +5,7 @@ import pkg/chronicles import pkg/questionable import pkg/confutils/defs import pkg/stew/io2 +import pkg/ethers import ../../conf import ./backends @@ -65,12 +66,12 @@ proc suggestDownloadTool(config: CodexConf) = $address ] - error "Proving circuit files are not found. Please run the following to download them:" & - "'./" & tokens.join(" ") & "'" + echo "Proving circuit files are not found. Please run the following to download them:" + echo "'./" & tokens.join(" ") & "'" proc initializeBackend*( config: CodexConf, - utils: BackendUtils = BackendUtils()): Future[?!AnyBackend] {.async.} = + utils: BackendUtils = BackendUtils()): ?!AnyBackend = without backend =? initializeFromConfig(config, utils), cliErr: info "Could not initialize prover backend from CLI options...", msg = cliErr.msg diff --git a/codex/slots/proofs/prover.nim b/codex/slots/proofs/prover.nim index 6696e38b..183830ae 100644 --- a/codex/slots/proofs/prover.nim +++ b/codex/slots/proofs/prover.nim @@ -43,7 +43,7 @@ type AnyProofInputs* = ProofInputs[Poseidon2Hash] Prover* = ref object of RootObj - backend: ?AnyBackend + backend: AnyBackend store: BlockStore nSamples: int @@ -62,27 +62,24 @@ proc prove*( trace "Received proof challenge" - 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 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 =? backend.prove(proofInput), err: - error "Unable to prove 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) - success (proofInput, proof) - else: - return failure("Prover was not started") + success (proofInput, proof) proc verify*( self: Prover, @@ -90,29 +87,18 @@ proc verify*( inputs: AnyProofInputs): Future[?!bool] {.async.} = ## Prove a statement using backend. ## Returns a future that resolves to a proof. - - if backend =? self.backend: - return backend.verify(proof, inputs) - else: - return failure("Prover was not started") - -proc start*( - self: Prover, - config: CodexConf): Future[?!void] {.async.} = - - without backend =? (await initializeBackend(config)), err: - error "Failed to initialize backend", msg = err.msg - return failure(err) - - self.backend = some backend - return success() + self.backend.verify(proof, inputs) proc new*( _: type Prover, store: BlockStore, - nSamples: int): Prover = + config: CodexConf): ?!Prover = - Prover( + without backend =? initializeBackend(config), err: + error "Failed to initialize backend", msg = err.msg + return failure(err) + + success Prover( store: store, - backend: none AnyBackend, - nSamples: nSamples) + backend: backend, + nSamples: config.numProofSamples)