Skip to content

Flexible Input/Output circuits #843

New issue

Have a question about this project? Sign up for a free account to open an issue and contact its maintainers and the community.

By clicking “Sign up for ”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on ? Sign in to your account

Merged
merged 16 commits into from
Aug 8, 2022
Merged

Flexible Input/Output circuits #843

merged 16 commits into from
Aug 8, 2022

Conversation

IlyasRidhuan
Copy link
Contributor

This PR closes #818 and closes #262 and removes the need for specific circuits based on the commitments and nullifiers. Instead we have 3 circuits (deposit, transfer, withdraw) that can support variable number of commitment/nullifiers. There are considerable changes to the way the circuits and commitment selection works in this PR.

Circuits

  1. The circuits are refactored to make liberal use of generics across the key verify functions (e.g. verify_nullifier, verify_commitment and verify_structure).
  2. The public transaction struct has been included as part of the public input to the proof. This means the circuit also performs the structural check for the validity of the transaction struct itself. This heavily simplifies the challenges as we no longer need to have a specific transaction structure challenge.
OperationConstraints BeforeConstraints After% Change
Deposit619921+48%
Single Transfer26,32039,363+50%
Double Transfer39,29539,363+0.01%
Withdraw12,07526,050+112%

Note: There is no longer a specific single_transfer circuit as the transfer circuit handles all scenarios (hence the constraint is as large as possible to also handle double_transfer). Similarly, withdraw must be able to accommodate the most complex scenario of 2 inputs with a single output, which increases the constraints significantly.

Commitment Selection

We now have the flexibility to better select the type of transaction that will be performed based on the current user's UTXO (notes). Previously, commitment selection was based on:

  1. Perform a single transfer when possible
  2. Else perform a double transfer if the total inputs were greater than the required output
    Note: A double transfer would fail if the sum of inputs were equal to the required output (i.e. it had to be strictly greater than). Withdraw's needed to be of exact value.

With the new flexible circuits we perform the following checks

  1. Perform a single transfer if possible.
  2. Perform a double transfer without change if we have a sum of inputs that match the exact value.
  3. Perform a single transfer with change if we have a single input > output required
  4. Perform a double transfer with change otherwise.

This is still subject to change, especially in the prioritising of (3) and (4). Note that a withdraw now attempts to do (1) to (3) instead of being restricted to an exactly matching input.

Testing

This can be tested by running npm run test-circuits while nightfall is running

RogerTaule
RogerTaule previously requested changes Aug 3, 2022
assert(pathValidity)

//Set the changeZkpPublicKeys if i = 0. Otherwise just set the same value
firstInputZkpPublicKeys = i == 0 ? zkpPublicKeys : firstInputZkpPublicKeys
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the firstInputZkpPublicKeys inicialization was removed?

@@ -11,7 +11,7 @@ def main(\
PublicTransaction tx,\
field[2] roots,\
private Nullifiers<2> nullifiers,\
private Commitments<2> commitments\
private Commitments<1> commitments\
Copy link
Contributor

Choose a reason for hiding this comment

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

If we set Commitments<1> in the withdraw.zok, withdraw_stub.zok needs to also be updated

@IlyasRidhuanIlyasRidhuan force-pushed the ilyas/flexible-circuits branch 4 times, most recently from 8f29a5d to ca9558b Compare August 5, 2022 16:54
@IlyasRidhuanIlyasRidhuan force-pushed the ilyas/flexible-circuits branch from 2a1df12 to cc72de3 Compare August 7, 2022 12:42
@RogerTauleRogerTaule mentioned this pull request Aug 8, 2022
Copy link
Contributor

@RogerTaule RogerTaule left a comment

Choose a reason for hiding this comment

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

Looks good to me :)

@druiz0992druiz0992 merged commit 2c79016 into master Aug 8, 2022
@druiz0992druiz0992 deleted the ilyas/flexible-circuits branch August 8, 2022 13:43
Sign up for free to join this conversation on . Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants