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 rot gadget to o1js #1182

Merged
merged 84 commits into from
Oct 26, 2023
Merged

Add rot gadget to o1js #1182

merged 84 commits into from
Oct 26, 2023

Conversation

MartinMinkov
Copy link
Contributor

@MartinMinkov MartinMinkov commented Oct 12, 2023

Summary

This PR adds the implementation for a ROT gate to the existing Gadgets namespace. For context of what a bitwise rotation is, a rotation (often referred to as a "bitwise rotation") is an operation that shifts the bits of a binary number either to the left or to the right, but unlike a standard shift operation, the bits that "fall off" the end are not discarded. Instead, they "wrap around" to the other end.

The implementation is based on the original OCaml implementation which is specified here

In our ROT implementation, we handle the constant case by using the added functionality in the bindings, and for the prover case, we specify the implementation in this PR.

Note: The rotate function that is specified for the ROT gate will also be used for the upcoming shift gates.

Tested

This PR adds e2e tests, unit tests, and verification key tests for the ROT gate.

🔗 bindings: o1-labs/o1js-bindings#184

@MartinMinkov MartinMinkov changed the base branch from main to feature/range-check-64-develop October 12, 2023 21:55
@MartinMinkov MartinMinkov changed the title WIP: add rot function to o1js WIP: add rot gadget to o1js Oct 12, 2023
@MartinMinkov MartinMinkov linked an issue Oct 12, 2023 that may be closed by this pull request
This commit introduces a new function 'rot' in rot.ts file which performs bitwise rotation on a given word. It supports both left and right rotation modes. The function also includes a check for the number of bits to be rotated, ensuring it is within the range of 0 to 64. The rotation function is designed to work with both constant and provable words.
Base automatically changed from feature/range-check-64-develop to main October 16, 2023 18:43
…method to improve usability

This change allows users to call the rot method without specifying the bits parameter, which will default to 64 for Field class, UInt64.NUM_BITS for UInt64 class, and UInt32.NUM_BITS for UInt32 class.
- Update the example output to match the correct result of the operation
- Change the direction parameter description from boolean to 'left' or 'right' string values for better readability and understanding of the function usage
@MartinMinkov MartinMinkov requested a review from a team as a code owner October 25, 2023 20:38
@mitschabaude
Copy link
Member

Re-reviewed, only thing left from my side is #1182 (comment)

@querolita
Copy link
Member

All good on my side

…ove performance

The checkMaxBits function was previously used to ensure that the input is at most 64 bits. However, this check is no longer necessary as the input size is now guaranteed by the type system.
- Change single line comment to JSDoc style for better IDE support
- Add parameter descriptions for better understanding
- Improve wording and formatting for better readability
- Add @throws tag to highlight error conditions
- Update example code to match new parameter descriptions
@MartinMinkov MartinMinkov merged commit 42a18c8 into main Oct 26, 2023
13 checks passed
@MartinMinkov MartinMinkov deleted the feat/ROT-gadget branch October 26, 2023 17:29
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.

Port ROT64 gadget to TypeScript
4 participants