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

Implement NOT gadget #1198

Merged
merged 71 commits into from
Nov 8, 2023
Merged

Implement NOT gadget #1198

merged 71 commits into from
Nov 8, 2023

Conversation

ymekuria
Copy link
Contributor

@ymekuria ymekuria commented Oct 25, 2023

Description

Closes #1141

This PR adds the implementation for a NOT gate to the existing Gadgets namespace. A bitwise NOT is an operation that returns 1 in each bit position if the corresponding bit of the operand is 0, and returns 0 if the corresponding bit of the operand is 1.

The original OCaml implementation is here.

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

…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.
…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.
…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.
@ymekuria ymekuria marked this pull request as ready for review October 26, 2023 20:36
@ymekuria ymekuria requested review from mitschabaude and a team as code owners October 26, 2023 20:36
@MartinMinkov
Copy link
Contributor

Do you mind merging main into your branch before reviewing? There were quite a few files that moved around, so it would really help to have that laid out before trying to review and then resolving conflicts.

src/lib/gadgets/bitwise.ts Outdated Show resolved Hide resolved
src/lib/gadgets/bitwise.ts Outdated Show resolved Hide resolved
@ymekuria
Copy link
Contributor Author

ymekuria commented Nov 2, 2023

Adding links to the mina book is a great idea! Do you mind adding the same for other gadgets in this PR here as well?

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
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.
src/lib/gadgets/gadgets.ts Outdated Show resolved Hide resolved
src/lib/gadgets/gadgets.ts Outdated Show resolved Hide resolved
src/examples/regression_test.json Outdated Show resolved Hide resolved
src/lib/gadgets/bitwise.unit-test.ts Outdated Show resolved Hide resolved
@ymekuria ymekuria merged commit 2636346 into main Nov 8, 2023
13 checks passed
@ymekuria ymekuria deleted the feature/NOT-gadget branch November 8, 2023 05:54
@ymekuria ymekuria mentioned this pull request Nov 13, 2023
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 NOT gadget to TypeScript
4 participants