-
Notifications
You must be signed in to change notification settings - Fork 136
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
Implement NOT gadget #1198
Merged
Merged
Implement NOT gadget #1198
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…se NOT operation on a field
…ts module The `not` method in the Gadgets module performs a bitwise NOT operation on a given input. It takes two parameters: `a`, the value to apply NOT to, and `length`, the number of bits to be considered for the NOT operation. The method uses the XOR gate to build the NOT operation, applying it only up to the specified bit length. The method documentation includes an example usage and a note about ensuring that the input value fits into the specified bit length to avoid potential errors.
…ield The `not` function is added to perform bitwise negation on a field. This function takes two parameters: `a` which is the field to be negated, and `length` which is the number of bits in the field. Currently, the function is empty and needs to be implemented.
… ensure it is a positive value
…aximum field size in bits to prevent errors
…tly perform bitwise NOT operation on constant values
… `Bitwise` module The `Not` gadget is a new addition to the `Bitwise` module. This commit adds a unit test for the `Not` gadget in the `bitwise.unit-test.ts` file. The unit test verifies the correctness of the `Not` gadget by running it with a private input and asserting the expected output.
… different lengths of inputs
…valentAsync The unit test was added to test the NOT operation in the `bitwise.unit-test.ts` file. The test checks if the input value `x` is greater than or equal to 2^64 and throws an error if it does not fit into 64 bits. It then returns the result of the NOT operation on `x`. The test also includes an async function that uses the `Bitwise.not` method to calculate the NOT operation and returns the public output of the proof.
… in the primitive constraint system example The 'not' operation has been added to the primitive constraint system. This operation allows for negating a value in the system. The 'not' operation is supported for 16-bit, 32-bit, 48-bit, and 64-bit values.
…ency and tracking purposes
…factored not method in Bitwise ZkProgram
…tion This commit adds the missing test case with the required "rows" and "digest" properties.
Do you mind merging |
Trivo25
reviewed
Oct 26, 2023
Trivo25
reviewed
Nov 2, 2023
Yeah of course! Thanks for the comments @MartinMinkov. |
…k if the length is less than the maximum field size in bits instead of less than or equal to, to ensure it doesn't exceed the maximum size
…76b1a36517722e931fcf6
…otate and xor gadgets
… fail if the length is larger than 254
The `Gadgets.not()` method was added to support bitwise shifting for native field elements. This change was made in response to the pull request #1198 on the o1js repository.
Trivo25
reviewed
Nov 3, 2023
Trivo25
reviewed
Nov 3, 2023
… greater than or equal to 2^254 instead of 2^255 to ensure it fits into 255 bits
…4376b1a36517722e931fcf6 to 1e7512296a2cf1653277cc9b11482975156fb5c9
…case to reflect the correct value after regression testing
… and notUnchecked functions
…of Fp.modulus for better error reporting and debugging
…ill fail if the input value is larger than 254 bits
Closed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Closes #1141
This PR adds the implementation for a
NOT
gate to the existingGadgets
namespace. A bitwiseNOT
is an operation that returns1
in each bit position if the corresponding bit of the operand is0
, and returns0
if the corresponding bit of the operand is1
.The original OCaml implementation is here.
🔗 bindings: o1-labs/o1js-bindings#194