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

Avoid deeply nested LinearCombinations in EvaluationsVar::interpolate_and_evaluate #145

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

winderica
Copy link
Contributor

@winderica winderica commented Apr 7, 2024

Description

It is observed in privacy-scaling-explorations/sonobe#80 that stack overflow occurs when calling EvaluationsVar::interpolate_and_evaluate for large evaluation domains (e.g., when $n > 11$).

I think this happens because in EvaluationsVar::lagrange_interpolate_with_constant_offset and EvaluationsVar::lagrange_interpolate_with_non_constant_offset, we are updating the final evaluation result in a for loop, and += in each iteration wraps the current result by a new layer of LinearCombination. This produces a deeply nested LinearCombination. When we get .value() of the evaluation result, internally ConstraintSystem::assigned_value is invoked to recursively flatten the LC. Unfortunately, the number of LC layers of the evaluation result is so large that the recursion depth exceeds the OS limit, resulting in a stack overflow.

This PR fixes the above bug by calling .sum() on the iterator of addends, since this method invokes ‎AllocatedFp::add_many, which produces a flat LC.


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against correct branch (master)
  • Linked to Github issue with discussion and accepted design OR have an explanation in the PR that describes this work.
  • Wrote unit tests
  • Updated relevant documentation in the code (N/A)
  • Added a relevant changelog entry to the Pending section in CHANGELOG.md
  • Re-reviewed Files changed in the Github PR explorer

@winderica winderica requested a review from a team as a code owner April 7, 2024 21:14
@winderica winderica requested review from z-tech, mmagician and weikengchen and removed request for a team April 7, 2024 21:14
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.

None yet

2 participants