-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from clearmatics/key-verification
Key verification
- Loading branch information
Showing
19 changed files
with
871 additions
and
504 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
// Copyright (c) 2015-2020 Clearmatics Technologies Ltd | ||
// | ||
// SPDX-License-Identifier: LGPL-3.0+ | ||
|
||
#ifndef __ZECALE_CORE_AGGREGATOR_CIRCUIT_HPP__ | ||
#define __ZECALE_CORE_AGGREGATOR_CIRCUIT_HPP__ | ||
|
||
#include "libzecale/circuits/aggregator_gadget.hpp" | ||
#include "libzecale/circuits/pairing/pairing_params.hpp" | ||
#include "libzecale/circuits/verification_key_hash_gadget.hpp" | ||
|
||
#include <libzeth/core/extended_proof.hpp> | ||
|
||
using namespace libzeth; | ||
|
||
namespace libzecale | ||
{ | ||
|
||
/// Creates a circuit for creating a wrapping proof aggregating a batch of | ||
/// nested proofs. Inputs are allocated as follows: | ||
/// | ||
/// <hash of nested verification key> | ||
/// <input[1,1]> | ||
/// ... | ||
/// <input[1,M]> | ||
/// <result[1]> | ||
/// ... | ||
/// ... | ||
/// ... | ||
/// <input[N,1]> | ||
/// ... | ||
/// <input[N,M]> | ||
/// <result[N]> | ||
/// | ||
/// where: | ||
/// N = NumProofs, | ||
/// M = num_inputs_per_nested_proof, | ||
/// input[i,j] = j-th input to i-th proof, | ||
/// result[i] = result of i-th proof verification) | ||
template< | ||
typename wppT, | ||
typename wsnarkT, | ||
typename nverifierT, | ||
typename hashT, | ||
size_t NumProofs> | ||
class aggregator_circuit | ||
{ | ||
private: | ||
using npp = other_curve<wppT>; | ||
using nsnark = typename nverifierT::snark; | ||
using verification_key_variable_gadget = | ||
typename nverifierT::verification_key_variable_gadget; | ||
using proof_variable_gadget = typename nverifierT::proof_variable_gadget; | ||
|
||
const size_t _num_inputs_per_nested_proof; | ||
|
||
libsnark::protoboard<libff::Fr<wppT>> _pb; | ||
|
||
/// (Primary) Variable holding the hash of the verification key for nested | ||
/// proofs. Verified against the actual verification key values, by the | ||
/// _nested_vk_hash_gadget. | ||
libsnark::pb_variable<libff::Fr<wppT>> _nested_vk_hash; | ||
|
||
/// (Primary) The nested primary inputs lie in the scalar field | ||
/// `libff::Fr<nppT>`, and must be represented as elements of | ||
/// `libff::Fr<wppT>` for use in the wrapper proof. | ||
std::array<libsnark::pb_variable_array<libff::Fr<wppT>>, NumProofs> | ||
_nested_primary_inputs; | ||
|
||
/// (Primary) The array of the results of the verifiers. 1 meaning that the | ||
/// nested proof is valid, 0 meaning it may not be valid. | ||
std::array<libsnark::pb_variable<libff::Fr<wppT>>, NumProofs> | ||
_nested_proof_results; | ||
|
||
/// (Auxiliary) Verification key used to verify the nested proofs. Consists | ||
/// of group elements of `nppT`, which again, can be represented using | ||
/// elements in `libff::Fr<wppT>`. | ||
std::shared_ptr<verification_key_variable_gadget> _nested_vk; | ||
|
||
/// (Auxiliary) The nested proofs (defined over `nppT`) to verify. As above, | ||
/// these are verified by virtue of the fact that the base field for nppT is | ||
/// the scalar field of wppT. These gadgets handle take a witness in the | ||
/// form of a proof with group elements from nppT and represent them as | ||
/// variables in the wppT scalar field. | ||
/// (Variables are expected to be auxiliary inputs). | ||
std::array<std::shared_ptr<proof_variable_gadget>, NumProofs> | ||
_nested_proofs; | ||
|
||
/// Gadget to check the hash of the nested verification key. | ||
std::shared_ptr<verification_key_hash_gadget<wppT, nverifierT, hashT>> | ||
_nested_vk_hash_gadget; | ||
|
||
/// Gadget to aggregate proofs. | ||
std::shared_ptr<aggregator_gadget<wppT, nverifierT, NumProofs>> | ||
_aggregator_gadget; | ||
|
||
public: | ||
explicit aggregator_circuit(const size_t inputs_per_nested_proof); | ||
|
||
aggregator_circuit(const aggregator_circuit &other) = delete; | ||
const aggregator_circuit &operator=(const aggregator_circuit &other) = | ||
delete; | ||
|
||
typename wsnarkT::keypair generate_trusted_setup() const; | ||
|
||
const libsnark::protoboard<libff::Fr<wppT>> &get_constraint_system() const; | ||
|
||
/// Generate a proof and returns an extended proof | ||
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); | ||
}; | ||
|
||
} // namespace libzecale | ||
|
||
#include "aggregator_circuit.tcc" | ||
|
||
#endif // __ZECALE_CORE_AGGREGATOR_CIRCUIT_HPP__ |
Oops, something went wrong.