Skip to content

fix(uints): constrain valueOf #1139

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

Merged
merged 7 commits into from
Jun 12, 2024
Merged

Conversation

bernard-wagner
Copy link
Contributor

Description

As stated in the TODO, uints8.ValueOf is not constrained. This commit constrains the output of ValueOf.

I am jumping in on the deep end with circuit development, so would appreciate as much feedback as possible. Especially would appreciate guidance on testing constraints for intermediate values, the overflow was the only technique I could think of that works in a unit test.

Type of change

  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

How has this been tested?

Added a unit test that if added to the current master branch will fail. The third test case should return an error as the input exceeds the output size.

Checklist:

  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • I did not modify files generated from templates
  • golangci-lint does not output errors locally
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@bernard-wagner bernard-wagner force-pushed the uints-value-of branch 2 times, most recently from 27e2072 to 6b7bffc Compare May 22, 2024 12:52
@ivokub
Copy link
Collaborator

ivokub commented May 22, 2024

Thanks for the PR. I'm trying to have a look at it this week to give feedback.

As of why we yet haven't added the constraining of the values always, is that in the context of some operations (XOR, AND), the uints.U8.Value are used as keys in looking up from the table and as such if the would not be in range, then the lookup would fail. So there is implicit constraining of the values to be 8-bit. But for example when we're doing some other operations which is not based on lookups, then it could lead to underconstrained circuits indeed.

I haven't looked at your implementation yet, but my general idea for building it better was to have an additional value or DB which says if U8 value is used in lookup table operations and is implicitly constrained.

@ivokub ivokub added bug Something isn't working consolidate strengthen an existing feature P1: High Issue priority: high labels Jun 12, 2024
Copy link
Collaborator

@ivokub ivokub left a comment

Choose a reason for hiding this comment

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

Alright - I finally got to reviewing it. Your initial PR was spot on, but it revealed another issue in Add method where we didn't check that the carry we omitted was correct. And fixing that made me realize that I could clean up some parts.

I pushed the changes directly to your branch, I hope you wont mind. Maybe you can have a look before I merge?

Otherwise, thanks for the contribution! Great work!

@ivokub ivokub merged commit 6abed5a into Consensys:master Jun 12, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working consolidate strengthen an existing feature P1: High Issue priority: high
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants