Clearmatics Libsnark  0.1
C++ library for zkSNARK proofs
Public Member Functions | Protected Attributes | List of all members
gadgetlib2::Gadget Class Referenceabstract

#include <gadget.hpp>

Inheritance diagram for gadgetlib2::Gadget:
Inheritance graph
[legend]

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)
 
FElemval (const Variable &var)
 
FElem val (const LinearCombination &lc)
 
FieldType fieldType () const
 
bool flagIsSet (const FlagVariable &flag) const
 

Protected Attributes

ProtoboardPtr pb_
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ Gadget()

gadgetlib2::Gadget::Gadget ( ProtoboardPtr  pb)

Definition at line 39 of file gadget.cpp.

39  : pb_(pb)
40 {
42  pb != NULL,
43  "Attempted to create gadget with uninitialized Protoboard.");
44 }

Member Function Documentation

◆ addRank1Constraint()

void gadgetlib2::Gadget::addRank1Constraint ( const LinearCombination a,
const LinearCombination b,
const LinearCombination c,
const ::std::string &  name 
)

Definition at line 58 of file gadget.cpp.

63 {
64  pb_->addRank1Constraint(a, b, c, name);
65 }
Here is the caller graph for this function:

◆ addUnaryConstraint()

void gadgetlib2::Gadget::addUnaryConstraint ( const LinearCombination a,
const ::std::string &  name 
)

Definition at line 52 of file gadget.cpp.

54 {
55  pb_->addUnaryConstraint(a, name);
56 }
Here is the caller graph for this function:

◆ enforceBooleanity()

void gadgetlib2::Gadget::enforceBooleanity ( const Variable var)
inline

Definition at line 108 of file gadget.hpp.

108 { pb_->enforceBooleanity(var); }
Here is the caller graph for this function:

◆ fieldType()

FieldType gadgetlib2::Gadget::fieldType ( ) const
inline

Definition at line 111 of file gadget.hpp.

111 { return pb_->fieldType_; }
Here is the caller graph for this function:

◆ flagIsSet()

bool gadgetlib2::Gadget::flagIsSet ( const FlagVariable flag) const
inline

Definition at line 112 of file gadget.hpp.

113  {
114  return pb_->flagIsSet(flag);
115  }

◆ generateConstraints()

virtual void gadgetlib2::Gadget::generateConstraints ( )
pure virtual

◆ generateWitness()

void gadgetlib2::Gadget::generateWitness ( )
virtual

◆ init()

virtual void gadgetlib2::Gadget::init ( )
pure virtual

◆ val() [1/2]

FElem gadgetlib2::Gadget::val ( const LinearCombination lc)
inline

Definition at line 110 of file gadget.hpp.

110 { return pb_->val(lc); }

◆ val() [2/2]

FElem& gadgetlib2::Gadget::val ( const Variable var)
inline

Definition at line 109 of file gadget.hpp.

109 { return pb_->val(var); }
Here is the caller graph for this function:

Member Data Documentation

◆ pb_

ProtoboardPtr gadgetlib2::Gadget::pb_
protected

Definition at line 87 of file gadget.hpp.


The documentation for this class was generated from the following files:
GADGETLIB_FATAL
#define GADGETLIB_FATAL(msg)
Definition: infrastructure.hpp:85
GADGETLIB_ASSERT
#define GADGETLIB_ASSERT(predicate, msg)
Definition: infrastructure.hpp:94
gadgetlib2::Gadget::pb_
ProtoboardPtr pb_
Definition: gadget.hpp:87