bool Protoboard::dualWordAssignmentEqualsValue(const DualWord& dualWord, const size_t expectedValue, const PrintOptions& printOption) const { bool multipackedEqualsValue = multipackedWordAssignmentEqualsValue(dualWord.multipacked(), expectedValue, printOption); bool unpackedEqualsValue = unpackedWordAssignmentEqualsValue(dualWord.unpacked(), expectedValue, printOption); if (multipackedAndUnpackedValuesDisagree(multipackedEqualsValue, unpackedEqualsValue)) { printInformativeNoticeMessage(multipackedEqualsValue, unpackedEqualsValue); } return multipackedEqualsValue && unpackedEqualsValue; }
void HashDifficultyEnforcer_Gadget::generateConstraints() { // enforce that both representations are equal hashValueUnpacker_->generateConstraints(); // add constraints asserting that the first 'difficultyBits' bits of 'hashValue' equal 0. Note // endianness, unpacked()[0] is LSB and unpacked()[63] is MSB for (size_t i = 0; i < difficultyBits_; ++i) { addUnaryConstraint(hashValue_.unpacked()[63 - i], GADGETLIB2_FMT("hashValue[%u] == 0", 63 - i)); } }
void HashDifficultyEnforcer_Gadget::init() { // because we are using a prime field with large characteristic, we can assume a 64 bit value // fits in the first element of a multipacked variable. GADGETLIB_ASSERT(hashValue_.multipacked().size() == 1, "multipacked word size too large"); // A DualWord_Gadget's constraints assert that the unpacked and packed values represent the // same integer element. The generateWitnes() method has two modes, one for packing (taking the // bit representation as input) and one for unpacking (creating the bit representation from // the packed representation) hashValueUnpacker_ = DualWord_Gadget::create(pb_, hashValue_, PackingMode::UNPACK); }
void DualWordArray::push_back(const DualWord& dualWord) { multipackedContents_.push_back(dualWord.multipacked()); unpackedContents_.push_back(dualWord.unpacked()); ++numElements_; }
void Protoboard::setDualWordValue(const DualWord& dualWord, const size_t srcValue) { setMultipackedWordValue(dualWord.multipacked(), srcValue); setValuesAsBitArray(dualWord.unpacked(), srcValue); }