diff --git a/circuits/cpp/barretenberg/cpp/scripts/run_tests b/circuits/cpp/barretenberg/cpp/scripts/run_tests index 6dee213173ab..409379f4e015 100755 --- a/circuits/cpp/barretenberg/cpp/scripts/run_tests +++ b/circuits/cpp/barretenberg/cpp/scripts/run_tests @@ -25,5 +25,5 @@ docker run --rm -t $IMAGE_URI /bin/sh -c "\ cd /usr/src/barretenberg/cpp/srs_db; \ ./download_ignition.sh $NUM_TRANSCRIPTS; \ cd /usr/src/barretenberg/cpp/build; \ -./bin/grumpkin_srs_gen 1048576; \ + ./bin/grumpkin_srs_gen 1048576; \ for BIN in $TESTS; do ./bin/\$BIN $@; done" diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/srs/factories/crs_factory.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/srs/factories/crs_factory.hpp index 8c5f659bdfb1..f9d989d30493 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/srs/factories/crs_factory.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/srs/factories/crs_factory.hpp @@ -21,7 +21,7 @@ template class ProverCrs { ; /** - * Returns the monomial points in a form to be consumed by scalar_multiplication pippenger algorithm. + * @brief Returns the monomial points in a form to be consumed by scalar_multiplication pippenger algorithm. */ virtual typename Curve::AffineElement* get_monomial_points() = 0; virtual size_t get_monomial_size() const = 0; @@ -36,7 +36,15 @@ template <> class VerifierCrs { public: virtual Curve::G2AffineElement get_g2x() const = 0; + /** + * @brief As the G_2 element of the CRS is fixed, we can precompute the operations performed on it during the + * pairing algorithm to optimise pairing computations. + */ virtual barretenberg::pairing::miller_lines const* get_precomputed_g2_lines() const = 0; + /** + * @brief Returns the first G_1 element from the CRS, used by the Shplonk verifier to compute the final + * commtiment. + */ virtual Curve::AffineElement get_first_g1() const = 0; }; @@ -44,8 +52,16 @@ template <> class VerifierCrs { using Curve = curve::Grumpkin; public: + /** + * @brief Returns the G_1 elements in the CRS after the pippenger point table has been applied on them + * + */ virtual Curve::AffineElement* get_monomial_points() const = 0; virtual size_t get_monomial_size() const = 0; + /** + * @brief Returns the first G_1 element from the CRS, used by the Shplonk verifier to compute the final + * commtiment. + */ virtual Curve::AffineElement get_first_g1() const = 0; }; diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/srs/global_crs.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/srs/global_crs.cpp index 232702dfa96c..acd615b8b8a2 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/srs/global_crs.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/srs/global_crs.cpp @@ -31,7 +31,7 @@ void init_grumpkin_crs_factory(std::string crs_path) std::shared_ptr> get_crs_factory() { if (!crs_factory) { - throw_or_abort("You need vto initalize the global CRS with a call to init_crs_factory(...)!"); + throw_or_abort("You need to initalize the global CRS with a call to init_crs_factory(...)!"); } return crs_factory; } @@ -39,7 +39,7 @@ std::shared_ptr> get_crs_factory() std::shared_ptr> get_grumpkin_crs_factory() { if (!grumpkin_crs_factory) { - throw_or_abort("You need vto initalize the global CRS with a call to init_grumpkin_crs_factory(...)!"); + throw_or_abort("You need to initalize the global CRS with a call to init_grumpkin_crs_factory(...)!"); } return grumpkin_crs_factory; } diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/stdlib/primitives/uint/plookup/arithmetic.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/stdlib/primitives/uint/plookup/arithmetic.cpp index 59c147a58a5c..ab461f3c14d2 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/stdlib/primitives/uint/plookup/arithmetic.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/stdlib/primitives/uint/plookup/arithmetic.cpp @@ -10,6 +10,7 @@ namespace stdlib { template uint_plookup uint_plookup::operator+(const uint_plookup& other) const { + ASSERT(context == other.context || (context != nullptr && other.context == nullptr) || (context == nullptr && other.context != nullptr)); Composer* ctx = (context == nullptr) ? other.context : context; @@ -26,15 +27,15 @@ uint_plookup uint_plookup::operator+(const u const uint256_t overflow = sum >> width; const uint256_t remainder = sum & MASK; - const add_quad_ gate{ + const add_quad_ gate{ is_constant() ? ctx->zero_idx : witness_index, other.is_constant() ? ctx->zero_idx : other.witness_index, ctx->add_variable(remainder), ctx->add_variable(overflow), - fr::one(), - fr::one(), - fr::neg_one(), - -fr(CIRCUIT_UINT_MAX_PLUS_ONE), + FF::one(), + FF::one(), + FF::neg_one(), + -FF(CIRCUIT_UINT_MAX_PLUS_ONE), constants, }; @@ -50,6 +51,7 @@ uint_plookup uint_plookup::operator+(const u template uint_plookup uint_plookup::operator-(const uint_plookup& other) const { + ASSERT(context == other.context || (context != nullptr && other.context == nullptr) || (context == nullptr && other.context != nullptr)); @@ -71,15 +73,15 @@ uint_plookup uint_plookup::operator-(const u const uint256_t overflow = difference >> width; const uint256_t remainder = difference & MASK; - const add_quad_ gate{ + const add_quad_ gate{ lhs_idx, rhs_idx, ctx->add_variable(remainder), ctx->add_variable(overflow), - fr::one(), - fr::neg_one(), - fr::neg_one(), - -fr(CIRCUIT_UINT_MAX_PLUS_ONE), + FF::one(), + FF::neg_one(), + FF::neg_one(), + -FF(CIRCUIT_UINT_MAX_PLUS_ONE), CIRCUIT_UINT_MAX_PLUS_ONE + constant_term, }; @@ -95,6 +97,7 @@ uint_plookup uint_plookup::operator-(const u template uint_plookup uint_plookup::operator*(const uint_plookup& other) const { + Composer* ctx = (context == nullptr) ? other.context : context; if (is_constant() && other.is_constant()) { @@ -113,16 +116,16 @@ uint_plookup uint_plookup::operator*(const u const uint256_t overflow = product >> width; const uint256_t remainder = product & MASK; - const mul_quad_ gate{ + const mul_quad_ gate{ witness_index, rhs_idx, ctx->add_variable(remainder), ctx->add_variable(overflow), - fr::one(), + FF::one(), other.additive_constant, additive_constant, - fr::neg_one(), - -fr(CIRCUIT_UINT_MAX_PLUS_ONE), + FF::neg_one(), + -FF(CIRCUIT_UINT_MAX_PLUS_ONE), 0, }; @@ -180,12 +183,12 @@ std::pair, uint_plookup> uint_p // We want to force the divisor to be non-zero, as this is an error state if (other.is_constant() && other.get_value() == 0) { // TODO: should have an actual error handler! - const uint32_t one = ctx->add_variable(fr::one()); - ctx->assert_equal_constant(one, fr::zero()); + const uint32_t one = ctx->add_variable(FF::one()); + ctx->assert_equal_constant(one, FF::zero()); ctx->failure("plookup_arithmetic: divide by zero!"); } else if (!other.is_constant()) { const bool_t is_divisor_zero = field_t(other).is_zero(); - ctx->assert_equal_constant(is_divisor_zero.witness_index, fr::zero(), "plookup_arithmetic: divide by zero!"); + ctx->assert_equal_constant(is_divisor_zero.witness_index, FF::zero(), "plookup_arithmetic: divide by zero!"); } if (is_constant() && other.is_constant()) { @@ -210,17 +213,17 @@ std::pair, uint_plookup> uint_p const uint32_t quotient_idx = ctx->add_variable(q); const uint32_t remainder_idx = ctx->add_variable(r); - const mul_quad_ division_gate{ + const mul_quad_ division_gate{ quotient_idx, // q divisor_idx, // b dividend_idx, // a remainder_idx, // r - fr::one(), // q_m.w_1.w_2 = q.b + FF::one(), // q_m.w_1.w_2 = q.b other.additive_constant, // q_l.w_1 = q.b if b const - fr::zero(), // q_2.w_2 = 0 - fr::neg_one(), // q_3.w_3 = -a - fr::one(), // q_4.w_4 = r - -fr(additive_constant) // q_c = -a if a const + FF::zero(), // q_2.w_2 = 0 + FF::neg_one(), // q_3.w_3 = -a + FF::one(), // q_4.w_4 = r + -FF(additive_constant) // q_c = -a if a const }; ctx->create_big_mul_gate(division_gate); @@ -228,13 +231,13 @@ std::pair, uint_plookup> uint_p const uint256_t delta = divisor - r; const uint32_t delta_idx = ctx->add_variable(delta); - const add_triple_ delta_gate{ + const add_triple_ delta_gate{ divisor_idx, // b remainder_idx, // r delta_idx, // d - fr::one(), // q_l = 1 - fr::neg_one(), // q_r = -1 - fr::neg_one(), // q_o = -1 + FF::one(), // q_l = 1 + FF::neg_one(), // q_r = -1 + FF::neg_one(), // q_o = -1 other.additive_constant, // q_c = d if const }; ctx->create_add_gate(delta_gate); diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/stdlib/primitives/uint/plookup/uint.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/stdlib/primitives/uint/plookup/uint.hpp index 6b41f6c4ceee..1b7ed3d27752 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/stdlib/primitives/uint/plookup/uint.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/stdlib/primitives/uint/plookup/uint.hpp @@ -10,6 +10,7 @@ namespace stdlib { template class uint_plookup { public: + using FF = typename Composer::FF; static constexpr size_t width = sizeof(Native) * 8; uint_plookup(const witness_t& other);