123 std::cout <<
"[ACK] Received the request to generate a proof"
125 std::cout <<
"[DEBUG] Parse received message to compute proof..."
132 Field root = libzeth::base_field_element_from_hex<Field>(
133 proof_inputs->mk_root());
143 if (libzeth::ZETH_NUM_JS_INPUTS != proof_inputs->js_inputs_size()) {
144 std::cout <<
"[INFO] Request with "
145 << proof_inputs->js_inputs_size()
146 <<
" inputs. Expecting "
147 << libzeth::ZETH_NUM_JS_INPUTS <<
"\n";
148 throw std::invalid_argument(
"Invalid number of JS inputs");
150 if (libzeth::ZETH_NUM_JS_OUTPUTS !=
151 proof_inputs->js_outputs_size()) {
152 throw std::invalid_argument(
"Invalid number of JS outputs");
155 std::cout <<
"[DEBUG] Process all inputs of the JoinSplit"
159 joinsplit_input<Field, libzeth::ZETH_MERKLE_TREE_DEPTH>,
160 libzeth::ZETH_NUM_JS_INPUTS>
162 for (
size_t i = 0; i < libzeth::ZETH_NUM_JS_INPUTS; i++) {
164 "\r input (%zu / %zu)\n", i, libzeth::ZETH_NUM_JS_INPUTS);
165 const zeth_proto::JoinsplitInput &received_input =
166 proof_inputs->js_inputs(i);
169 libzeth::ZETH_MERKLE_TREE_DEPTH>(received_input);
172 std::cout <<
"[DEBUG] Process all outputs of the JoinSplit"
174 std::array<libzeth::zeth_note, libzeth::ZETH_NUM_JS_OUTPUTS>
176 for (
size_t i = 0; i < libzeth::ZETH_NUM_JS_OUTPUTS; i++) {
178 "\r output (%zu / %zu)\n",
180 libzeth::ZETH_NUM_JS_OUTPUTS);
181 const zeth_proto::ZethNote &received_output =
182 proof_inputs->js_outputs(i);
185 joinsplit_outputs[i] = parsed_output;
188 std::cout <<
"[DEBUG] Data parsed successfully" << std::endl;
189 std::cout <<
"[DEBUG] Generating the proof..." << std::endl;
191 std::vector<Field> public_data;
203 std::cout <<
"[DEBUG] Displaying extended proof and public data\n";
205 for (
const Field &f : public_data) {
210 if (!extproof_json_output_file.empty()) {
211 std::cout <<
"[DEBUG] Writing extended proof (JSON) to "
212 << extproof_json_output_file <<
"\n";
213 std::ofstream out_s(extproof_json_output_file.c_str());
216 if (!proof_output_file.empty()) {
217 std::cout <<
"[DEBUG] Writing proof to " << proof_output_file
219 std::ofstream out_s =
221 snark::proof_write_bytes(ext_proof.
get_proof(), out_s);
223 if (!primary_output_file.empty()) {
224 std::cout <<
"[DEBUG] Writing primary input to "
225 << primary_output_file <<
"\n";
227 primary_output_file.c_str());
231 if (!assignment_output_file.empty()) {
232 std::cout <<
"[DEBUG] WARNING! Writing assignment to "
233 << assignment_output_file <<
"\n";
235 assignment_output_file.c_str());
240 std::cout <<
"[DEBUG] Preparing response..." << std::endl;
241 api_handler::extended_proof_to_proto(
242 ext_proof, proof_and_public_data->mutable_extended_proof());
243 for (
size_t i = 0; i < public_data.size(); ++i) {
244 proof_and_public_data->add_public_data(
248 }
catch (
const std::exception &e) {
249 std::cout <<
"[ERROR] " << e.what() << std::endl;
251 grpc::StatusCode::INVALID_ARGUMENT, grpc::string(e.what()));
253 std::cout <<
"[ERROR] In catch all" << std::endl;
254 return grpc::Status(grpc::StatusCode::UNKNOWN,
"");
257 return grpc::Status::OK;