Skip to content

Commit

Permalink
Merge pull request #356 from EYBlockchain/hari/duplicate-commitment
Browse files Browse the repository at this point in the history
Hari/duplicate commitment
  • Loading branch information
ChaitanyaKonda authored Jan 10, 2022
2 parents 65eccb3 + 9702f4f commit 55ddebf
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
3 changes: 2 additions & 1 deletion nightfall-client/src/services/commitment-storage.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ async function findUsableCommitments(compressedPkd, ercAddress, tokenId, _value,
return [singleCommitment];
}
// If we get here it means that we have not been able to find a single commitment that matches the required value
if (onlyOne) return null; // sometimes we require just one commitment
if (onlyOne || commitments.length < 2) return null; // sometimes we require just one commitment

/* if not, maybe we can do a two-commitment transfer. The current strategy aims to prioritise smaller commitments while also
minimising the creation of low value commitments (dust)
Expand Down Expand Up @@ -493,6 +493,7 @@ async function findUsableCommitments(compressedPkd, ercAddress, tokenId, _value,
// then we will need to use a commitment of greater value than the target
if (twoGreatestSum < value.bigInt) {
if (commitsLessThanTargetValue.length === sortedCommits.length) return null; // We don't have any more commitments
if (commitsLessThanTargetValue.length === 0) return [sortedCommits[0], sortedCommits[1]]; // return smallest in GT if LT array is empty
return [sortedCommits[commitsLessThanTargetValue.length], sortedCommits[0]]; // This should guarantee that we will replace our smallest commitment with a greater valued one.
}

Expand Down
1 change: 1 addition & 0 deletions nightfall-optimist/src/services/transaction-checker.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ async function checkTransactionType(transaction) {
transaction.commitments.length !== 2 ||
transaction.nullifiers.some(n => n === ZERO) ||
transaction.nullifiers.length !== 2 ||
transaction.nullifiers[0] === transaction.nullifiers[1] ||
transaction.compressedSecrets.every(cs => cs === ZERO) ||
transaction.compressedSecrets.length !== 8 ||
transaction.proof.every(p => p === ZERO)
Expand Down

0 comments on commit 55ddebf

Please sign in to comment.