Zecale - Reconciling Privacy and Scalability on Smart-Contract Chains  0.5
Reference implementation of the Zecale protocol by Clearmatics
Public Member Functions | List of all members
aggregator_server Class Referencefinal
Inheritance diagram for aggregator_server:
Inheritance graph
[legend]
Collaboration diagram for aggregator_server:
Collaboration graph
[legend]

Public Member Functions

 aggregator_server (aggregator_circuit &aggregator, const wsnark::keypair &keypair)
 
virtual ~aggregator_server ()
 
grpc::Status GetConfiguration (grpc::ServerContext *, const proto::Empty *, zecale_proto::AggregatorConfiguration *response) override
 
grpc::Status GetVerificationKey (grpc::ServerContext *, const proto::Empty *, zeth_proto::VerificationKey *response) override
 
grpc::Status GetNestedVerificationKeyHash (grpc::ServerContext *, const zeth_proto::VerificationKey *request, zecale_proto::VerificationKeyHash *response) override
 
grpc::Status RegisterApplication (grpc::ServerContext *, const zecale_proto::ApplicationDescription *registration, zecale_proto::VerificationKeyHash *response) override
 
grpc::Status SubmitNestedTransaction (grpc::ServerContext *, const zecale_proto::NestedTransaction *transaction, proto::Empty *) override
 
grpc::Status GenerateAggregatedTransaction (grpc::ServerContext *, const zecale_proto::AggregatedTransactionRequest *request, zecale_proto::AggregatedTransaction *response) override
 

Detailed Description

The aggregator_server class inherits from the Aggregator service defined in the proto files, and provides an implementation of the service.

Definition at line 80 of file aggregator_server.cpp.

Constructor & Destructor Documentation

◆ aggregator_server()

aggregator_server::aggregator_server ( aggregator_circuit aggregator,
const wsnark::keypair &  keypair 
)
inlineexplicit

Definition at line 95 of file aggregator_server.cpp.

97  : aggregator(aggregator), keypair(keypair)
98  {
99  }

◆ ~aggregator_server()

virtual aggregator_server::~aggregator_server ( )
inlinevirtual

Definition at line 101 of file aggregator_server.cpp.

102  {
103  // Release all application_pool objects.
104  for (const auto &entry : application_pools) {
105  delete entry.second;
106  }
107  application_pools.clear();
108  }

Member Function Documentation

◆ GenerateAggregatedTransaction()

grpc::Status aggregator_server::GenerateAggregatedTransaction ( grpc::ServerContext *  ,
const zecale_proto::AggregatedTransactionRequest *  request,
zecale_proto::AggregatedTransaction *  response 
)
inlineoverride

Definition at line 253 of file aggregator_server.cpp.

257  {
258  try {
259  // Get the application_pool if it exists (otherwise an exception is
260  // thrown, returning an error to the client).
261  const std::string &app_name = request->application_name();
262  std::cout << "[ACK] Aggregation tx request, app name: " << app_name
263  << std::endl;
264  application_pool *const app_pool = application_pools.at(app_name);
265 
266  // Retrieve a batch from the pool.
267  std::array<libzecale::nested_transaction<npp, nsnark>, batch_size>
268  batch;
269  const size_t num_entries = app_pool->get_next_batch(batch);
270  std::cout << "[DEBUG] Got batch of size "
271  << std::to_string(num_entries) << " from the pool\n";
272  if (num_entries == 0) {
273  throw std::runtime_error("insufficient entries in pool");
274  }
275 
276  // Extract the nested proofs
277  std::array<const libzeth::extended_proof<npp, nsnark> *, batch_size>
278  nested_proofs;
279  for (size_t i = 0; i < batch_size; ++i) {
280  nested_proofs[i] = &batch[i].extended_proof();
281 
282  std::cout << "[DEBUG] got tx " << std::to_string(i)
283  << " with ext proof:\n";
284  nested_proofs[i]->write_json(std::cout);
285  }
286 
287  // Retrieve the nested verification key for this application.
288  const nsnark::verification_key &nested_vk =
289  app_pool->verification_key();
290 
291  std::cout << "[DEBUG] Generating the batched proof...\n";
292  libzeth::extended_proof<wpp, wsnark> wrapping_proof =
293  aggregator.prove(nested_vk, nested_proofs, keypair.pk);
294 
295  std::cout << "[DEBUG] Generated extended proof:\n";
296  wrapping_proof.write_json(std::cout);
297 
298  // Populate the response with name, extended_proof and
299  // nested_parameters.
300  response->set_application_name(app_name);
301  zeth_proto::ExtendedProof *wrapping_proof_proto =
302  new zeth_proto::ExtendedProof();
303  wapi_handler::extended_proof_to_proto(
304  wrapping_proof, wrapping_proof_proto);
305  response->set_allocated_extended_proof(wrapping_proof_proto);
306  for (size_t i = 0; i < batch_size; ++i) {
307  const std::vector<uint8_t> &parameters = batch[i].parameters();
308  response->add_nested_parameters(
309  (const char *)parameters.data(), parameters.size());
310  }
311  std::cout << "[DEBUG] Written to response" << std::endl;
312  } catch (const std::exception &e) {
313  std::cout << "[ERROR] " << e.what() << std::endl;
314  return grpc::Status(
315  grpc::StatusCode::INVALID_ARGUMENT, grpc::string(e.what()));
316  } catch (...) {
317  std::cout << "[ERROR] In catch all" << std::endl;
318  return grpc::Status(grpc::StatusCode::UNKNOWN, "");
319  }
320 
321  return grpc::Status::OK;
322  }

◆ GetConfiguration()

grpc::Status aggregator_server::GetConfiguration ( grpc::ServerContext *  ,
const proto::Empty *  ,
zecale_proto::AggregatorConfiguration *  response 
)
inlineoverride

Definition at line 110 of file aggregator_server.cpp.

114  {
115  std::cout << "[INFO] Request for configuration\n";
116  libzecale::aggregator_configuration_to_proto<npp, wpp, nsnark, wsnark>(
117  *response);
118  return grpc::Status::OK;
119  }

◆ GetNestedVerificationKeyHash()

grpc::Status aggregator_server::GetNestedVerificationKeyHash ( grpc::ServerContext *  ,
const zeth_proto::VerificationKey *  request,
zecale_proto::VerificationKeyHash *  response 
)
inlineoverride

Definition at line 144 of file aggregator_server.cpp.

148  {
149  typename nsnark::verification_key vk =
150  napi_handler::verification_key_from_proto(*request);
151  const libff::Fr<wpp> vk_hash =
153  compute_hash(vk, num_inputs_per_nested_proof);
154  const std::string vk_hash_str = libzeth::field_element_to_json(vk_hash);
155  response->set_hash(vk_hash_str);
156 
157  std::cout << "[DEBUG] GetNestedVerificationKeyHash: "
158  << "vk:\n";
159  nsnark::verification_key_write_json(vk, std::cout);
160  std::cout << "\n VK hash: " << vk_hash_str << "\n";
161  return grpc::Status::OK;
162  }
Here is the call graph for this function:

◆ GetVerificationKey()

grpc::Status aggregator_server::GetVerificationKey ( grpc::ServerContext *  ,
const proto::Empty *  ,
zeth_proto::VerificationKey *  response 
)
inlineoverride

Definition at line 121 of file aggregator_server.cpp.

125  {
126  std::cout << "[ACK] Received the request to get the verification key"
127  << std::endl;
128  std::cout << "[DEBUG] Preparing verification key for response..."
129  << std::endl;
130  try {
131  wapi_handler::verification_key_to_proto(keypair.vk, response);
132  } catch (const std::exception &e) {
133  std::cout << "[ERROR] " << e.what() << std::endl;
134  return grpc::Status(
135  grpc::StatusCode::INVALID_ARGUMENT, grpc::string(e.what()));
136  } catch (...) {
137  std::cout << "[ERROR] In catch all" << std::endl;
138  return grpc::Status(grpc::StatusCode::UNKNOWN, "");
139  }
140 
141  return grpc::Status::OK;
142  }

◆ RegisterApplication()

grpc::Status aggregator_server::RegisterApplication ( grpc::ServerContext *  ,
const zecale_proto::ApplicationDescription *  registration,
zecale_proto::VerificationKeyHash *  response 
)
inlineoverride

Definition at line 164 of file aggregator_server.cpp.

168  {
169  std::cout << "[ACK] Received 'register application' request"
170  << std::endl;
171  std::cout << "[DEBUG] Registering application..." << std::endl;
172 
173  try {
174  // Ensure an app of the same name has not already been registered.
175  const std::string &name = registration->application_name();
176  if (application_pools.count(name)) {
177  return grpc::Status(
178  grpc::StatusCode::INVALID_ARGUMENT,
179  grpc::string("application already registered"));
180  }
181 
182  // Add the application to the list of supported applications on the
183  // aggregator server.
184  const zeth_proto::VerificationKey &vk_proto = registration->vk();
185  typename nsnark::verification_key vk =
186  napi_handler::verification_key_from_proto(vk_proto);
187  application_pools[name] = new application_pool(name, vk);
188  const libff::Fr<wpp> vk_hash =
190  compute_hash(vk, num_inputs_per_nested_proof);
191  const std::string vk_hash_str =
192  libzeth::field_element_to_json(vk_hash);
193  response->set_hash(vk_hash_str);
194 
195  std::cout << "[DEBUG] Registered application '" << name
196  << " with VK:\n";
197  nsnark::verification_key_write_json(vk, std::cout);
198  std::cout << "\n VK hash: " << vk_hash_str << "\n";
199  } catch (const std::exception &e) {
200  std::cout << "[ERROR] " << e.what() << std::endl;
201  return grpc::Status(
202  grpc::StatusCode::INVALID_ARGUMENT, grpc::string(e.what()));
203  } catch (...) {
204  std::cout << "[ERROR] In catch all" << std::endl;
205  return grpc::Status(grpc::StatusCode::UNKNOWN, "");
206  }
207 
208  return grpc::Status::OK;
209  }
Here is the call graph for this function:

◆ SubmitNestedTransaction()

grpc::Status aggregator_server::SubmitNestedTransaction ( grpc::ServerContext *  ,
const zecale_proto::NestedTransaction *  transaction,
proto::Empty *   
)
inlineoverride

Definition at line 211 of file aggregator_server.cpp.

215  {
216  try {
217  // Get the application_pool if it exists (otherwise an exception is
218  // thrown, returning an error to the client).
219  const std::string &app_name = transaction->application_name();
220  std::cout << "[ACK] Received nested transaction, app name: "
221  << app_name << std::endl;
222  application_pool *const app_pool = application_pools.at(app_name);
223 
224  // Sanity-check the transaction (number of inputs).
226  libzecale::nested_transaction_from_proto<npp, napi_handler>(
227  *transaction);
228  if (tx.extended_proof().get_primary_inputs().size() !=
229  num_inputs_per_nested_proof) {
230  throw std::invalid_argument("invalid number of inputs");
231  }
232 
233  // Add the proof to the pool for the named application.
234  app_pool->add_tx(tx);
235 
236  std::cout << "[DEBUG] Registered tx with ext proof:\n";
237  tx.extended_proof().write_json(std::cout) << "\n";
238 
239  std::cout << "[DEBUG] " << std::to_string(app_pool->tx_pool_size())
240  << " txs in pool\n";
241  } catch (const std::exception &e) {
242  std::cout << "[ERROR] " << e.what() << std::endl;
243  return grpc::Status(
244  grpc::StatusCode::INVALID_ARGUMENT, grpc::string(e.what()));
245  } catch (...) {
246  std::cout << "[ERROR] In catch all" << std::endl;
247  return grpc::Status(grpc::StatusCode::UNKNOWN, "");
248  }
249 
250  return grpc::Status::OK;
251  }
Here is the call graph for this function:

The documentation for this class was generated from the following file:
libzecale::nested_transaction
Definition: nested_transaction.hpp:17
libzecale::verification_key_hash_gadget::compute_hash
static FieldT compute_hash(const typename nsnark::verification_key &vk, size_t num_inputs)
libzecale::nested_transaction::extended_proof
const libzeth::extended_proof< nppT, nsnarkT > & extended_proof() const
setup.name
name
Definition: setup.py:18
libzecale::aggregator_circuit::prove
extended_proof< wppT, wsnarkT > prove(const typename nsnark::verification_key &nested_vk, const std::array< const libzeth::extended_proof< npp, nsnark > *, NumProofs > &extended_proofs, const typename wsnarkT::proving_key &aggregator_proving_key)
Generate a proof and returns an extended proof.