-
Notifications
You must be signed in to change notification settings - Fork 316
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: handle properly invalid witness assignment in ec add (#7690)
Apply the strategy added used for MSM in PR #7653 in regard to invalid witness assignment for grumpking points with constant or witness input, also for ec add.
- Loading branch information
Showing
4 changed files
with
67 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
barretenberg/cpp/src/barretenberg/dsl/acir_format/witness_constant.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#include "witness_constant.hpp" | ||
#include "barretenberg/ecc/curves/bn254/fr.hpp" | ||
|
||
namespace acir_format { | ||
|
||
using namespace bb; | ||
using namespace bb::stdlib; | ||
template <typename Builder, typename FF> | ||
bb::stdlib::cycle_group<Builder> to_grumpkin_point(const WitnessOrConstant<FF>& input_x, | ||
const WitnessOrConstant<FF>& input_y, | ||
const WitnessOrConstant<FF>& input_infinite, | ||
bool has_valid_witness_assignments, | ||
Builder& builder) | ||
{ | ||
using bool_ct = bb::stdlib::bool_t<Builder>; | ||
auto point_x = to_field_ct(input_x, builder); | ||
auto point_y = to_field_ct(input_y, builder); | ||
auto infinite = bool_ct(to_field_ct(input_infinite, builder)); | ||
|
||
// When we do not have the witness assignments, we set is_infinite value to true if it is not constant | ||
// else default values would give a point which is not on the curve and this will fail verification | ||
if (!has_valid_witness_assignments) { | ||
if (!input_infinite.is_constant) { | ||
builder.variables[input_infinite.index] = fr(1); | ||
} else if (input_infinite.value == fr::zero() && !(input_x.is_constant || input_y.is_constant)) { | ||
// else, if is_infinite is false, but the coordinates (x, y) are witness (and not constant) | ||
// then we set their value to an arbitrary valid curve point (in our case G1). | ||
auto g1 = bb::grumpkin::g1::affine_one; | ||
builder.variables[input_x.index] = g1.x; | ||
builder.variables[input_y.index] = g1.y; | ||
} | ||
} | ||
cycle_group<Builder> input_point(point_x, point_y, infinite); | ||
return input_point; | ||
} | ||
|
||
template bb::stdlib::cycle_group<UltraCircuitBuilder> to_grumpkin_point(const WitnessOrConstant<fr>& input_x, | ||
const WitnessOrConstant<fr>& input_y, | ||
const WitnessOrConstant<fr>& input_infinite, | ||
bool has_valid_witness_assignments, | ||
UltraCircuitBuilder& builder); | ||
template bb::stdlib::cycle_group<MegaCircuitBuilder> to_grumpkin_point(const WitnessOrConstant<fr>& input_x, | ||
const WitnessOrConstant<fr>& input_y, | ||
const WitnessOrConstant<fr>& input_infinite, | ||
bool has_valid_witness_assignments, | ||
MegaCircuitBuilder& builder); | ||
|
||
} // namespace acir_format |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters