Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
safe_uint.test.cpp
Go to the documentation of this file.
1#include "safe_uint.hpp"
2#include "../byte_array/byte_array.hpp"
8#include "gmock/gmock.h"
9#include <cstddef>
10#include <gtest/gtest.h>
11
12using namespace bb;
13
14#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
15#pragma GCC diagnostic ignored "-Wunused-const-variable"
16
17#define STDLIB_TYPE_ALIASES \
18 using Builder = TypeParam; \
19 using witness_ct = stdlib::witness_t<Builder>; \
20 using field_ct = stdlib::field_t<Builder>; \
21 using bool_ct = stdlib::bool_t<Builder>; \
22 using suint_ct = stdlib::safe_uint_t<Builder>; \
23 using byte_array_ct = stdlib::byte_array<Builder>; \
24 using public_witness_ct = stdlib::public_witness_t<Builder>;
25
26namespace {
28}
29
30using namespace bb;
31
32template <class T> void ignore_unused(T&) {} // use to ignore unused variables in lambdas
33
34template <class Builder> class SafeUintTest : public ::testing::Test {};
35
36using CircuitTypes = ::testing::Types<bb::UltraCircuitBuilder>;
38
40// CONSTRUCTOR
41
42TYPED_TEST(SafeUintTest, TestConstructorWithValueOutOfRangeFails)
43{
45 auto builder = Builder();
46
47 // check incorrect range init causes failure
48
50
51 // Check the tag is preserved during construction
52 a.set_origin_tag(first_and_third_merged_tag);
53 suint_ct b(a, 2, "b");
54
55 EXPECT_FALSE(CircuitChecker::check(builder));
56 EXPECT_EQ(b.get_origin_tag(), first_and_third_merged_tag);
57}
58
59TYPED_TEST(SafeUintTest, TestConstructorWithValueInRange)
60{
62 auto builder = Builder();
63
65 suint_ct b(a, 7);
66
67 EXPECT_TRUE(CircuitChecker::check(builder));
68}
69
70// * OPERATOR
71
76{
78 auto builder = Builder();
79
82 suint_ct c(a, 2);
83 c.set_origin_tag(submitted_value_origin_tag);
84 suint_ct d(b, 4);
85 d.set_origin_tag(challenge_origin_tag);
86 c = c * d;
87
88 EXPECT_TRUE(CircuitChecker::check(builder));
89 EXPECT_EQ(c.get_origin_tag(), first_two_merged_tag);
90}
94#if !defined(__wasm__)
95TYPED_TEST(SafeUintTest, TestMultiplyOperationOutOfRangeFails)
96{
98 auto builder = Builder();
99 // Since max is initially set to (1 << 2) - 1 = 3 (as bit range checks are easier than generic integer bounds),
100 // should allow largest power of 3 smaller than r iterations, which is 159. Hence below we should exceed r, and
101 // expect a throw
103 suint_ct c(a, 2);
104 suint_ct d(a, 2);
105 // should not fail on 159 iterations, since 3**160 < r < 3**161
106 for (auto i = 0; i < 159; i++) {
107 c = c * d;
108 }
109 EXPECT_TRUE(CircuitChecker::check(builder));
110 try {
111 // should throw an overflow error on the 160th iteration
112 c = c * d;
113 FAIL() << "Expected out of range error";
114 } catch (std::runtime_error const& err) {
115 EXPECT_TRUE(CircuitChecker::check(builder)); // no failing constraints should be created from multiply
116 EXPECT_THAT(err.what(), testing::HasSubstr("exceeded modulus in safe_uint class"));
117 } catch (...) {
118 FAIL() << "Expected std::runtime_error modulus in safe_uint class";
119 }
120}
121
125TYPED_TEST(SafeUintTest, TestMultiplyOperationOnConstantsOutOfRangeFails)
126{
128 auto builder = Builder();
129 // Now we check that when using constants the maximum grows more slowly - since they are bounded by themselves
130 // rather than the next 2^n-1
131
133 suint_ct c(a, 2);
134 suint_ct d(fr(2));
135
136 // should not fail on 252 iterations
137 for (auto i = 0; i < 252; i++) {
138 c = c * d;
139 }
140 EXPECT_TRUE(CircuitChecker::check(builder));
141 // Below we should exceed r, and expect a throw
142
143 try {
144 // should fail on the 253rd iteration
145 c = c * d;
146 FAIL() << "Expected out of range error";
147 } catch (std::runtime_error const& err) {
148 EXPECT_TRUE(CircuitChecker::check(builder)); // no failing constraint from multiply
149 EXPECT_THAT(err.what(), testing::HasSubstr("exceeded modulus in safe_uint class"));
150 } catch (...) {
151 FAIL() << "Expected std::runtime_error modulus in safe_uint class";
152 }
153}
154// + OPERATOR
159{
161 auto builder = Builder();
162
165 suint_ct c(a, 2);
166 c.set_origin_tag(submitted_value_origin_tag);
167 suint_ct d(b, 4);
168 d.set_origin_tag(challenge_origin_tag);
169 c = c + d;
170
171 EXPECT_TRUE(CircuitChecker::check(builder));
172 EXPECT_EQ(c.get_origin_tag(), first_two_merged_tag);
173}
177TYPED_TEST(SafeUintTest, TestAddOperationOutOfRangeFails)
178{
180 auto builder = Builder();
181 // Here we test the addition operator also causes a throw when exceeding r
183 suint_ct c(a, 2);
184 suint_ct d(a, 2);
185 // should not fail on the initial setup
186 for (auto i = 0; i < 159; i++) {
187 c = c * d;
188 }
189 EXPECT_TRUE(CircuitChecker::check(builder));
190 try {
191 // should fail when we add and exceed the modulus
192 c = c + c;
193 FAIL() << "Expected out of range error";
194 } catch (std::runtime_error const& err) {
195 EXPECT_TRUE(CircuitChecker::check(builder)); // no failing constraints from add or multiply
196 EXPECT_THAT(err.what(), testing::HasSubstr("exceeded modulus in safe_uint class"));
197 } catch (...) {
198 FAIL() << "Expected std::runtime_error modulus in safe_uint class";
199 }
200}
201#endif
202
203// SUBTRACT METHOD
204
209{
211 auto builder = Builder();
212
215 suint_ct c(a, 2);
216 c.set_origin_tag(submitted_value_origin_tag);
217 suint_ct d(b, 4);
218 d.set_origin_tag(challenge_origin_tag);
219 c = d.subtract(c, 3); // result is 7, which fits in 3 bits and does not fail the range constraint
220
221 EXPECT_TRUE(CircuitChecker::check(builder));
222 // Subtract merges tags
223 EXPECT_EQ(c.get_origin_tag(), first_two_merged_tag);
224}
225
230TYPED_TEST(SafeUintTest, TestSubtractResultOutOfRange)
231{
233 auto builder = Builder();
234 // test failure when range for difference too small
235
238 suint_ct c(a, 2, "c");
239 suint_ct d(b, 4, "d");
240 c = d.subtract(c, 2, "d - c"); // we can't be sure that 4-bits minus 2-bits is 2-bits.
241
242 EXPECT_FALSE(CircuitChecker::check(builder));
243}
244
250#if !defined(__wasm__)
251TYPED_TEST(SafeUintTest, TestSubtractUnderflowGeneral)
252{
254 auto builder = Builder();
255
258 suint_ct c(a, 0);
259 suint_ct d(b, 1);
260 c = c.subtract(d, suint_ct::MAX_BIT_NUM);
261 EXPECT_FALSE(CircuitChecker::check(builder));
262}
263#endif
264
269#if !defined(__wasm__)
270TYPED_TEST(SafeUintTest, TestSubtractUnderflowSpecial)
271{
273 auto builder = Builder();
274
277 suint_ct c(a, 2);
278 suint_ct d(b, suint_ct::MAX_BIT_NUM);
279 try {
280 c = c.subtract(d, suint_ct::MAX_BIT_NUM);
281 FAIL() << "Expected out of range error";
282 } catch (std::runtime_error const& err) {
283 EXPECT_TRUE(CircuitChecker::check(builder));
284 EXPECT_EQ(err.what(), std::string("maximum value exceeded in safe_uint subtract"));
285 } catch (...) {
286 FAIL() << "Expected std::runtime_error modulus in safe_uint class";
287 }
288}
289#endif
290
291// - OPERATOR
292
296TYPED_TEST(SafeUintTest, TestMinusOperator)
297{
299 auto builder = Builder();
300
303 suint_ct c(a, 4);
304 c.set_origin_tag(submitted_value_origin_tag);
305 suint_ct d(b, 2);
306 d.set_origin_tag(challenge_origin_tag);
307 c = c - d; // 9 - 2 = 7 should not underflow
308
309 EXPECT_TRUE(CircuitChecker::check(builder));
310 // Minus operator in safe_uint merges tags
311 EXPECT_EQ(c.get_origin_tag(), first_two_merged_tag);
312}
313
317#if !defined(__wasm__)
318TYPED_TEST(SafeUintTest, TestMinusOperatorValidOnZero)
319{
321 auto builder = Builder();
322
325 suint_ct c(a, 2);
326 suint_ct d(b, 3);
327 c = c - d; // 2 - 2 = 0 should not overflow, even if d has more bits than c.
328 EXPECT_TRUE(CircuitChecker::check(builder));
329}
330#endif
331
336#if !defined(__wasm__)
337TYPED_TEST(SafeUintTest, TestMinusUnderflowGeneral1)
338{
340 auto builder = Builder();
341
344 suint_ct c(a, 2);
345 suint_ct d(b, suint_ct::MAX_BIT_NUM);
346 c = c - d; // generates range constraint that the difference is in [0, 3], which it is not with these witness values
347 EXPECT_FALSE(CircuitChecker::check(builder));
348}
349#endif
350
355#if !defined(__wasm__)
356TYPED_TEST(SafeUintTest, TestMinusUnderflowGeneral2)
357{
359 auto builder = Builder();
360
363 suint_ct c(a, 2);
364 suint_ct d(b, 3);
365 c = c - d;
366 EXPECT_FALSE(CircuitChecker::check(builder)); // underflow should cause range constraint to fail
367}
368#endif
369
376#if !defined(__wasm__)
377TYPED_TEST(SafeUintTest, TestMinusUnderflowSpecial1)
378{
380 auto builder = Builder();
381
384 suint_ct c(a, suint_ct::MAX_BIT_NUM);
385 suint_ct d(b, suint_ct::MAX_BIT_NUM);
386 try {
387 c = c - d; // even though this is not an underflow, we cannot distinguish it from an actual underflow
388 // because the sum of maxes exceeds MAX_VALUE so we must throw an error
389 FAIL() << "Expected error to be thrown";
390 } catch (std::runtime_error const& err) {
391 EXPECT_TRUE(CircuitChecker::check(builder)); // no incorrect constraints
392 EXPECT_EQ(err.what(),
393 std::string("maximum value exceeded in safe_uint minus operator")); // possible underflow is
394 // detected with check on maxes
395 } catch (...) {
396 FAIL() << "Expected no error, got other error";
397 }
398}
399#endif
400
407#if !defined(__wasm__)
408TYPED_TEST(SafeUintTest, TestMinusUnderflowSpecial2)
409{
411 auto builder = Builder();
412
415 suint_ct c(a, suint_ct::MAX_BIT_NUM);
416 suint_ct d(b, suint_ct::MAX_BIT_NUM);
417 try {
418 c = c - d; // underflow and error should be thrown
419 FAIL() << "Expected error to be thrown";
420 } catch (std::runtime_error const& err) {
421 EXPECT_FALSE(CircuitChecker::check(builder)); // underflow causes failing constraint
422 EXPECT_EQ(err.what(),
423 std::string("maximum value exceeded in safe_uint minus operator")); // possible underflow is
424 // detected with check on maxes
425 } catch (...) {
426 FAIL() << "Expected no error, got other error";
427 }
428}
429#endif
430
431// DIVIDE METHOD
432
433TYPED_TEST(SafeUintTest, TestDivideMethod)
434{
436 auto builder = Builder();
437
438 field_ct a1(witness_ct(&builder, 2));
439 field_ct b1(witness_ct(&builder, 9));
442 suint_ct c1(a1, 2);
443 c1.set_origin_tag(submitted_value_origin_tag);
444 suint_ct d1(b1, 4);
445 d1.set_origin_tag(challenge_origin_tag);
446 c1 = d1.divide(c1, 3, 1);
447
448 // .divide(other) merges tags
449 EXPECT_EQ(c1.get_origin_tag(), first_two_merged_tag);
450
451 field_ct a2(witness_ct(&builder, engine.get_random_uint8()));
452 field_ct b2(witness_ct(&builder, engine.get_random_uint32()));
453 suint_ct c2(a2, 8);
454 suint_ct d2(b2, 32);
455 c2 = d2.divide(c2, 32, 8);
456
457 EXPECT_TRUE(CircuitChecker::check(builder));
458}
459
460TYPED_TEST(SafeUintTest, TestDivideMethodQuotientRangeTooSmallFails)
461{
463 auto builder = Builder();
464
467 suint_ct c(a, 2);
468 suint_ct d(b, 6);
469 d = d.divide(c, 4, 1, "d/c");
470
471 EXPECT_FALSE(CircuitChecker::check(builder));
472}
473
474#if !defined(__wasm__)
475TYPED_TEST(SafeUintTest, TestDivideRemainderTooLarge)
476{
478 auto builder = Builder();
479 // test failure when range for remainder too small
480
482 suint_ct c(a, 3);
483 suint_ct d((fr::modulus - 1) / 3);
484 suint_ct b;
485 EXPECT_ANY_THROW(b = c / d);
486}
487#endif
488
489TYPED_TEST(SafeUintTest, TestDivideMethodQuotientRemainderIncorrectFails)
490{
492 auto builder = Builder();
493 // test failure when quotient and remainder values are wrong
494
497 suint_ct c(a, 3);
498 suint_ct d(b, 5);
499 d = d.divide(c, 3, 2, "d/c", [](uint256_t, uint256_t) { return std::make_pair(2, 3); });
500
501 EXPECT_FALSE(CircuitChecker::check(builder));
502}
503
504TYPED_TEST(SafeUintTest, TestDivideMethodQuotientRemainderModRFails)
505{
507 auto builder = Builder();
508 // test failure when quotient and remainder are only correct mod r
509
512 suint_ct c(a, 3);
513 suint_ct d(b, 5);
514 d = d.divide(c, 3, 1, "d/c", [](uint256_t a, uint256_t b) { return std::make_pair((fr)a / (fr)b, 0); });
515 // 19 / 5 in the field is 0x1d08fbde871dc67f6e96903a4db401d17e858b5eaf6f438a5bedf9bf2999999e, so the
516 // quotient should fail the range check of 3-bits.
517
518 EXPECT_FALSE(CircuitChecker::check(builder));
519}
520
521TYPED_TEST(SafeUintTest, TestDivOperator)
522{
524 auto builder = Builder();
525
526 suint_ct a(witness_ct(&builder, 1000), 10, "a");
527 a.set_origin_tag(submitted_value_origin_tag);
528 suint_ct b(2, 2, "b");
529 b.set_origin_tag(challenge_origin_tag);
530
531 a = a / b;
532
533 EXPECT_TRUE(CircuitChecker::check(builder));
534 // Division operator merges tags
535 EXPECT_EQ(a.get_origin_tag(), first_two_merged_tag);
536}
537
538// / OPERATOR
539
540TYPED_TEST(SafeUintTest, TestDivideOperator)
541{
543 auto builder = Builder();
544 // test success cases
545 {
546 auto builder = Builder();
547 field_ct a1(witness_ct(&builder, 2));
548 field_ct b1(witness_ct(&builder, 9));
549 suint_ct c1(a1, 2);
550 suint_ct d1(b1, 4);
551 d1 / c1;
552
553 field_ct a2(witness_ct(&builder, engine.get_random_uint8()));
554 field_ct b2(witness_ct(&builder, engine.get_random_uint32()));
555 suint_ct c2(a2, 8);
556 suint_ct d2(b2, 32);
557 d2 / c2;
558
559 bool result = CircuitChecker::check(builder);
560 EXPECT_EQ(result, true);
561 }
562 // test failure when range for quotient too small
563 {
564 auto builder = Builder();
567 suint_ct c(a, 2);
568 suint_ct d(b, 5);
569 d = d / c;
570 bool result = CircuitChecker::check(builder);
571 EXPECT_EQ(result, false);
572 }
573 // test failure when range for remainder too small
574 {
575
578 suint_ct c(a, 2);
579 suint_ct d(b, 5);
580 d = d / c;
581 bool result = CircuitChecker::check(builder);
582 EXPECT_EQ(result, false);
583 }
584 // test failure when quotient and remainder values are wrong
585 {
586 auto builder = Builder();
589 suint_ct c(a, 2);
590 suint_ct d(b, 5);
591 d = d / c;
592 bool result = CircuitChecker::check(builder);
593 EXPECT_EQ(result, false);
594 }
595 // test failure when quotient and remainder are only correct mod r
596 {
597 auto builder = Builder();
600 suint_ct c(a, 2);
601 suint_ct d(b, 5);
602 d = d / c;
603 bool result = CircuitChecker::check(builder);
604 EXPECT_EQ(result, false);
605 }
606}
607
608// SLICE
609
611{
613 auto builder = Builder();
614
615 // 0b11110110101001011
616 // ^ ^
617 // msb lsb
618 // 10 3
619 // hi=0x111101, lo=0x011, slice=0x10101001
620 //
621 suint_ct a(witness_ct(&builder, fr(126283)), 17);
622 a.set_origin_tag(next_challenge_tag);
623 auto slice_data = a.slice(10, 3);
624
625 EXPECT_EQ(slice_data[0].get_value(), fr(3));
626 EXPECT_EQ(slice_data[1].get_value(), fr(169));
627 EXPECT_EQ(slice_data[2].get_value(), fr(61));
628
629 // Slice preserves tags
630 EXPECT_EQ(slice_data[0].get_origin_tag(), next_challenge_tag);
631 EXPECT_EQ(slice_data[1].get_origin_tag(), next_challenge_tag);
632 EXPECT_EQ(slice_data[2].get_origin_tag(), next_challenge_tag);
633
634 bool result = CircuitChecker::check(builder);
635 EXPECT_TRUE(result);
636}
637
638TYPED_TEST(SafeUintTest, TestSliceEqualMsbLsb)
639{
641 auto builder = Builder();
642
643 // 0b11110110101001011
644 // ^
645 // msb = lsb
646 // 6
647 // hi=0b1111011010, lo=0b001011, slice=0b1
648 //
649 suint_ct a(witness_ct(&builder, fr(126283)), 17);
650 auto slice_data = a.slice(6, 6);
651
652 EXPECT_EQ(slice_data[0].get_value(), fr(11));
653 EXPECT_EQ(slice_data[1].get_value(), fr(1));
654 EXPECT_EQ(slice_data[2].get_value(), fr(986));
655
656 bool result = CircuitChecker::check(builder);
657 EXPECT_TRUE(result);
658}
659
660TYPED_TEST(SafeUintTest, TestSliceRandom)
661{
663 auto builder = Builder();
664
665 uint8_t lsb = 106;
666 uint8_t msb = 189;
667 fr a_ = fr(uint256_t(fr::random_element()) && ((uint256_t(1) << 252) - 1));
668 suint_ct a(witness_ct(&builder, a_), 252);
669 auto slice = a.slice(msb, lsb);
670
671 const uint256_t expected0 = uint256_t(a_) & ((uint256_t(1) << uint64_t(lsb)) - 1);
672 const uint256_t expected1 = (uint256_t(a_) >> lsb) & ((uint256_t(1) << (uint64_t(msb - lsb) + 1)) - 1);
673 const uint256_t expected2 =
674 (uint256_t(a_) >> uint64_t(msb + 1)) & ((uint256_t(1) << (uint64_t(252 - msb) - 1)) - 1);
675
676 EXPECT_EQ(slice[0].get_value(), fr(expected0));
677 EXPECT_EQ(slice[1].get_value(), fr(expected1));
678 EXPECT_EQ(slice[2].get_value(), fr(expected2));
679
680 bool result = CircuitChecker::check(builder);
681 EXPECT_TRUE(result);
682}
683
688TYPED_TEST(SafeUintTest, TestOperatorDivRemainderConstraint)
689{
691 auto builder = Builder();
692
693 uint256_t val = 5;
694
695 suint_ct a(witness_ct(&builder, val), 32);
696 suint_ct b(witness_ct(&builder, val), 32);
697
698 uint256_t quotient_val = 0;
699 uint256_t remainder_val = val;
700 field_ct quotient_field(witness_ct(&builder, quotient_val));
701 field_ct remainder_field(witness_ct(&builder, remainder_val));
702 suint_ct quotient(quotient_field, (size_t)(a.current_max.get_msb() + 1));
703 suint_ct remainder(remainder_field, (size_t)(a.current_max.get_msb() + 1));
704 // This line implicitly checks we are not overflowing
705 suint_ct int_val = quotient * b + remainder;
706
707 // Idiomatic constraint
708 // We constrain divisor - remainder - 1 to be positive to ensure that remainder < divisor.
709 suint_ct delta = b - remainder - 1;
710 field_ct::from_witness_index(delta.value.context, delta.value.get_witness_index())
711 .create_range_constraint(static_cast<size_t>(b.current_max.get_msb() + 1));
712
713 // // More rudimentary constraint
714 // // We constrain divisor - remainder - 1 to be positive to ensure that remainder < divisor.
715 // const uint256_t delta = b.get_value() - remainder_val - 1;
716 // const uint32_t delta_idx = builder.add_variable(delta);
717
718 // // constraint: other - remainder - delta - 1 == 0
719 // const add_triple delta_gate{ .a = b.get_witness_index(),
720 // .b = remainder.get_witness_index(),
721 // .c = delta_idx,
722 // .a_scaling = 1,
723 // .b_scaling = -1,
724 // .c_scaling = -1,
725 // .const_scaling = -1 };
726
727 // builder.create_add_gate(delta_gate);
728
729 // // validate delta is in the correct range
730 // field_ct::from_witness_index(&builder, delta_idx).create_range_constraint(b.current_max.get_msb() + 1);
731
732 a.assert_equal(int_val);
733
734 bool result = CircuitChecker::check(builder);
735 EXPECT_EQ(result, false);
736}
737
742TYPED_TEST(SafeUintTest, TestDivRemainderConstraint)
743{
745 auto builder = Builder();
746
747 uint256_t val = 5;
748
749 suint_ct a(witness_ct(&builder, val), 32);
750 suint_ct b(witness_ct(&builder, val), 32);
751
752 // set quotient to 0 and remainder to val.
753 auto supply_bad_witnesses = [](uint256_t val, [[maybe_unused]] uint256_t divisor) {
754 return std::make_pair(0, val);
755 };
756
757 a.divide(b, 32, 32, "", supply_bad_witnesses);
758
759 bool result = CircuitChecker::check(builder);
760 EXPECT_EQ(result, false);
761}
762
763TYPED_TEST(SafeUintTest, TestByteArrayConversion)
764{
766 auto builder = Builder();
767
768 field_ct elt = witness_ct(&builder, 0x7f6f5f4f00010203);
769 elt.set_origin_tag(next_challenge_tag);
770 suint_ct safe(elt, 63);
771 // safe.value is a uint256_t, so we serialize to a 32-byte array
772 std::string expected = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
773 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
774 0x00, 0x00, 0x7f, 0x6f, 0x5f, 0x4f, 0x00, 0x01, 0x02, 0x03 };
775
777 arr.write(static_cast<byte_array_ct>(safe));
778 EXPECT_EQ(arr.get_string(), expected);
779 // Conversion to byte_array preserves tags
780 for (const auto& single_byte : arr.bytes()) {
781 EXPECT_EQ(single_byte.get_origin_tag(), next_challenge_tag);
782 }
783 EXPECT_EQ(arr.get_origin_tag(), next_challenge_tag);
784}
static bool check(const Builder &circuit)
Check the witness satisifies the circuit.
Represents a dynamic array of bytes in-circuit.
byte_array & write(byte_array const &other)
Appends the contents of another byte_array (other) to the end of this one.
bytes_t const & bytes() const
std::string get_string() const
Given a byte_array, compute a vector containing the values of its entries and convert it to a string.
bb::OriginTag get_origin_tag() const
static field_t from_witness_index(Builder *ctx, uint32_t witness_index)
Definition field.cpp:61
void create_range_constraint(size_t num_bits, std::string const &msg="field_t::range_constraint") const
Let x = *this.normalize(), constrain x.v < 2^{num_bits}.
Definition field.cpp:910
void unset_free_witness_tag() const
Unset the free witness flag for the field element's tag.
Definition field.hpp:343
static constexpr uint256_t modulus
Definition field.hpp:212
void set_origin_tag(const OriginTag &new_tag) const
Definition field.hpp:332
AluTraceBuilder builder
Definition alu.test.cpp:123
FF a
FF b
ECCVMCircuitBuilder Builder
bn254::witness_ct witness_ct
testing::Types< bb::UltraCircuitBuilder, bb::MegaCircuitBuilder > CircuitTypes
RNG & get_debug_randomness(bool reset, std::uint_fast64_t seed)
Definition engine.cpp:190
Entry point for Barretenberg command-line interface.
TYPED_TEST_SUITE(ShpleminiTest, TestSettings)
field< Bn254FrParams > fr
Definition fr.hpp:174
C slice(C const &container, size_t start)
Definition container.hpp:9
TYPED_TEST(ShpleminiTest, CorrectnessOfMultivariateClaimBatching)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
This file contains part of the logic for the Origin Tag mechanism that tracks the use of in-circuit p...
#define STANDARD_TESTING_TAGS
#define STDLIB_TYPE_ALIASES
void ignore_unused(T &)
static constexpr uint256_t modulus
static field random_element(numeric::RNG *engine=nullptr) noexcept