17 }
else if (base == 16) {
19 }
else if (base == 10) {
21 }
else if (step == 0) {
22 info(
"Step should be non zero");
29 size_t i = number[0] ==
'-' ? 1 : 0;
31 for (; i < number.size(); i += step) {
32 std::string slice = number.substr(i, step);
33 bb::fr cur_power = i + step > number.size() ?
bb::fr(base).
pow(number.size() - i) : step_power;
37 res = number[0] ==
'-' ? -res : res;
39 if (base == 2 && number[0] ==
'1' && is_signed) {
65 const std::string& fname,
82 myfile.open(fname, std::ios::out | std::ios::trunc | std::ios::binary);
90 std::string vname1 = vterms1[i].toString();
91 std::string vname2 = vterms2[i].toString();
92 std::string new_line =
"{" + mmap1[vname1] +
", " + mmap2[vname2] +
"}, // " + vname1 +
", " + vname2;
98 if (mmap1[vname1] != mmap2[vname2]) {
112 uint32_t res_idx = post.first;
113 auto left_idx =
static_cast<uint32_t
>(post.second[0]);
114 auto right_idx =
static_cast<uint32_t
>(post.second[1]);
115 bb::fr q_m = post.second[2];
116 bb::fr q_l = post.second[3];
117 bb::fr q_r = post.second[4];
118 bb::fr q_c = post.second[5];
119 packed_witness[res_idx][0] = q_m * packed_witness[left_idx][0] * packed_witness[right_idx][0] +
120 q_l * packed_witness[left_idx][0] + q_r * packed_witness[right_idx][0] + q_c;
121 packed_witness[res_idx][1] = q_m * packed_witness[left_idx][1] * packed_witness[right_idx][1] +
122 q_l * packed_witness[left_idx][1] + q_r * packed_witness[right_idx][1] + q_c;
126 msgpack::pack(
buffer, packed_witness);
129 myfile.open(fname +
".pack", std::ios::out | std::ios::trunc | std::ios::binary);
131 myfile.write(
buffer.data(),
static_cast<int64_t
>(
buffer.size()));
136 for (
const auto& vname : special) {
137 vterms.insert({ vname +
"_1", c1[vname] });
138 vterms.insert({ vname +
"_2", c2[vname] });
142 for (
const auto& vname : special) {
143 info(vname,
"_1, ", vname,
"_2 = ", mmap[vname +
"_1"],
", ", mmap[vname +
"_2"]);
145 return packed_witness;
164 const std::string& fname,
177 myfile.open(fname, std::ios::out | std::ios::trunc | std::ios::binary);
185 std::string vname = vterms[i].toString();
186 std::string new_line = mmap[vname] +
", // " + vname;
191 packed_witness.push_back(
string_to_fr(mmap[vname], base));
201 uint32_t res_idx = post.first;
202 auto left_idx =
static_cast<uint32_t
>(post.second[0]);
203 auto right_idx =
static_cast<uint32_t
>(post.second[1]);
204 bb::fr q_m = post.second[2];
205 bb::fr q_l = post.second[3];
206 bb::fr q_r = post.second[4];
207 bb::fr q_c = post.second[5];
208 packed_witness[res_idx] = q_m * packed_witness[left_idx] * packed_witness[right_idx] +
209 q_l * packed_witness[left_idx] + q_r * packed_witness[right_idx] + q_c;
213 msgpack::pack(
buffer, packed_witness);
216 myfile.open(fname +
".pack", std::ios::out | std::ios::trunc | std::ios::binary);
218 myfile.write(
buffer.data(),
static_cast<int64_t
>(
buffer.size()));
223 for (
const auto& vname : special) {
224 vterms1.insert({ vname, c[vname] });
228 for (
const auto& vname : special) {
229 info(vname,
" = ", mmap1[vname]);
231 return packed_witness;
244 fin.open(fname, std::ios::ate | std::ios::binary);
245 if (!fin.is_open()) {
246 throw std::invalid_argument(
"file not found");
248 if (fin.tellg() == -1) {
249 throw std::invalid_argument(
"something went wrong");
252 uint64_t fsize =
static_cast<uint64_t
>(fin.tellg());
253 fin.seekg(0, std::ios_base::beg);
256 char* encoded_data =
new char[fsize];
258 msgpack::unpack(encoded_data, fsize).get().convert(res);
272 fin.open(fname, std::ios::ate | std::ios::binary);
273 if (!fin.is_open()) {
274 throw std::invalid_argument(
"file not found");
276 if (fin.tellg() == -1) {
277 throw std::invalid_argument(
"something went wrong");
280 uint64_t fsize =
static_cast<uint64_t
>(fin.tellg());
281 fin.seekg(0, std::ios_base::beg);
284 char* encoded_data =
new char[fsize];
286 msgpack::unpack(encoded_data, fsize).get().convert(res);
299 auto start = std::chrono::high_resolution_clock::now();
300 bool res = s->
check();
301 auto stop = std::chrono::high_resolution_clock::now();
302 uint32_t duration_secs =
static_cast<uint32_t
>(duration_cast<std::chrono::seconds>(stop - start).count());
303 info(
"Time elapsed: ", duration_secs / 60,
" min ", duration_secs % 60,
" sec");
319 for (
size_t i = 0; i < 16; i++) {
320 limbs.emplace_back(el % 4);
323 std::reverse(limbs.begin(), limbs.end());
325 accumulators.reserve(16);
327 for (
size_t i = 0; i < 16; i++) {
328 accumulator = accumulator * 4 + limbs[i];
329 accumulators.emplace_back(accumulator);
331 std::reverse(limbs.begin(), limbs.end());
332 std::reverse(accumulators.begin(), accumulators.end());
333 return { limbs, accumulators };
346 for (
auto list :
builder.range_lists) {
348 for (uint64_t i = 0; i <= num_multiples_of_three; i++) {
349 builder.set_variable(list.second.variable_indices[i],
352 builder.set_variable(list.second.variable_indices[num_multiples_of_three + 1], list.first);
static constexpr size_t DEFAULT_PLOOKUP_RANGE_STEP_SIZE
static constexpr size_t length()
Base class for symbolic circuits.
std::vector< uint32_t > real_variable_index
size_t get_num_vars() const
std::unordered_map< uint32_t, std::vector< bb::fr > > post_process
std::unordered_map< uint32_t, STerm > symbolic_vars
std::unordered_map< std::string, std::string > model(std::unordered_map< std::string, cvc5::Term > &terms) const
uint8_t buffer[RANDOM_BUFFER_SIZE]
field< Bn254FrParams > fr
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
std::string to_string(bb::avm2::ValueTag tag)
std::vector< bb::fr > default_model_single(const std::vector< std::string > &special, smt_circuit::CircuitBase &c, const std::string &fname, bool pack)
Get pretty formatted result of the solver work.
bool smt_timer(smt_solver::Solver *s)
Get the solver result and amount of time that it took to solve.
std::vector< bb::fr > import_witness_single(const std::string &fname)
Import witness, obtained by solver, from file.
void fix_range_lists(bb::UltraCircuitBuilder &builder)
Fix the triples from range_lists in the witness.
std::pair< std::vector< bb::fr >, std::vector< bb::fr > > base4(uint32_t el)
base4 decomposition with accumulators
std::vector< std::vector< bb::fr > > default_model(const std::vector< std::string > &special, smt_circuit::CircuitBase &c1, smt_circuit::CircuitBase &c2, const std::string &fname, bool pack)
Get pretty formatted result of the solver work.
bb::fr string_to_fr(const std::string &number, int base, bool is_signed, size_t step)
Converts a string of an arbitrary base to fr. Note: there should be no prefix.
std::vector< std::vector< bb::fr > > import_witness(const std::string &fname)
Import witness, obtained by solver, from file.
BB_INLINE constexpr field pow(const uint256_t &exponent) const noexcept