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: constrain ops only in constrained context #102

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

olehmisar
Copy link
Contributor

Description

Problem*

Resolves #91

Summary*

Constrain ops via evaluate_quadratic_expression only in constrained context.

Additional Context

@TomAFrench shouldvalidate_gt::<_, MOD_BITS>(divisor, remainder); from fn udiv_mod also be inside if !std::runtime::is_unconstrained()?

PR Checklist*

  • I have tested the changes locally.
  • I have formatted the changes with Prettier and/or cargo fmt on default settings.

@olehmisar
Copy link
Contributor Author

I believe this will optimize execution inside AVM, right?

@TomAFrench
Copy link
Member

shouldvalidate_gt::<_, MOD_BITS>(divisor, remainder); from fn udiv_mod also be inside if !std::runtime::is_unconstrained()?

Yep, anything that checks the result is correct is unnecessary in the unconstrained context.

@olehmisar
Copy link
Contributor Author

olehmisar commented Jan 20, 2025

@TomAFrench review please. Review very carefully as IDK what i am doing

@TomAFrench
Copy link
Member

We can do the same stuff in add and sub as well.

if std::runtime::is_unconstrained() {
  _sub(lhs, rhs)
} else {
  //existing code
}


@olehmisar olehmisar marked this pull request as draft January 20, 2025 23:19
@olehmisar olehmisar force-pushed the om/check-unconstrained-context branch from a793732 to abe33a0 Compare January 21, 2025 02:51
@olehmisar olehmisar force-pushed the om/check-unconstrained-context branch from abe33a0 to 707fe98 Compare January 21, 2025 02:52
@olehmisar olehmisar marked this pull request as ready for review January 21, 2025 02:53
@olehmisar
Copy link
Contributor Author

@TomAFrench i added is_unconstrained checks in from_field, neg, add and sub. I believe tests for neg, add and sub in unconstrained context are required due to how they are implemented

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🏗 In progress
Development

Successfully merging this pull request may close these issues.

Calls to constrained functions in an unconstrained context are needlessly inefficient
2 participants