Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ensure dummy values are on the curve for MSM #7653

Merged
merged 10 commits into from
Jul 30, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ void build_constraints(Builder& builder,
// Add multi scalar mul constraints
for (size_t i = 0; i < constraint_system.multi_scalar_mul_constraints.size(); ++i) {
const auto& constraint = constraint_system.multi_scalar_mul_constraints.at(i);
create_multi_scalar_mul_constraint(builder, constraint);
create_multi_scalar_mul_constraint(builder, constraint, has_valid_witness_assignments);
track_gate_diff(constraint_system.gates_per_opcode,
constraint_system.original_opcode_indices.multi_scalar_mul_constraints.at(i));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ namespace acir_format {

using namespace bb;

template <typename Builder> void create_multi_scalar_mul_constraint(Builder& builder, const MultiScalarMul& input)
template <typename Builder>
void create_multi_scalar_mul_constraint(Builder& builder,
const MultiScalarMul& input,
bool has_valid_witness_assignments)
{
using cycle_group_ct = stdlib::cycle_group<Builder>;
using cycle_scalar_ct = typename stdlib::cycle_group<Builder>::cycle_scalar;
Expand All @@ -25,21 +28,27 @@ template <typename Builder> void create_multi_scalar_mul_constraint(Builder& bui
field_ct point_x;
field_ct point_y;
bool_ct infinite;
if (input.points[i].is_constant) {
point_x = field_ct(input.points[i].value);
} else {
point_x = field_ct::from_witness_index(&builder, input.points[i].index);
}
if (input.points[i + 1].is_constant) {
point_y = field_ct(input.points[i + 1].value);
} else {
point_y = field_ct::from_witness_index(&builder, input.points[i + 1].index);
}
if (input.points[i + 2].is_constant) {
infinite = bool_ct(field_ct(input.points[i + 2].value));

if (!has_valid_witness_assignments) {
infinite = bool_ct(true);
guipublic marked this conversation as resolved.
Show resolved Hide resolved
} else {
infinite = bool_ct(field_ct::from_witness_index(&builder, input.points[i + 2].index));
if (input.points[i].is_constant) {
point_x = field_ct(input.points[i].value);
} else {
point_x = field_ct::from_witness_index(&builder, input.points[i].index);
}
if (input.points[i + 1].is_constant) {
point_y = field_ct(input.points[i + 1].value);
} else {
point_y = field_ct::from_witness_index(&builder, input.points[i + 1].index);
}
if (input.points[i + 2].is_constant) {
guipublic marked this conversation as resolved.
Show resolved Hide resolved
infinite = bool_ct(field_ct(input.points[i + 2].value));
} else {
infinite = bool_ct(field_ct::from_witness_index(&builder, input.points[i + 2].index));
}
}

cycle_group_ct input_point(point_x, point_y, infinite);
// Reconstruct the scalar from the low and high limbs
field_ct scalar_low_as_field;
Expand Down Expand Up @@ -81,8 +90,10 @@ template <typename Builder> void create_multi_scalar_mul_constraint(Builder& bui
}

template void create_multi_scalar_mul_constraint<UltraCircuitBuilder>(UltraCircuitBuilder& builder,
const MultiScalarMul& input);
const MultiScalarMul& input,
bool has_valid_witness_assignments);
template void create_multi_scalar_mul_constraint<MegaCircuitBuilder>(MegaCircuitBuilder& builder,
const MultiScalarMul& input);
const MultiScalarMul& input,
bool has_valid_witness_assignments);

} // namespace acir_format
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ struct MultiScalarMul {
friend bool operator==(MultiScalarMul const& lhs, MultiScalarMul const& rhs) = default;
};

template <typename Builder> void create_multi_scalar_mul_constraint(Builder& builder, const MultiScalarMul& input);
template <typename Builder>
void create_multi_scalar_mul_constraint(Builder& builder,
const MultiScalarMul& input,
bool has_valid_witness_assignments);

} // namespace acir_format
Loading