Skip to content

Commit 373d115

Browse files
committed
smarter checking used_witnesses
1 parent 6ee56c1 commit 373d115

File tree

2 files changed

+24
-23
lines changed

2 files changed

+24
-23
lines changed

barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup_impl.hpp

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -122,26 +122,24 @@ element<C, Fq, Fr, G> element<C, Fq, Fr, G>::operator+(const element& other) con
122122
// yes = infinity_predicate && !lhs_infinity && !rhs_infinity
123123
// yes = lhs_infinity && rhs_infinity
124124
// n.b. can likely optimize this
125-
info("PRINT in BIGGROUP OLOLLLO");
126-
info(lhs_infinity.witness_index);
127-
info(rhs_infinity.witness_index);
128125
bool_ct result_is_infinity = infinity_predicate && (!lhs_infinity && !rhs_infinity);
129-
/* if constexpr (IsUltraBuilder<C>) {
130-
result_is_infinity.get_context()->update_used_witnesses(result_is_infinity.witness_index);
131-
} */
132-
info(result_is_infinity.witness_index);
133126
result_is_infinity = result_is_infinity || (lhs_infinity && rhs_infinity);
134-
/* if constexpr (IsUltraBuilder<C>) {
135-
result_is_infinity.get_context()->update_used_witnesses(result_is_infinity.witness_index);
136-
} */
137-
info(result_is_infinity.witness_index);
138127
result.set_point_at_infinity(result_is_infinity);
139-
info(result_is_infinity.get_value());
140-
141128
result.set_origin_tag(OriginTag(get_origin_tag(), other.get_origin_tag()));
129+
if ((lhs_infinity.is_constant() && !rhs_infinity.is_constant())) {
130+
// in this case (lhs_infninity && rhs_infninity) has witness_index == IS_CONSTANT, so
131+
// in the last operation result_is_infinity's witness_index won't be changed and it will be in one gate
132+
result_is_infinity.get_context()->update_used_witnesses(result_is_infinity.witness_index);
133+
}
134+
if (!lhs_infinity.is_constant() && !rhs_infinity.is_constant()) {
135+
// if both variables lhs_infinity && rhs_infinity are not constant, first result_is_infinity will be in 2
136+
// gates and second one will be in 1 gate
137+
if constexpr (IsUltraBuilder<C>) {
138+
result_is_infinity.get_context()->update_used_witnesses(result_is_infinity.witness_index);
139+
}
140+
}
142141
return result;
143142
}
144-
145143
/**
146144
* @brief Enforce x and y coordinates of a point to be (0,0) in the case of point at infinity
147145
*
@@ -207,15 +205,21 @@ element<C, Fq, Fr, G> element<C, Fq, Fr, G>::operator-(const element& other) con
207205
// yes = lhs_infinity && rhs_infinity
208206
// n.b. can likely optimize this
209207
bool_ct result_is_infinity = infinity_predicate && (!lhs_infinity && !rhs_infinity);
210-
if constexpr (IsUltraBuilder<C>) {
211-
result_is_infinity.get_context()->update_used_witnesses(result_is_infinity.witness_index);
212-
}
213208
result_is_infinity = result_is_infinity || (lhs_infinity && rhs_infinity);
214-
if constexpr (IsUltraBuilder<C>) {
215-
result_is_infinity.get_context()->update_used_witnesses(result_is_infinity.witness_index);
216-
}
217209
result.set_point_at_infinity(result_is_infinity);
218210
result.set_origin_tag(OriginTag(get_origin_tag(), other.get_origin_tag()));
211+
if ((lhs_infinity.is_constant() && !rhs_infinity.is_constant())) {
212+
// in this case (lhs_infninity && rhs_infninity) has witness_index == IS_CONSTANT, so
213+
// in the last operation result_is_infinity's witness_index won't be changed and it will be in one gate
214+
result_is_infinity.get_context()->update_used_witnesses(result_is_infinity.witness_index);
215+
}
216+
if (!lhs_infinity.is_constant() && !rhs_infinity.is_constant()) {
217+
// if both variables lhs_infinity && rhs_infinity are not constant, first result_is_infinity will be in 2
218+
// gates and second one will be in 1 gate
219+
if constexpr (IsUltraBuilder<C>) {
220+
result_is_infinity.get_context()->update_used_witnesses(result_is_infinity.witness_index);
221+
}
222+
}
219223
return result;
220224
}
221225

barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/circuit_builder_base_impl.hpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,6 @@ template <typename FF_> uint32_t CircuitBuilderBase<FF_>::add_variable(const FF&
8484
{
8585
variables.emplace_back(in);
8686
const uint32_t index = static_cast<uint32_t>(variables.size()) - 1U;
87-
if (index == 19470) {
88-
info("OLOLOLOLOL");
89-
}
9087
real_variable_index.emplace_back(index);
9188
next_var_index.emplace_back(REAL_VARIABLE);
9289
prev_var_index.emplace_back(FIRST_VARIABLE_IN_CLASS);

0 commit comments

Comments
 (0)