fix: Patches to cycle_group and cycle_group fuzzer#12385
Conversation
Rumata888
left a comment
There was a problem hiding this comment.
Please look at the comments
| @@ -6,13 +6,17 @@ | |||
| #pragma clang diagnostic push | |||
| // TODO(luke/kesha): Add a comment explaining why we need this ignore and what the solution is. | |||
| // TODO(alex): resolve this todo in current pr | |||
| #define HAVOC_TESTING | ||
|
|
||
| #include "barretenberg/common/fuzzer.hpp" | ||
| // TODO: figure out how to detect w + w = c |
There was a problem hiding this comment.
Could you elaborate so someone else might understand?
There was a problem hiding this comment.
I think of just deleting this comment for now, since I'll add this check in the following pr
| // Most of the time it is true, so we won't need to do extra conditional_assign | ||
| // during `get_standard_form` or `assert_equal` call | ||
| // However sometimes it won't be the case, so we can handle these cases using this flag | ||
| bool _is_standard; |
There was a problem hiding this comment.
Could you write what "standard" means?
| } | ||
| this->_is_standard = true; | ||
|
|
||
| // TODO(alex): there can be a possible bug. Again due to montgomery arithmetic. |
There was a problem hiding this comment.
If you're talking about the infinity representation in native affine elements, I don't think it should affect anything here
| // This ensures that at least one of the switches was performed | ||
| this->_is_constant = this->x.is_constant() && this->y.is_constant(); | ||
| if (this->_is_constant) { | ||
| this->_is_infinity = this->_is_infinity.get_value(); |
There was a problem hiding this comment.
Could you explain to me what this does?
There was a problem hiding this comment.
After describing this, I realized that it was not necessary, after all the stuff that set_point_at_infinity does.
I can bet that I saw a case when we got a non-standard point after some operations. But it seems like not the case anymore. I will delete most of this method for now.
| return equal_and_not_infinity || both_infinity; | ||
| this->standardize(); | ||
| other.standardize(); | ||
| const auto equal = (x == other.x) && (y == other.y); |
There was a problem hiding this comment.
I'm not sure if we should add the Point at infinity check, because right now if you compare a broken 0,0 point that is not set as point at infinity to a point at infinity, you'll get true
There was a problem hiding this comment.
I guess we can throw extra (lhs._is_infinity == rhs._is_infinity) into this bool. Same goes to assert_equal
| if (is_constant() || !witness_inverted) { | ||
| return *this; | ||
| } | ||
| // TODO(alex): shouldn't normalize return this->witness_value^witness_inverted in const case? |
There was a problem hiding this comment.
You should probably assert that it is not inverted (since what would be the point of inverting it separately, when you can just change the value)
| bool same = (lhs.witness_index == rhs.witness_index) && (lhs.witness_inverted == rhs.witness_inverted); | ||
| bool witness_same = same && lhs.witness_index != IS_CONSTANT; | ||
| bool const_same = same && (lhs.witness_index == IS_CONSTANT) && (lhs.witness_bool == rhs.witness_bool); | ||
| // TODO(alex): reference to the above todo just to not forget to change the lhs.witness_inverted == |
There was a problem hiding this comment.
The previous comment about constants possibly having witness_inverted true. Fixed that
| allow_chain_2.must_imply(output_note_2.owner == self, "inter-user chaining disallowed"); | ||
|
|
||
| group_ct output_note_1_owner = output_note_1.owner; | ||
| group_ct output_note_2_owner = output_note_2.owner; |
There was a problem hiding this comment.
standardize method changes the class state, so we can't mark assert_equal and == to const anymore. Hence we can't call them on consts either
Rumata888
left a comment
There was a problem hiding this comment.
Because after that, the coordinates are not normalized anywhere. Hence after calling
create_ecc_dbl_gate,create_ecc_add_gatewith this point as an argument, the witness will be wrong
I think you should add that comment then, otherwise someone reading this might remove it
Rumata888
left a comment
There was a problem hiding this comment.
PLease add the comment explaining why you're calling normalize after negation and then merge
* master: fix: filter for empty attestations when pulling from block (#12740) feat: one-way noir sync (#12592) feat(avm): Address derivation gadget (#12721) chore(ci): add workflow dispatch to masternet (#12739) feat: add default accounts (#12734) feat: gas reports and snapshots (#12724) fix(avm): fix vm1 fake proof size (#12733) feat(bb): extend_edges optimization for zero values past end_index (#12703) fix: remove hard coding of constructor for account manager (#12678) git subrepo push --branch=master noir-projects/aztec-nr git_subrepo.sh: Fix parent in .gitrepo file. [skip ci] chore: replace relative paths to noir-protocol-circuits git subrepo push --branch=master barretenberg fix: verify_honk_proof inputs generation in bootstrap (#12457) fix: Patches to cycle_group and cycle_group fuzzer (#12385)
This pr adds some features and fixes some bugs
Cycle Group
features:
bool _is_standardthat detects whether the point is in it's standard form. i.e.this constant tracks the of the state of the point. So we won't create unnecessary gates repeatedly.
The reason we need it to be (0, 0) is because the ordinary representation in
AffineElementis not compatible with our arithmetic design choices.added the necessary
_is_standardthroughout the whole fileredesigned the
get_standard_formmethod accordinglyadded the method
standardizeadded some comments to the use cases of
unconditionaloperationscycle_group::conditional_assignnow keeps track of the resulting standard'nessredesigned the
cycle_group::set_point_at_infinityto match the standard form. Also setting the resulting value to be witness in some cases.Bugs:
cycle_group::from_witnessnow doesn't throw an error during the point at infinity initializationcycle_group::from_constant_witnessnow doesn't throw an error during the point at infinity initializationcycle_group::dblnow doesn't throw an error when we pass a point with_is_infinitybeingconstandtruecycle_group::checked_unconditional_add/subtractnow doesn't crash on circuit_builder level when we pass two constant points with colliding x coordinatescycle_group::operator+\-now handles the cases when we pass allegedly witness point but with constant_is_infinitypartcycle_group::operator+\-. Previously when we added any two points the result point was marked as constant. Not the case anymore.cycle_group::operator-(). Previously the result value was not normalized. Which resulted in wrong witness.cycle_group::operator==. Now both values should be standardized first.cycle_group::assert_equalsame as ==cycle_group::conditional_assignnow results into both coordinates being witness or constant at the same time.Also added the regression test on each bug that I've fixed
bool_t
conditional_assignbehave like thefield_t::conditoinal_assign. Which doesn't create a gate when we choose between two equal witnessesUltraCircuitBuilder
assert_valid_variablesinside thecreate_ecc_dbl_gateCycleGroupFuzzer
fuzzer.hppadded the
BATCH_MULandCOND_ASSIGNopcodescycle_group.fuzzer.hpp
Added
SHOW_PRETTY_INFORMATIONdefine. It just spits out a code that I can then debug separately. Really helped to shorten the amount of time spent per crashAdded
DISABLE_MULTIPLICATIONdefine. For now there're still too much bugs related to the ordinary logic.Added
witnesspredicate possibility inconstruct_predicate.Renamed
ExecutionHandler::operator+-tooperator_addandoperator_subrespectively. Needed to pass builder as one of the variables due to point_at_infinity possibilityAdded
smth_infflag during addition/subtraction, becauseunconditionaloperations can't work with points at infinityAdded
standardizedcheck duringpostProcessto check whether I handled all the cases of initialization correctly