Clearmatics Libsnark
0.1
C++ library for zkSNARK proofs
|
Go to the documentation of this file.
30 : numInputs_(0), pParams_(pParams), fieldType_(fieldType)
40 "Assigned field element of incorrect field type in Variable \"%s\"",
54 varArray.size() >=
Log2ceil(srcValue),
56 "Variable array of size %u too small to hold value %u. Array must "
63 for (i = 0; i <
Log2ceil(srcValue); ++i) {
64 val(varArray[i]) = srcValue & (1u << i) ? 1 : 0;
66 for (; i < varArray.size(); ++i) {
72 const DualWord &dualWord,
const size_t srcValue)
83 multipackedWord.size() == 1,
84 "Multipacked word size mismatch in R1P");
85 val(multipackedWord[0]) = srcValue;
88 "Unknown protoboard type in Protoboard::setMultipackedWordValue");
99 const ::std::string &name)
123 val(flag) = newFlagState ? 1 : 0;
139 retVal +=
"Variable Assignments:\n";
141 const string varName = assignmentPair.first.name();
142 const string varAssignedValue = assignmentPair.second.asString();
143 retVal += varName +
": " + varAssignedValue +
"\n";
152 const bool multipackedEqualsValue,
const bool unpackedEqualsValue)
154 return multipackedEqualsValue != unpackedEqualsValue;
158 const bool multipackedEqualsValue,
const bool unpackedEqualsValue)
160 if (multipackedEqualsValue ==
true && unpackedEqualsValue ==
false) {
161 cout <<
"NOTE: multipacked value equals expected value but unpacked "
166 multipackedEqualsValue ==
false && unpackedEqualsValue ==
true,
167 "printInformativeNoticeMessage(...) has been called incorrectly");
168 cout <<
"NOTE: unpacked value equals expected value but multipacked "
176 const size_t expectedValue,
180 dualWord.
multipacked(), expectedValue, printOption);
182 dualWord.
unpacked(), expectedValue, printOption);
184 multipackedEqualsValue, unpackedEqualsValue)) {
186 multipackedEqualsValue, unpackedEqualsValue);
188 return multipackedEqualsValue && unpackedEqualsValue;
196 (boolValue ==
false &&
202 const size_t expectedValue,
208 multipackedWord.size() == 1,
"R1P multipacked size mismatch");
209 if (
val(multipackedWord[0]) == expectedValue) {
215 cout <<
"Expected value for multipacked word \""
216 << multipackedWord.
name() <<
"\" is: " << expectedValue
218 cout <<
"Actual value is: " <<
val(multipackedWord[0]) << endl;
222 "Unknown field type in "
223 "Protoboard::multipackedWordAssignmentEqualsValue(...)");
230 const size_t expectedValue,
234 size_t expectedValueCopy = expectedValue;
235 for (
size_t i = 0; i < unpackedWord.size(); ++i) {
236 if (
val(unpackedWord[i]) != (expectedValueCopy & 1u)) {
240 expectedValueCopy >>= 1;
242 if (expectedValueCopy != 0) {
246 cout <<
"Expected value for unpacked word \"" << unpackedWord.
name()
247 <<
"\" is: " << expectedValue << endl;
248 cout <<
"Actual values are: " << endl;
249 for (
size_t i = 0; i < unpackedWord.size(); ++i) {
250 cout <<
"bit " << i <<
": " <<
val(unpackedWord[i]) << endl;
Holds both representations of a word, both multipacked and unpacked.
void setFlag(const FlagVariable &flag, bool newFlagState=true)
FElem eval(const VariableAssignment &assignment) const
void addConstraint(const Rank1Constraint &c)
void setValuesAsBitArray(const VariableArray &varArray, const size_t srcValue)
bool expectedToPrintValues(const bool boolValue, const PrintOptions &printOption)
void enforceBooleanity(const Variable &var)
::std::string GADGETLIB2_FMT(const char *format,...)
::std::string annotation() const
::std::string name() const
const FieldType fieldType_
VariableAssignment assignment_
void setMultipackedWordValue(const MultiPackedWord &multipackedWord, const size_t srcValue)
void addGeneralConstraint(const Polynomial &a, const Polynomial &b, const ::std::string &name)
FElem & val(const Variable &var)
void printInformativeNoticeMessage(const bool multipackedEqualsValue, const bool unpackedEqualsValue)
bool isSatisfied(const PrintOptions &printOnFail=PrintOptions::NO_DBG_PRINT)
void setDualWordValue(const DualWord &dualWord, const size_t srcValue)
unsigned int Log2ceil(uint64_t i)
bool multipackedAndUnpackedValuesDisagree(const bool multipackedEqualsValue, const bool unpackedEqualsValue)
::std::string annotation() const
#define GADGETLIB_FATAL(msg)
ConstraintSystem constraintSystem_
virtual ~ProtoboardParams()=0
bool multipackedWordAssignmentEqualsValue(const MultiPackedWord &multipackedWord, const size_t expectedValue, const PrintOptions &printOption=PrintOptions::NO_DBG_PRINT) const
void addUnaryConstraint(const LinearCombination &a, const ::std::string &name)
adds a constraint of the form (a == 0)
FieldType fieldType() const
bool dualWordAssignmentEqualsValue(const DualWord &dualWord, const size_t expectedValue, const PrintOptions &printOption=PrintOptions::NO_DBG_PRINT) const
::std::string name() const
void addRank1Constraint(const LinearCombination &a, const LinearCombination &b, const LinearCombination &c, const ::std::string &name)
MultiPackedWord multipacked() const
A formal variable, field agnostic.
#define GADGETLIB_ASSERT(predicate, msg)
::std::string name() const
UnpackedWord unpacked() const
bool isSatisfied(const VariableAssignment &assignment, const PrintOptions &printOnFail=PrintOptions::NO_DBG_PRINT) const
Protoboard(const FieldType &fieldType, ParamsCPtr pParams)
bool unpackedWordAssignmentEqualsValue(const UnpackedWord &unpackedWord, const size_t expectedValue, const PrintOptions &printOption=PrintOptions::NO_DBG_PRINT) const
::std::shared_ptr< const ProtoboardParams > ParamsCPtr