/
adapters.hpp
72 lines (60 loc) · 2.91 KB
/
adapters.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/** @file
*****************************************************************************
Declaration of an adapter to POD types for interfacing to SNARKs
*****************************************************************************
* @author This file is part of libsnark, developed by SCIPR Lab
* and contributors (see AUTHORS).
* @copyright MIT license (see LICENSE file)
*****************************************************************************/
#ifndef LIBSNARK_GADGETLIB2_INCLUDE_GADGETLIB2_ADAPTERS_HPP_
#define LIBSNARK_GADGETLIB2_INCLUDE_GADGETLIB2_ADAPTERS_HPP_
#include <map>
#include <tuple>
#include <utility>
#include <libsnark/gadgetlib2/constraint.hpp>
#include <libsnark/gadgetlib2/pp.hpp>
#include <libsnark/gadgetlib2/protoboard.hpp>
#include <libsnark/gadgetlib2/variable.hpp>
using gadgetlib2::LinearTerm;
using gadgetlib2::LinearCombination;
using gadgetlib2::Constraint;
using gadgetlib2::ConstraintSystem;
using gadgetlib2::VariableAssignment;
using gadgetlib2::Protoboard;
using gadgetlib2::FElem;
namespace gadgetlib2 {
/**
* This class is a temporary hack for quick integration of Fp constraints with ppsnark. It is the
* IDDQD of classes and has "god mode" friend access to many of the gadgetlib classes. This will
* be refactored out in the future. --Shaul
*/
class GadgetLibAdapter {
public:
typedef unsigned long variable_index_t;
typedef gadgetlib2::Fp Fp_elem_t;
typedef ::std::pair<variable_index_t, Fp_elem_t> linear_term_t;
typedef ::std::vector<linear_term_t> sparse_vec_t;
typedef ::std::pair<sparse_vec_t, Fp_elem_t> linear_combination_t;
typedef ::std::tuple<linear_combination_t,
linear_combination_t,
linear_combination_t> constraint_t;
typedef ::std::vector<constraint_t> constraint_sys_t;
typedef ::std::map<variable_index_t, Fp_elem_t> assignment_t;
typedef ::std::pair<constraint_sys_t, assignment_t> protoboard_t;
GadgetLibAdapter() {};
linear_term_t convert(const LinearTerm& lt) const;
linear_combination_t convert(const LinearCombination& lc) const;
constraint_t convert(const Constraint& constraint) const;
constraint_sys_t convert(const ConstraintSystem& constraint_sys) const;
assignment_t convert(const VariableAssignment& assignment) const;
static void resetVariableIndex(); ///< Resets variable index to 0 to make variable indices deterministic.
//TODO: Kill GadgetLibAdapter::resetVariableIndex()
static size_t getNextFreeIndex(){return Variable::nextFreeIndex_;}
protoboard_t convert(const Protoboard& pb) const;
Fp_elem_t convert(FElem fElem) const;
static size_t getVariableIndex(const Variable& v){return v.index_;}
};
bool operator==(const GadgetLibAdapter::linear_combination_t& lhs,
const GadgetLibAdapter::linear_term_t& rhs);
}
#endif // LIBSNARK_GADGETLIB2_INCLUDE_GADGETLIB2_ADAPTERS_HPP_