Skip to content

Commit

Permalink
Merge pull request #84 from clearmatics/remove-generic-gadgets
Browse files Browse the repository at this point in the history
Remove generic gadgets (depends on #83)
  • Loading branch information
AntoineRondelet authored Nov 2, 2021
2 parents 8618bc9 + 8e4e34b commit c631b29
Show file tree
Hide file tree
Showing 43 changed files with 136 additions and 9,691 deletions.
10 changes: 5 additions & 5 deletions aggregator_server/aggregator_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@ namespace po = boost::program_options;

// Set the wrapper curve type (wpp) based on the build configuration.
#if defined(ZECALE_CURVE_MNT6)
#include "libzecale/circuits/pairing/mnt_pairing_params.hpp"
#include <libsnark/gadgetlib1/gadgets/pairing/mnt/mnt_pairing_params.hpp>
using wpp = libff::mnt6_pp;
#elif defined(ZECALE_CURVE_BW6_761)
#include "libzecale/circuits/pairing/bw6_761_pairing_params.hpp"
#include <libsnark/gadgetlib1/gadgets/pairing/bw6_761_bls12_377/bw6_761_pairing_params.hpp>
using wpp = libff::bw6_761_pp;
#else
#error "ZECALE_CURVE_* variable not set to supported curve"
#endif

// The nested curve type (npp)
using npp = libzecale::other_curve<wpp>;
using npp = libsnark::other_curve<wpp>;

// Set both wrapper and nested snark schemes based on the build configuration.
#if defined(ZECALE_SNARK_PGHR13)
Expand Down Expand Up @@ -175,7 +175,7 @@ class aggregator_server final : public zecale_proto::Aggregator::Service
typename nsnark::verification_key vk =
napi_handler::verification_key_from_proto(*request);
const libff::Fr<wpp> vk_hash =
libzecale::verification_key_scalar_hash_gadget<wpp, nverifier>::
libzecale::verification_key_hash_gadget<wpp, nverifier>::
compute_hash(vk, num_inputs_per_nested_proof);
const std::string vk_hash_str = libzeth::field_element_to_json(vk_hash);
response->set_hash(vk_hash_str);
Expand Down Expand Up @@ -212,7 +212,7 @@ class aggregator_server final : public zecale_proto::Aggregator::Service
napi_handler::verification_key_from_proto(vk_proto);
application_pools[name] = new application_pool(name, vk);
const libff::Fr<wpp> vk_hash =
libzecale::verification_key_scalar_hash_gadget<wpp, nverifier>::
libzecale::verification_key_hash_gadget<wpp, nverifier>::
compute_hash(vk, num_inputs_per_nested_proof);
const std::string vk_hash_str =
libzeth::field_element_to_json(vk_hash);
Expand Down
2 changes: 1 addition & 1 deletion depends/zeth
7 changes: 3 additions & 4 deletions libzecale/circuits/aggregator_circuit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#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>
Expand Down Expand Up @@ -34,10 +33,10 @@ template<typename wppT, typename wsnarkT, typename nverifierT, size_t NumProofs>
class aggregator_circuit
{
private:
using npp = other_curve<wppT>;
using npp = libsnark::other_curve<wppT>;
using nsnark = typename nverifierT::snark;
using verification_key_variable_gadget =
typename nverifierT::verification_key_scalar_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;
Expand Down Expand Up @@ -79,7 +78,7 @@ class aggregator_circuit
_nested_proofs;

/// Gadget to check the hash of the nested verification key.
std::shared_ptr<verification_key_scalar_hash_gadget<wppT, nverifierT>>
std::shared_ptr<verification_key_hash_gadget<wppT, nverifierT>>
_nested_vk_hash_gadget;

/// Gadget to aggregate proofs.
Expand Down
3 changes: 1 addition & 2 deletions libzecale/circuits/aggregator_circuit.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ aggregator_circuit<wppT, wsnarkT, nverifierT, NumProofs>::aggregator_circuit(

// Nested verification key hash gadget
_nested_vk_hash_gadget.reset(
new verification_key_scalar_hash_gadget<wppT, nverifierT>(
new verification_key_hash_gadget<wppT, nverifierT>(
_pb,
*_nested_vk,
_nested_vk_hash,
Expand Down Expand Up @@ -89,7 +89,6 @@ aggregator_circuit<wppT, wsnarkT, nverifierT, NumProofs>::aggregator_circuit(
"_nested_proof_results_packer"));

// Initialize all constraints in the circuit.
_nested_vk->generate_r1cs_constraints();
for (size_t i = 0; i < NumProofs; ++i) {
_nested_proofs[i]->generate_r1cs_constraints();
}
Expand Down
7 changes: 3 additions & 4 deletions libzecale/circuits/aggregator_gadget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
#ifndef __ZECALE_CIRCUITS_AGGREGATOR_GADGET_HPP_
#define __ZECALE_CIRCUITS_AGGREGATOR_GADGET_HPP_

#include "libzecale/circuits/pairing/pairing_params.hpp"

#include <libff/algebra/fields/field_utils.hpp>
#include <libsnark/gadgetlib1/gadget.hpp>
#include <libsnark/gadgetlib1/gadgets/basic_gadgets.hpp>
#include <libsnark/gadgetlib1/gadgets/pairing/pairing_params.hpp>
#include <libzeth/core/extended_proof.hpp>

namespace libzecale
Expand All @@ -33,14 +32,14 @@ template<typename wppT, typename nverifierT, size_t NumProofs>
class aggregator_gadget : libsnark::gadget<libff::Fr<wppT>>
{
private:
using npp = other_curve<wppT>;
using npp = libsnark::other_curve<wppT>;
using nsnark = typename nverifierT::snark;
using process_verification_key_gadget =
typename nverifierT::process_verification_key_gadget;
using online_verifier_gadget = typename nverifierT::online_verifier_gadget;
using proof_variable_gadget = typename nverifierT::proof_variable_gadget;
using verification_key_variable_gadget =
typename nverifierT::verification_key_scalar_variable_gadget;
typename nverifierT::verification_key_variable_gadget;
using processed_verification_key_variable_gadget =
typename nverifierT::processed_verification_key_variable_gadget;
using input_packing_gadget = libsnark::multipacking_gadget<libff::Fr<wppT>>;
Expand Down
57 changes: 57 additions & 0 deletions libzecale/circuits/compression_function_selector.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright (c) 2015-2021 Clearmatics Technologies Ltd
//
// SPDX-License-Identifier: LGPL-3.0+

#include <libff/algebra/curves/bw6_761/bw6_761_pp.hpp>
#include <libff/algebra/curves/mnt/mnt4/mnt4_pp.hpp>
#include <libff/algebra/curves/mnt/mnt6/mnt6_pp.hpp>
#include <libzeth/circuits/circuit_types.hpp>

namespace libzecale
{

/// Used to select a compression function depending on the scalar field of the
/// wrapping pairing-friendly curve.
template<typename wppT> class compression_function_selector
{
public:
/// By default, use the tree_hash_selector from zeth.
using compression_function =
typename libzeth::tree_hash_selector<wppT>::tree_hash;
};

template<> class compression_function_selector<libff::bw6_761_pp>
{
public:
// Constants e=17, r=93 computed via scripts/mimc_constraints.sage in
// http://github.com/clearmatics/zeth.
using compression_function = libzeth::MiMC_mp_gadget<
libff::bw6_761_Fr,
libzeth::MiMC_permutation_gadget<libff::bw6_761_Fr, 17, 93>>;
};

template<> class compression_function_selector<libff::mnt4_pp>
{
public:
// Constants e=17, r=73 computed via scripts/mimc_constraints.sage in
// http://github.com/clearmatics/zeth.
using compression_function = libzeth::MiMC_mp_gadget<
libff::mnt4_Fr,
libzeth::MiMC_permutation_gadget<libff::mnt4_Fr, 17, 73>>;
};

template<> class compression_function_selector<libff::mnt6_pp>
{
public:
// Constants e=17, r=73 computed via scripts/mimc_constraints.sage in
// http://github.com/clearmatics/zeth.
using compression_function = libzeth::MiMC_mp_gadget<
libff::mnt6_Fr,
libzeth::MiMC_permutation_gadget<libff::mnt6_Fr, 17, 73>>;
};

template<typename ppT>
using compression_function_gadget =
typename compression_function_selector<ppT>::compression_function;

} // namespace libzecale
Loading

0 comments on commit c631b29

Please sign in to comment.