Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
7d1176a
remove (unused) modulus from non_native_field_witnesses.
suyash67 Jun 8, 2025
a3c1001
simplify condition for l and r constant_to_fixed_wit.
suyash67 Jun 8, 2025
89b8811
remove redundant static casts (prob were there because we didn't have…
suyash67 Jun 8, 2025
6fdf16a
modify the input to queue_partial_non_native_field_multiplication as …
suyash67 Jun 9, 2025
f8415b7
fix bigfield use of queue_partial_non_native_field_multiplication
suyash67 Jun 9, 2025
d5b089d
rename non_native_field_witnesses to non_native_multiplication_witnes…
suyash67 Jun 9, 2025
d1909f9
define a fn to get witness indices of limbs, and use it in evaluate_n…
suyash67 Jun 9, 2025
697cb21
remove TODO: this one suggests auditing the `evaluate_linear_identity…
suyash67 Jun 9, 2025
ad1dc83
use is_constant.
suyash67 Jun 9, 2025
b9e816a
make sure all limbs is_constant is the same in is_constant fn.
suyash67 Jun 9, 2025
20808fd
remove todo issue#14662 on ap.
suyash67 Jun 9, 2025
d1fff0b
add todo in ultra circuit builder: decompose_into_default_range. pote…
suyash67 Jun 14, 2025
aaa7fa8
remove == todo, not necessary. resolves bb#999.
suyash67 Jun 12, 2025
60f8c98
simplification (no logic change) in assert_less_than.
suyash67 Jun 20, 2025
b1aeba0
resolves ap#14660, we don't allow some limbs to be const and some not…
suyash67 Jun 13, 2025
1a75786
remove todo from reduction check, not necessary to pursue. resolve ap…
suyash67 Jun 20, 2025
3a203e3
use efficient div to calculate constant to add, should not change cir…
suyash67 Jun 22, 2025
f507703
change the dummy gate TODO to a NOTE.
suyash67 Jun 22, 2025
86ff6db
get rid of old TODO.
suyash67 Jun 22, 2025
7c3a678
resolved TODO related to redundant multiplication ==> we cannot simpl…
suyash67 Jun 22, 2025
8c5b189
closed the issue re assert_equal when `other` is constant. changed it…
suyash67 Jun 22, 2025
9084982
change TODO in sqr to NOTE.
suyash67 Jun 22, 2025
d9668dd
TODO in pow: avoid squaring for last bit, low hanging fruit 1.
suyash67 Jun 22, 2025
58afe6f
add is_constant conditional for pow.
suyash67 Jun 22, 2025
0de6540
change TODO to NOTE in pow.
suyash67 Jun 22, 2025
3ea68cf
remove old plookup tests, no more req.
suyash67 Jun 23, 2025
dececd5
remove commented out lines in tests: cleanup.
suyash67 Jun 23, 2025
8678713
add div_with_constant test and remove old commented out one.
suyash67 Jun 23, 2025
e5d431b
add ASSERT on numerator size < 16.
suyash67 Jun 23, 2025
0a94476
Assert that inp is constant in lambda fn.
suyash67 Jun 23, 2025
283684b
kesha suggestion: avoid redundant is_constant() calls.
suyash67 Jun 24, 2025
4dda0ef
kesha suggestion: add const/witness test case.
suyash67 Jun 24, 2025
3a13040
kesha suggestion 3: assert that atleast one multiplicand is witness.
suyash67 Jun 24, 2025
c11a828
enable madd test, add mult_madd with constant test.
suyash67 Jun 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,7 @@ TEST(UltraCircuitBuilder, SortWidgetNeg)

TEST(UltraCircuitBuilder, ComposedRangeConstraint)
{
// even num bits - not divisible by 3
UltraCircuitBuilder builder = UltraCircuitBuilder();
auto c = fr::random_element();
auto d = uint256_t(c).slice(0, 133);
Expand All @@ -564,6 +565,14 @@ TEST(UltraCircuitBuilder, ComposedRangeConstraint)
builder.create_add_gate({ a_idx, builder.zero_idx, builder.zero_idx, 1, 0, 0, -fr(e) });
builder.decompose_into_default_range(a_idx, 134);

// odd num bits - divisible by 3

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added test case for decompose_into_default_range with odd num of bits.

auto c_1 = fr::random_element();
auto d_1 = uint256_t(c_1).slice(0, 126);
auto e_1 = fr(d_1);
auto a_idx_1 = builder.add_variable(fr(e_1));
builder.create_add_gate({ a_idx_1, builder.zero_idx, builder.zero_idx, 1, 0, 0, -fr(e_1) });
builder.decompose_into_default_range(a_idx_1, 127);

bool result = CircuitChecker::check(builder);
EXPECT_EQ(result, true);
}
Expand Down Expand Up @@ -612,8 +621,8 @@ TEST(UltraCircuitBuilder, NonNativeFieldMultiplication)
const auto q_indices = get_limb_witness_indices(split_into_limbs(uint256_t(q)));
const auto r_indices = get_limb_witness_indices(split_into_limbs(uint256_t(r)));

non_native_field_witnesses<fr> inputs{
a_indices, b_indices, q_indices, r_indices, modulus_limbs, fr(uint256_t(modulus)),
non_native_multiplication_witnesses<fr> inputs{

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renaming, and removed modulus as its not used.

a_indices, b_indices, q_indices, r_indices, modulus_limbs,
};
const auto [lo_1_idx, hi_1_idx] = builder.evaluate_non_native_field_multiplication(inputs);
builder.range_constrain_two_limbs(lo_1_idx, hi_1_idx, 70, 70);
Expand Down Expand Up @@ -670,8 +679,8 @@ TEST(UltraCircuitBuilder, NonNativeFieldMultiplicationSortCheck)
const auto q_indices = get_limb_witness_indices(split_into_limbs(uint256_t(q)));
const auto r_indices = get_limb_witness_indices(split_into_limbs(uint256_t(r)));

non_native_field_witnesses<fr> inputs{
a_indices, b_indices, q_indices, r_indices, modulus_limbs, fr(uint256_t(modulus)),
non_native_multiplication_witnesses<fr> inputs{
a_indices, b_indices, q_indices, r_indices, modulus_limbs,
};
const auto [lo_1_idx, hi_1_idx] = builder.evaluate_non_native_field_multiplication(inputs);
builder.range_constrain_two_limbs(lo_1_idx, hi_1_idx, 70, 70);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "../byte_array/byte_array.hpp"
#include "../circuit_builders/circuit_builders_fwd.hpp"
#include "../field/field.hpp"
#include "barretenberg/common/assert.hpp"
#include "barretenberg/ecc/curves/bn254/fq.hpp"
#include "barretenberg/ecc/curves/bn254/fr.hpp"
#include "barretenberg/numeric/uint256/uint256.hpp"
Expand Down Expand Up @@ -497,7 +498,7 @@ template <typename Builder, typename T> class bigfield {
* @return bigfield
*
* @details Costs the same as operator* as it just sets a = b.
* TODO(https://github.com/AztecProtocol/aztec-packages/issues/15089): can optimise this further.
* NOTE(https://github.com/AztecProtocol/aztec-packages/issues/15089): Can optimise this further to save a gate.
*/
bigfield sqr() const;

Expand All @@ -520,9 +521,10 @@ template <typename Builder, typename T> class bigfield {
*
* @details Uses the square-and-multiply algorithm to compute a^exponent mod p.
*
* @todo TODO(https://github.com/AztecProtocol/barretenberg/issues/1014) Improve the efficiency of this function.
* NOTE(https://github.com/AztecProtocol/barretenberg/issues/1014) Improve the efficiency of this function using
* sliding window method.
*/
bigfield pow(const size_t exponent) const;
bigfield pow(const uint32_t exponent) const;

/**
* @brief Compute a * b + ...to_add = c mod p
Expand Down Expand Up @@ -587,9 +589,19 @@ template <typename Builder, typename T> class bigfield {
*
* @return true if the bigfield is constant, false otherwise.
*
* TODO(https://github.com/AztecProtocol/aztec-packages/issues/14662): should we check if all limbs are constants?
* @details We use assertions to ensure that all limbs are consistent in their constant status.
*/
bool is_constant() const { return prime_basis_limb.witness_index == IS_CONSTANT; }
bool is_constant() const
{
bool is_limb_0_constant = binary_basis_limbs[0].element.is_constant();
bool is_limb_1_constant = binary_basis_limbs[1].element.is_constant();
bool is_limb_2_constant = binary_basis_limbs[2].element.is_constant();
bool is_limb_3_constant = binary_basis_limbs[3].element.is_constant();
bool is_prime_limb_constant = prime_basis_limb.is_constant();
ASSERT(is_limb_0_constant == is_limb_1_constant && is_limb_1_constant == is_limb_2_constant &&
is_limb_2_constant == is_limb_3_constant && is_limb_3_constant == is_prime_limb_constant);
return is_prime_limb_constant;
}

/**
* @brief Inverting function with the assumption that the bigfield element we are calling invert on is not zero.
Expand Down Expand Up @@ -890,6 +902,20 @@ template <typename Builder, typename T> class bigfield {
static_assert(PROHIBITED_LIMB_BITS < MAXIMUM_LIMB_SIZE_THAT_WOULDNT_OVERFLOW);

private:
/**
* @brief Get the witness indices of the (normalized) binary basis limbs
*
* @return Witness indices of the binary basis limbs
*/
std::array<uint32_t, NUM_LIMBS> get_binary_basis_limb_witness_indices() const
{
std::array<uint32_t, NUM_LIMBS> limb_witness_indices;
for (size_t i = 0; i < NUM_LIMBS; i++) {
limb_witness_indices[i] = binary_basis_limbs[i].element.get_normalized_witness_index();
}
return limb_witness_indices;
}

/**
* @brief Compute the quotient and remainder values for dividing (a * b + (to_add[0] + ... + to_add[-1])) with p
*
Expand Down
Loading
Loading