Clearmatics Libsnark  0.1
C++ library for zkSNARK proofs
Public Member Functions | Static Public Member Functions | List of all members
gadgetExamples::HashDifficultyEnforcer_Gadget Class Reference
Inheritance diagram for gadgetExamples::HashDifficultyEnforcer_Gadget:
Inheritance graph
[legend]
Collaboration diagram for gadgetExamples::HashDifficultyEnforcer_Gadget:
Collaboration graph
[legend]

Public Member Functions

void generateConstraints ()
 
void generateWitness ()
 
- Public Member Functions inherited from gadgetlib2::Gadget
 Gadget (ProtoboardPtr pb)
 
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
 

Static Public Member Functions

static GadgetPtr create (ProtoboardPtr pb, const MultiPackedWord &hashValue, const size_t difficultyBits)
 

Additional Inherited Members

- Protected Attributes inherited from gadgetlib2::Gadget
ProtoboardPtr pb_
 

Detailed Description

Definition at line 297 of file tutorial.cpp.

Member Function Documentation

◆ create()

GadgetPtr gadgetExamples::HashDifficultyEnforcer_Gadget::create ( ProtoboardPtr  pb,
const MultiPackedWord hashValue,
const size_t  difficultyBits 
)
static

Definition at line 354 of file tutorial.cpp.

358 {
359  GadgetPtr pGadget(
360  new HashDifficultyEnforcer_Gadget(pb, hashValue, difficultyBits));
361  pGadget->init();
362  return pGadget;
363 }
Here is the caller graph for this function:

◆ generateConstraints()

void gadgetExamples::HashDifficultyEnforcer_Gadget::generateConstraints ( )
virtual

Implements gadgetlib2::Gadget.

Definition at line 365 of file tutorial.cpp.

366 {
367  // enforce that both representations are equal
368  hashValueUnpacker_->generateConstraints();
369  // add constraints asserting that the first 'difficultyBits' bits of
370  // 'hashValue' equal 0. Note endianness, unpacked()[0] is LSB and
371  // unpacked()[63] is MSB
372  for (size_t i = 0; i < difficultyBits_; ++i) {
374  hashValue_.unpacked()[63 - i],
375  GADGETLIB2_FMT("hashValue[%u] == 0", 63 - i));
376  }
377 }
Here is the call graph for this function:

◆ generateWitness()

void gadgetExamples::HashDifficultyEnforcer_Gadget::generateWitness ( )
virtual

Reimplemented from gadgetlib2::Gadget.

Definition at line 379 of file tutorial.cpp.

380 {
381  // Take the packed representation and unpack to bits.
382  hashValueUnpacker_->generateWitness();
383  // In a real setting we would add an assertion that the value will indeed
384  // satisfy the difficulty constraint, and notify the user with an error
385  // otherwise. As this is a tutorial, we'll let invalid values pass through
386  // so that we can see how isSatisfied() returns false.
387 }

The documentation for this class was generated from the following file:
gadgetlib2::GADGETLIB2_FMT
::std::string GADGETLIB2_FMT(const char *format,...)
Definition: infrastructure.cpp:49
gadgetlib2::GadgetPtr
::std::shared_ptr< Gadget > GadgetPtr
Definition: gadget.hpp:119
gadgetlib2::Gadget::addUnaryConstraint
void addUnaryConstraint(const LinearCombination &a, const ::std::string &name)
Definition: gadget.cpp:52
gadgetlib2::DualWord::unpacked
UnpackedWord unpacked() const
Definition: variable.hpp:440