7 from __future__
import annotations
9 IVerificationKey, ExtendedProof
12 from zeth.api.zeth_messages_pb2
import ProofInputs
16 from os.path
import exists
19 from google.protobuf
import empty_pb2
20 from typing
import Dict, List, Tuple, Optional, Any
25 In-memory version of protobuf ProverConfig object
27 def __init__(self, zksnark_name: str, pairing_parameters: PairingParameters):
40 json_dict[
"zksnark_name"],
41 PairingParameters.from_json_dict(json_dict[
"pairing_parameters"]))
45 prover_config_proto: prover_pb2.ProverConfiguration
46 ) -> ProverConfiguration:
48 zksnark_name=prover_config_proto.zksnark,
50 prover_config_proto.pairing_parameters))
57 prover_config_file: Optional[str] =
None):
59 If config_file is not None, the ProverConfiguration will be cached in the
68 Get the ProverConfiguration for the connected server, caching in memory
69 and in `config_file` if given.
79 json.load(prover_config_f))
81 except Exception
as ex:
83 f
"prover config error '{self.prover_config_file}': {str(ex)}")
86 with grpc.insecure_channel(self.
endpoint)
as channel:
87 stub = prover_pb2_grpc.ProverStub(channel)
88 prover_config_proto = stub.GetConfiguration(_make_empty_message())
100 Get the appropriate zksnark provider, based on the server configuration.
107 Fetch the verification key from the proving service
109 with grpc.insecure_channel(self.
endpoint)
as channel:
110 stub = prover_pb2_grpc.ProverStub(channel)
111 vk_proto = stub.GetVerificationKey(_make_empty_message())
113 return zksnark.verification_key_from_proto(vk_proto)
117 proof_inputs: ProofInputs) -> Tuple[ExtendedProof, List[int]]:
119 Request a proof generation to the proving service
121 assert len(proof_inputs.js_inputs) == JS_INPUTS
122 with grpc.insecure_channel(self.
endpoint)
as channel:
123 stub = prover_pb2_grpc.ProverStub(channel)
124 extproof_and_pub_data = stub.Prove(proof_inputs)
126 extproof = zksnark.extended_proof_from_proto(
127 extproof_and_pub_data.extended_proof)
128 public_data = [
int(x, 16)
for x
in extproof_and_pub_data.public_data]
129 return extproof, public_data
132 def _make_empty_message() -> empty_pb2.Empty:
133 return empty_pb2.Empty()