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

Fix handling of 0 input elements in nullifier token mints #74

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions solidity/contracts/lib/zeto_nullifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ abstract contract ZetoNullifier is ZetoCommon {
function _mint(uint256[] memory utxos) internal virtual {
for (uint256 i = 0; i < utxos.length; ++i) {
uint256 utxo = utxos[i];
if (utxo == 0) {
continue;
}
uint256 nodeHash = _getLeafNodeHash(utxo);
SmtLib.Node memory node = _commitmentsTree.getNode(nodeHash);

Expand Down
9 changes: 8 additions & 1 deletion solidity/test/zeto_anon_enc_nullifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ describe("Zeto based fungible token with anonymity using nullifiers and encrypti
// check the private transfer activity is not exposed in the ERC20 contract
const afterTransferBalance = await erc20.balanceOf(Alice.ethAddress);
expect(afterTransferBalance).to.equal(startingBalance);

// Alice locally tracks the UTXOs inside the Sparse Merkle Tree
await smtAlice.add(_utxo3.hash, _utxo3.hash);
await smtAlice.add(utxo4.hash, utxo4.hash);
Expand Down Expand Up @@ -326,6 +326,13 @@ describe("Zeto based fungible token with anonymity using nullifiers and encrypti

await expect(doTransfer(Alice, [nonExisting1, nonExisting2], [nullifier1, nullifier2], [utxo7, _utxo1], root.bigInt(), merkleProofs, [Bob, Charlie])).rejectedWith("UTXORootNotFound");
}).timeout(600000);

it("repeated mint calls with single UTXO should not fail", async function () {
const utxo5 = newUTXO(10, Alice);
await expect(doMint(zeto, deployer, [utxo5, ZERO_UTXO])).fulfilled;
const utxo6 = newUTXO(20, Alice);
await expect(doMint(zeto, deployer, [utxo6, ZERO_UTXO])).fulfilled;
});
});

async function doTransfer(signer: User, inputs: UTXO[], _nullifiers: UTXO[], outputs: UTXO[], root: BigInt, merkleProofs: BigInt[][], owners: User[]) {
Expand Down
7 changes: 7 additions & 0 deletions solidity/test/zeto_anon_nullifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,13 @@ describe("Zeto based fungible token with anonymity using nullifiers without encr

await expect(doTransfer(Alice, [nonExisting1, nonExisting2], [nullifier1, nullifier2], [utxo7, _utxo1], root.bigInt(), merkleProofs, [Bob, Charlie])).rejectedWith("UTXORootNotFound");
}).timeout(600000);

it("repeated mint calls with single UTXO should not fail", async function () {
const utxo5 = newUTXO(10, Alice);
await expect(doMint(zeto, deployer, [utxo5, ZERO_UTXO])).fulfilled;
const utxo6 = newUTXO(20, Alice);
await expect(doMint(zeto, deployer, [utxo6, ZERO_UTXO])).fulfilled;
});
});

async function doTransfer(signer: User, inputs: UTXO[], _nullifiers: UTXO[], outputs: UTXO[], root: BigInt, merkleProofs: BigInt[][], owners: User[]) {
Expand Down
7 changes: 7 additions & 0 deletions solidity/test/zeto_anon_nullifier_kyc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,13 @@ describe("Zeto based fungible token with anonymity, KYC, using nullifiers withou

await expect(doTransfer(Alice, [nonExisting1, nonExisting2], [nullifier1, nullifier2], [utxo7, _utxo1], root.bigInt(), merkleProofs, identitiesRoot.bigInt(), identitiesMerkleProofs, [Bob, Charlie])).rejectedWith("UTXORootNotFound");
}).timeout(600000);

it("repeated mint calls with single UTXO should not fail", async function () {
const utxo5 = newUTXO(10, Alice);
await expect(doMint(zeto, deployer, [utxo5, ZERO_UTXO])).fulfilled;
const utxo6 = newUTXO(20, Alice);
await expect(doMint(zeto, deployer, [utxo6, ZERO_UTXO])).fulfilled;
});
});

async function doTransfer(signer: User, inputs: UTXO[], _nullifiers: UTXO[], outputs: UTXO[], utxosRoot: BigInt, utxosMerkleProofs: BigInt[][], identitiesRoot: BigInt, identitiesMerkleProof: BigInt[][], owners: User[]) {
Expand Down
Loading