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

Add boundary constraints to the constraint graph #126

Merged
merged 4 commits into from
Jan 31, 2023
Merged

Conversation

grjte
Copy link
Contributor

@grjte grjte commented Jan 26, 2023

This PR addresses part of #106, by moving boundary constraints into the AlgebraicGraph alongside the integrity constraints, and updating the codegen and tests accordingly.

It includes the following changes:

  • add the boundary statements to the graph
  • refactor to graph handling to simplify the combined handling of integrity + boundary constraints
  • update winter codegen to work with the new boundary constraints
  • update the tests to reflect the changes (primarily constraint re-ordering) and skip the tests which are failing due to the pending changes listed below

There are several things that yet to be completed, but I'd like to tackle these in a subsequent PR since this is already quite large:

  • restore functionality of public inputs, by adding them to the graph, then restore the related tests
  • restore boundary constraint validation in the IR, then restore the related tests
  • add support for boundary variables
  • verify that all cases are captured and add any additional validation/testing as required

enf a.first = stack_inputs[0]
enf a.first = 0
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed this to keep the public inputs usage in the public inputs test. Once we add variables for the boundary constraints, we can test them here as well

@grjte grjte force-pushed the grjte-refactor-graph branch from cd7e777 to 8828c54 Compare January 26, 2023 15:48
@tohrnii tohrnii mentioned this pull request Jan 26, 2023
14 tasks
@grjte grjte force-pushed the grjte-refactor-graph branch 2 times, most recently from d2f0406 to 49f2fd8 Compare January 26, 2023 19:36
@grjte grjte marked this pull request as ready for review January 26, 2023 19:42
@grjte grjte requested review from tohrnii, bobbinth, Fumuran and Al-Kindi-0 and removed request for tohrnii and bobbinth January 26, 2023 19:42
@grjte grjte force-pushed the grjte-refactor-graph branch 2 times, most recently from c915ba6 to cd08bd7 Compare January 27, 2023 13:11
Copy link
Collaborator

@Al-Kindi-0 Al-Kindi-0 left a comment

Choose a reason for hiding this comment

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

Looks great to me, thanks @grjte !
Just some minor nits from my side.

ir/src/constraints/mod.rs Outdated Show resolved Hide resolved
ir/src/constraints/mod.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@tohrnii tohrnii left a comment

Choose a reason for hiding this comment

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

Thank you @grjte, looks good to me. I left a few minor nits inline.

codegen/winterfell/src/air/boundary_constraints.rs Outdated Show resolved Hide resolved
codegen/winterfell/src/air/boundary_constraints.rs Outdated Show resolved Hide resolved
codegen/winterfell/src/air/mod.rs Outdated Show resolved Hide resolved
codegen/winterfell/src/air/mod.rs Show resolved Hide resolved
ir/src/constraints/graph.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@Fumuran Fumuran left a comment

Choose a reason for hiding this comment

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

Looks great to me, thank you @grjte!

@grjte grjte force-pushed the grjte-refactor-graph branch 3 times, most recently from d48dce5 to f2c43ea Compare January 30, 2023 15:38
@grjte grjte marked this pull request as draft January 30, 2023 15:47
@grjte grjte force-pushed the grjte-refactor-graph branch from f2c43ea to cb45670 Compare January 30, 2023 15:54
@grjte grjte marked this pull request as ready for review January 30, 2023 15:55
@grjte
Copy link
Contributor Author

grjte commented Jan 30, 2023

Thanks for your reviews @Al-Kindi-0 @Overcastan and @tohrnii! I made the suggested changes, except for one point of discussion raised by @tohrnii (which it would be great to get your thoughts on).

Since this is a very significant change, let's wait for the review from @bobbinth before we merge.

Copy link
Contributor

@bobbinth bobbinth left a comment

Choose a reason for hiding this comment

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

Looks great! Thank you! I reviewed everything except for tests.

I think the structure is much cleaner than before. My comments are mostly for the future except fro the split_boundary_constraint comment. But even that one is non-blocking.

Comment on lines 110 to 111
ElemType::Felt => format!("({lhs}).exp(Felt::new({r_idx}))"),
ElemType::E => format!("({lhs}).exp(E::PositiveInteger::from({r_idx}_u64))"),
Copy link
Contributor

Choose a reason for hiding this comment

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

We should remember that using exp could be quite expensive as it uses constant-time exponentiation. In the future, we might want o "unroll" this into a sequence of multiplications.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed. I was trying to minimize changes in this PR. I've opened #130 to track this.

Are you thinking this unrolling should be done in the IR or in the winterfell codegen? (It seems to make sense as a future optimization that could be done in the IR)

codegen/winterfell/src/air/mod.rs Outdated Show resolved Hide resolved
codegen/winterfell/src/air/boundary_constraints.rs Outdated Show resolved Hide resolved
Comment on lines +90 to +93
/// Variable roots for the variables used in integrity constraints. For each element in a
/// vector or a matrix, a new root is added with a key equal to the [VariableValue] of the
/// element.
variable_roots: VariableRoots,
Copy link
Contributor

Choose a reason for hiding this comment

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

As far as I can tell, this is a helper map which is used only during the construction of the graph and is not really needed after the graph is constructed. If so, it may be good to find a better way to handle it in the future so that once constructed Constraints does not need to retain any extra info.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this is true. I think there are still a few refactors that could be done, but I wanted to keep this PR as minimal as possible. Once the remaining issues related to this work are addressed this is worth revisiting (or possibly while addressing those)

ir/src/constraints/graph.rs Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants