def get_configuration(self) -> ProverConfiguration: """ Get the ProverConfiguration for the connected server, caching in memory and in `config_file` if given. """ if self.prover_config is not None: return self.prover_config if (self.prover_config_file is not None) and \ exists(self.prover_config_file): try: with open(self.prover_config_file, "r") as prover_config_f: self.prover_config = ProverConfiguration.from_json_dict( json.load(prover_config_f)) return self.prover_config except Exception as ex: print( f"prover config error '{self.prover_config_file}': {str(ex)}" ) unlink(self.prover_config_file) with grpc.insecure_channel(self.endpoint) as channel: stub = prover_pb2_grpc.ProverStub(channel) # type: ignore prover_config_proto = stub.GetConfiguration(_make_empty_message()) self.prover_config = prover_configuration_from_proto( prover_config_proto) if self.prover_config_file is not None: with open(self.prover_config_file, "w") as prover_config_f: json.dump(self.prover_config.to_json_dict(), prover_config_f) return self.prover_config
def get_verification_key(self) -> VerificationKey: """ Fetch the verification key from the proving service """ with grpc.insecure_channel(self.endpoint) as channel: stub = prover_pb2_grpc.ProverStub(channel) # type: ignore print("-------------- Get the verification key --------------") verificationkey = stub.GetVerificationKey(_make_empty_message()) return verificationkey
def get_proof(self, proof_inputs: ProofInputs) -> ExtendedProof: """ Request a proof generation to the proving service """ with grpc.insecure_channel(self.endpoint) as channel: stub = prover_pb2_grpc.ProverStub(channel) # type: ignore print("-------------- Get the proof --------------") proof = stub.Prove(proof_inputs) return proof
def get_verification_key(self) -> IVerificationKey: """ Fetch the verification key from the proving service """ with grpc.insecure_channel(self.endpoint) as channel: stub = prover_pb2_grpc.ProverStub(channel) # type: ignore vk_proto = stub.GetVerificationKey(_make_empty_message()) zksnark = self.get_zksnark_provider() return zksnark.verification_key_from_proto(vk_proto)
def get_proof( self, proof_inputs: ProofInputs) -> Tuple[ExtendedProof, List[int]]: """ Request a proof generation to the proving service """ assert len(proof_inputs.js_inputs) == JS_INPUTS with grpc.insecure_channel(self.endpoint) as channel: stub = prover_pb2_grpc.ProverStub(channel) # type: ignore extproof_and_pub_data = stub.Prove(proof_inputs) zksnark = self.get_zksnark_provider() extproof = zksnark.extended_proof_from_proto( extproof_and_pub_data.extended_proof) public_data = [ int(x, 16) for x in extproof_and_pub_data.public_data ] return extproof, public_data