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

Generate constraints in black box functions #74

Draft
wants to merge 30 commits into
base: main
Choose a base branch
from

Conversation

ilitteri
Copy link
Collaborator

@ilitteri ilitteri commented Mar 27, 2023

Description

  • AND.
  • XOR.
  • RANGE.
  • SHA256.
  • Blake2s.
  • HashToField128Security.

ilitteri and others added 23 commits March 17, 2023 11:49
Due to the new fixed bugs, new test programs could run properly using our backend
- AND
- XOR
- RANGE
- SHA256
- Blake2s
- HashToField128Security
- EcdsaSecp256k1
* Add first implementation of  gadget

* Update gnark_backend_ffi/backend/plonk/components.go

* Update gnark_backend_ffi/backend/plonk/components.go

* Update gnark_backend_ffi/backend/plonk/components.go

* Update gnark_backend_ffi/backend/plonk/components.go

* Add function to get the one wire's index

* Fix function signature

* Improve documentation

* Add secret variables instead of internal ones for the intermediate variables

* Return the mutated secret variables

* Refactor a function (abstract it from the ACIR)

* Add tests for `assertIsBoolean` component

* Fix `assertIsBoolean` constraint component

* Remove useless function

* Update naming

* Fix
@ilitteri ilitteri self-assigned this Mar 27, 2023
ilitteri and others added 6 commits March 30, 2023 10:38
* Add first implementation of  gadget

* Update gnark_backend_ffi/backend/plonk/components.go

* Update gnark_backend_ffi/backend/plonk/components.go

* Update gnark_backend_ffi/backend/plonk/components.go

* Update gnark_backend_ffi/backend/plonk/components.go

* Add function to get the one wire's index

* Fix function signature

* Improve documentation

* Add secret variables instead of internal ones for the intermediate variables

* Return the mutated secret variables

* Refactor a function (abstract it from the ACIR)

* Add tests for `assertIsBoolean` component

* Add tests for bit and component

* Add bit and component

* Add multiple-bit and component

* Update result's secret variable name

* Fix `assertIsBoolean` constraint component

* Remove useless function

* Update naming

* Fix

* Add `assertIsEqual` component

* Refactor repeated code in tests

* Add `assertIsEqual` component tests

* Implement `add` `mul` & `assertIsEqual` components

* Fix `toBinaryConversion` component

* Update secret variables naming

* Add `toBinaryConversion` tests

* Remove print

* Add missing boolean assertion when converting to binary

* Improve variable labels

* Fix `toBinaryConversion`

* Flag to generate constraint over `and` inputs

* Update `And`

* Shift coefficient after every iteration

* Implement `fromBinaryConversion` component

* Update tests naming

* Finish `And` implementation

* Update `accumulator` label name

* Remove needless boolean assertion

It is asserted above

* Document components

* Cleanup components

* Rename module

* Doc `assertIsEqual`
* Add first implementation of  gadget

* Update gnark_backend_ffi/backend/plonk/components.go

* Update gnark_backend_ffi/backend/plonk/components.go

* Update gnark_backend_ffi/backend/plonk/components.go

* Update gnark_backend_ffi/backend/plonk/components.go

* Add function to get the one wire's index

* Fix function signature

* Improve documentation

* Add secret variables instead of internal ones for the intermediate variables

* Return the mutated secret variables

* Refactor a function (abstract it from the ACIR)

* Add tests for `assertIsBoolean` component

* Add tests for bit and component

* Add bit and component

* Add multiple-bit and component

* Update result's secret variable name

* Add xor component implementation

Both for bit-to-bit and multiple bits

* Fix append

* Add tests for single bit xor

* Fix `assertIsBoolean` constraint component

* Remove useless function

* Update naming

* Fix

* Add `assertIsEqual` component

* Refactor repeated code in tests

* Add `assertIsEqual` component tests

* Implement `add` `mul` & `assertIsEqual` components

* Fix `toBinaryConversion` component

* Update secret variables naming

* Add `toBinaryConversion` tests

* Remove print

* Add missing boolean assertion when converting to binary

* Improve variable labels

* Fix `toBinaryConversion`

* Flag to generate constraint over `and` inputs

* Update `And`

* Shift coefficient after every iteration

* Implement `fromBinaryConversion` component

* Update tests naming

* Finish `And` implementation

* Update `accumulator` label name

* Remove needless boolean assertion

It is asserted above

* Document components

* Cleanup components

* Rename module

* Doc `assertIsEqual`

* Finish `Xor` & `xor` components implementations

* Update doc
* Add first implementation of  gadget

* Update gnark_backend_ffi/backend/plonk/components.go

* Update gnark_backend_ffi/backend/plonk/components.go

* Update gnark_backend_ffi/backend/plonk/components.go

* Update gnark_backend_ffi/backend/plonk/components.go

* Add function to get the one wire's index

* Fix function signature

* Improve documentation

* Add secret variables instead of internal ones for the intermediate variables

* Return the mutated secret variables

* Refactor a function (abstract it from the ACIR)

* Add tests for `assertIsBoolean` component

* Add tests for bit and component

* Add bit and component

* Add multiple-bit and component

* Update result's secret variable name

* Add xor component implementation

Both for bit-to-bit and multiple bits

* Fix append

* Add tests for single bit xor

* Fix `assertIsBoolean` constraint component

* Remove useless function

* Update naming

* Fix

* Add `assertIsEqual` component

* Refactor repeated code in tests

* Add `assertIsEqual` component tests

* Implement `add` `mul` & `assertIsEqual` components

* Fix `toBinaryConversion` component

* Update secret variables naming

* Add `toBinaryConversion` tests

* Remove print

* Add missing boolean assertion when converting to binary

* Improve variable labels

* Fix `toBinaryConversion`

* Flag to generate constraint over `and` inputs

* Update `And`

* Shift coefficient after every iteration

* Implement `fromBinaryConversion` component

* Update tests naming

* Finish `And` implementation

* Update `accumulator` label name

* Remove needless boolean assertion

It is asserted above

* Document components

* Cleanup components

* Rename module

* Doc `assertIsEqual`

* Finish `Xor` & `xor` components implementations

* Update doc

* Update variable usage

In the previous iteration, only secret variables were assumed to be the only ones used for the component. In reality, both secret and public variables could be used with components. Given that in components, the intermediate variables are treated as secret, then we must track them, but we also need to use the full variables vector (public+secret in order).

This is just another iteration, it seems that having some mutable Context data structure would clean the code a lot, because it is really messy as it is and the user must take care of updating the secret, and the full variables vectors.

* `HandleValues` returns a full variables vector too

Public + secret in order

* Both `handleOpcodes`and `handleBlackBoxFunctionOpcode` must now return the added secret variables (that are the internal ones).

If we manage to handle these internal variables as internal and not as secret, this would be useless.

* First iteration of integrating AND & XOR opcodes

On this iteration we do not handle the `variablesMap` and we do not compare the incoming output with the computed one.

* Bring back Go tests

At the moment we're just running Plonk's components tests because the ACIR's are to be fixed

* Update package name

* Sort imports

* Update imports

* Add missing function

* `Context` refactor (#76)

* Add `Context`

* Handle `Context` in components

* Update tests

* Comment out `go` job until fixed

* Temporarily fix integration

For some reason, having a third level module (`components`) makes the `cc` crate not to compile when building `nargo`. It seems that the module is not being found.
* `Select` component (#78)

* `Sub` component (#77)

* Add `sub` component (subtraction)

* Update test

* Add `Select` component (if condition)

* Add components to `components.go`

* Add `assertIsInRange` component

* Handle `Range` black box function
…k into generate_constraints_in_black_box_functions
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.

1 participant