Skip to content

Commit 8f29a5d

Browse files
committed
fix: rebase and fixes
1 parent 11292ea commit 8f29a5d

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

‎nightfall-client/src/utils/compute-witness.mjs

+8-5
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ const computePrivateInputsNullifiers = privateData => {
6666
].flat(Infinity);
6767
};
6868

69-
const computePrivateInputsCommitments = privateData => {
69+
const computePrivateInputsCommitments = (privateData, padTo) => {
7070
const { newCommitmentPreimage, recipientPublicKeys } = generalise(privateData);
71-
const paddedNewCommitmentPreimage = padArray(newCommitmentPreimage, NULL_COMMITMENT, 2);
72-
const paddedRecipientPublicKeys = padArray(recipientPublicKeys, [0, 0], 2);
71+
const paddedNewCommitmentPreimage = padArray(newCommitmentPreimage, NULL_COMMITMENT, padTo);
72+
const paddedRecipientPublicKeys = padArray(recipientPublicKeys, [0, 0], padTo);
7373
return [
7474
paddedNewCommitmentPreimage.map(commitment => commitment.value.limbs(8, 31)),
7575
paddedNewCommitmentPreimage.map(commitment => commitment.salt.field(BN128_GROUP_ORDER)),
@@ -96,19 +96,22 @@ export const computeWitness = (txObject, roots, privateData) => {
9696
const publicInputs = computePublicInputs(txObject, roots);
9797
switch (Number(txObject.transactionType)) {
9898
case 0:
99+
// Deposit
99100
return [...publicInputs, ...computePrivateInputsDeposit(privateData)];
100101
case 1:
102+
// Transfer
101103
return [
102104
...publicInputs,
103105
...computePrivateInputsNullifiers(privateData),
104-
...computePrivateInputsCommitments(privateData),
106+
...computePrivateInputsCommitments(privateData, 2),
105107
...computePrivateInputsEncryption(privateData),
106108
];
107109
default:
110+
// Withdraw
108111
return [
109112
...publicInputs,
110113
...computePrivateInputsNullifiers(privateData),
111-
...computePrivateInputsCommitments(privateData),
114+
...computePrivateInputsCommitments(privateData, 1),
112115
];
113116
}
114117
};

‎nightfall-deployer/circuits/common/generic_circuit/Verifiers/verify_commitments.zok

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def main<MinCommitments, MaxCommitments>(\
2121
We can check if commitment is supposed to be null or non-null by the following
2222
1) Note that degenerate case for each circuit type (deposit, transfer, withdraw) also matches the possible uses involving erc721
2323
2) Thus, we first perform checks based on this degenerate case (characterised by MinCommitments).
24-
3) We use (i + 1) as the loop is zero-indexed by MinCommitments is a count of minimum allowable commitments.
24+
3) We use (i + 1) as the loop is zero-indexed while MinCommitments is a count of minimum allowable commitments.
2525
4) Therefore we check (with a poseidon hash) any input when the incremented loop index matches this conditional.
2626
5) Finally, we check the "optional extra commitments" that are only allowable to erc20/1155 (characterised by value > 0)
2727
*/

‎nightfall-deployer/circuits/common/generic_circuit/Verifiers/verify_nullifiers.zok

+5-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def main<MinNullifiers, MaxNullifiers>(\
4242
We can check if nullifier is supposed to be null or non-null by the following
4343
1) Note that degenerate case for each circuit type (deposit, transfer, withdraw) also matches the possible uses involving erc721
4444
2) Thus, we first perform checks based on this degenerate case (characterised by MinNullifiers).
45-
3) We use (i + 1) as the loop is zero-indexed by MinNullifiers is a count of minimum allowable nullifiers.
45+
3) We use (i + 1) as the loop is zero-indexed while MinNullifiers is a count of minimum allowable nullifiers.
4646
4) Therefore we check (with a poseidon hash/path check) any input when the incremented loop index matches this conditional.
4747
5) Finally, we check the "optional extra nullifiers" that are only allowable to erc20/1155 (characterised by value > 0)
4848
*/
@@ -53,15 +53,17 @@ def main<MinNullifiers, MaxNullifiers>(\
5353
...zkpPublicKeys,\
5454
oldCommitmentSalts[i]\
5555
])
56-
field nullifier = if(oldCommitmentValues[i] != 0 || (i+1) != MinNullifiers) then poseidon([nullifierKeys, calculatedOldCommitmentHash]) else 0 fi
56+
field nullifier = if(oldCommitmentValues[i] != 0 || (i+1) == MinNullifiers) then poseidon([nullifierKeys, calculatedOldCommitmentHash]) else 0 fi
5757

5858
//Check that the calculated nullifier matches with the one contained in the transaction
5959
assert(nullifier == nullifierHashes[i])
6060

6161
//Check that the nullifier is contained in the tree
62-
bool pathValidity = if(oldCommitmentValues[i] != 0 || (i+1) != MinNullifiers) then pathCheck([roots[i], ...paths[i]], orders[i], calculatedOldCommitmentHash) else true fi
62+
bool pathValidity = if(oldCommitmentValues[i] != 0 || (i+1) == MinNullifiers) then pathCheck([roots[i], ...paths[i]], orders[i], calculatedOldCommitmentHash) else true fi
6363
assert(pathValidity)
6464

65+
//Set the changeZkpPublicKeys if i = 0. Otherwise just set the same value
66+
firstInputZkpPublicKeys = i == 0 ? zkpPublicKeys : firstInputZkpPublicKeys
6567
endfor
6668

6769
return firstInputZkpPublicKeys

0 commit comments

Comments
 (0)