Skip to content

feat: add div-mod constraints #646

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

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

Conversation

stuarttimwhite
Copy link
Contributor

Please be sure to look over the pull request guidelines here: https://github.com/spaceandtimelabs/sxt-proof-of-sql/blob/main/CONTRIBUTING.md#submit-pr.

Please go through the following checklist

Rationale for this change

The constraints for div and mod expr need to be added. This will allow it to be a fully secure gadget.

What changes are included in this PR?

All the constraints for div-and-mod-expr.

Are these changes tested?

Yes. There is a tamperproof test for each constraint, demonstrating that each constraint is necessary.

@stuarttimwhite stuarttimwhite marked this pull request as ready for review March 18, 2025 17:38
Copy link

codecov bot commented Mar 18, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.14%. Comparing base (a8e21f9) to head (2ab2ab6).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #646      +/-   ##
==========================================
+ Coverage   96.08%   96.14%   +0.05%     
==========================================
  Files         331      331              
  Lines       58897    59607     +710     
==========================================
+ Hits        56593    57307     +714     
+ Misses       2304     2300       -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@JayWhite2357 JayWhite2357 left a comment

Choose a reason for hiding this comment

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

Can you make a PR with a LaTeX document with the constraints here:
https://github.com/spaceandtimelabs/sxt-proof-of-sql/tree/main/docs/protocols

We can then reference that in this PR.

)?;

// (r - b) * (r + b) * t' - b = 0
let t = builder.try_consume_final_round_mle_evaluation()?;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you put all of these together? That way the order is clear, and separated from the constraints.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should I do this on the prove side as well? Put the constraints after the commitments?

2,
)?;

// (r - b) * (r + b) * t' - b = 0
Copy link
Contributor

Choose a reason for hiding this comment

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

There should be some comments indicating

// r - remainder
// t' - t
// u - b_div_q
// etc.

Perhaps t should be t_prime.

let sqrt_min_plus_s = verifier_evaluate_sign(builder, min_sqrt_eval + s, one_eval, None)?;
let sqrt_min_less_s = verifier_evaluate_sign(builder, min_sqrt_eval - s, one_eval, None)?;

// MIN < q < -MIN
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't quite the constraint that is being enforced here.
It is actually $$-2^B \leq q &lt; 2^B$$ for some $B$.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Aren't we making the assumption that MIN = -2^B for some B for all our supported data types?

Comment on lines +479 to +505
// sign(sqrt(-min) + s) = 1
// sign(sqrt(-min) - s) = 1
Copy link
Contributor

@JayWhite2357 JayWhite2357 Mar 20, 2025

Choose a reason for hiding this comment

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

Could we get away with $$-2^B \leq s &lt; 2^B$$ for some $B$?

Copy link
Contributor

Choose a reason for hiding this comment

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

We already need to show that $q\in[T_{min},-T_{min}]$.
Additionally, we know that $b\in[T_{min}, -T_{min}-1]$ since that is guaranteed by the input.
So, as long as $T_{min}^2\leq S_{max}$, we don't need this check.
This is true for all integer types (except u128, which I want to deprecate).
It is not true for all decimal types. (But is true for some of them.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What's the smallest order field we would ever use for our scalar type? Is i128 the biggest type we will use long term? Are decimals with high precision something that might be relevant here?

2,
)?;

// (q′ − q) * (q + MIN) = 0
Copy link
Contributor

@JayWhite2357 JayWhite2357 Mar 20, 2025

Choose a reason for hiding this comment

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

NIT: is not '. is not -.

2,
)?;

// (q' - MIN) * (q + MIN) * v - (q' - MIN) = 0
Copy link
Contributor

Choose a reason for hiding this comment

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

This does the same thing. The definition of v changes, but it's just a hint anyway.

Suggested change
// (q' - MIN) * (q + MIN) * v - (q' - MIN) = 0
// (q + MIN) * v - (q' - MIN) = 0

Copy link
Contributor

Choose a reason for hiding this comment

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

Slightly prefer

(q + MIN) * v + (q' - MIN) = 0

2,
)?;

// (r - b) * (r + b) * t' - b = 0
Copy link
Contributor

Choose a reason for hiding this comment

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

Slightly prefer

(r - b) * (r + b) * t' + b = 0

let sqrt_min_less_s = verifier_evaluate_sign(builder, min_sqrt_eval - s, one_eval, None)?;

// MIN < q < -MIN
// We need at least an extra bit to allow for -MIN
Copy link
Contributor

Choose a reason for hiding this comment

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

We could avoid this extra bit if we do $q'\in[MIN,MAX]$ instead.
This, paired with $(q - q') * (q + MIN) = 0$ guarentees that $q$ is correctly bounded.

@stuarttimwhite stuarttimwhite force-pushed the feat/add-div-mod-constraint branch from 3a6baac to c65f130 Compare March 21, 2025 14:51
@stuarttimwhite stuarttimwhite force-pushed the feat/add-div-mod-constraint branch from 4bebbc0 to 0354b02 Compare April 21, 2025 16:28
@stuarttimwhite stuarttimwhite force-pushed the feat/add-div-mod-constraint branch from 0354b02 to 2ab2ab6 Compare April 21, 2025 17:23
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.

2 participants