Clearmatics Libsnark
0.1
C++ library for zkSNARK proofs
|
#include <gadget.hpp>
Public Member Functions | |
Gadget (ProtoboardPtr pb) | |
virtual void | init ()=0 |
virtual void | generateConstraints ()=0 |
virtual void | generateWitness () |
void | addUnaryConstraint (const LinearCombination &a, const ::std::string &name) |
void | addRank1Constraint (const LinearCombination &a, const LinearCombination &b, const LinearCombination &c, const ::std::string &name) |
void | enforceBooleanity (const Variable &var) |
FElem & | val (const Variable &var) |
FElem | val (const LinearCombination &lc) |
FieldType | fieldType () const |
bool | flagIsSet (const FlagVariable &flag) const |
Protected Attributes | |
ProtoboardPtr | pb_ |
Gadget class, representing the constraints and witness generation for a logical task.
Gadget hierarchy: (Here and elsewhere: R1P = Rank 1 constraints over a prime-characteristic field.) Gadgets have a somewhat cumbersome class hierarchy, for the sake of clean gadget construction. (1) A field agnostic, concrete (as opposed to interface) gadget will derive from Gadget. For instance NAND needs only AND and NOT and does not care about the field, thus it derives from Gadget. (2) Field specific interface class R1P_Gadget derives from Gadget using virtual inheritance, in order to avoid the Dreaded Diamond problem (see http://stackoverflow.com/a/21607/1756254 for more info) (3) Functional interface classes such as LooseMUX_GadgetBase virtually derive from Gadget and define special gadget functionality. For gadgets with no special interfaces we use the macro CREATE_GADGET_BASE_CLASS() for the sake of code consistency (these gadgets can work the same without this base class). This is an interface only and the implementation of AND_Gadget is field specific. (4) These field specific gadgets will have a factory class with static method create, such as AND_Gadget::create(...) in order to agnostically create this gadget for use by a field agnostic gadget. (5) Concrete field dependent gadgets derive via multiple inheritance from two interfaces. e.g. R1P_AND_Gadget derives from both AND_Gadget and R1P_Gadget. This was done to allow usage of AND_Gadget's field agnostic create() method and R1P_Gadget's field specific val() method.
Definition at line 81 of file gadget.hpp.
gadgetlib2::Gadget::Gadget | ( | ProtoboardPtr | pb | ) |
Definition at line 39 of file gadget.cpp.
void gadgetlib2::Gadget::addRank1Constraint | ( | const LinearCombination & | a, |
const LinearCombination & | b, | ||
const LinearCombination & | c, | ||
const ::std::string & | name | ||
) |
void gadgetlib2::Gadget::addUnaryConstraint | ( | const LinearCombination & | a, |
const ::std::string & | name | ||
) |
|
inline |
|
inline |
|
inline |
Definition at line 112 of file gadget.hpp.
|
pure virtual |
Implemented in gadgetlib2::R1P_Comparison_Gadget, gadgetlib2::LogicImplication_Gadget, gadgetlib2::ConditionalFlag_Gadget, gadgetlib2::Toggle_Gadget, gadgetlib2::DualWordArray_Gadget, gadgetlib2::DualWord_Gadget, gadgetlib2::R1P_EqualsConst_Gadget, gadgetlib2::R1P_IntegerPacking_Gadget, gadgetlib2::R1P_CompressionPacking_Gadget, gadgetExamples::R1P_VerifyTransactionAmounts_Gadget, gadgetlib2::R1P_LooseMUX_Gadget, gadgetlib2::R1P_InnerProduct_Gadget, gadgetExamples::HashDifficultyEnforcer_Gadget, gadgetlib2::R1P_OR_Gadget, gadgetlib2::R1P_AND_Gadget, and gadgetExamples::NAND_Gadget.
|
virtual |
Reimplemented in gadgetlib2::R1P_Comparison_Gadget, gadgetlib2::LogicImplication_Gadget, gadgetlib2::ConditionalFlag_Gadget, gadgetlib2::Toggle_Gadget, gadgetlib2::DualWordArray_Gadget, gadgetlib2::DualWord_Gadget, gadgetlib2::R1P_EqualsConst_Gadget, gadgetlib2::R1P_IntegerPacking_Gadget, gadgetlib2::R1P_CompressionPacking_Gadget, gadgetExamples::R1P_VerifyTransactionAmounts_Gadget, gadgetlib2::R1P_LooseMUX_Gadget, gadgetlib2::R1P_InnerProduct_Gadget, gadgetExamples::HashDifficultyEnforcer_Gadget, gadgetlib2::R1P_OR_Gadget, gadgetlib2::R1P_AND_Gadget, and gadgetExamples::NAND_Gadget.
Definition at line 46 of file gadget.cpp.
|
pure virtual |
|
inline |
Definition at line 110 of file gadget.hpp.
|
protected |
Definition at line 87 of file gadget.hpp.