Skip to content

Commit

Permalink
Merge pull request #74 from hyperledger-labs/nullifier_mint
Browse files Browse the repository at this point in the history
Fix handling of 0 input elements in nullifier token mints
  • Loading branch information
Chengxuan authored Sep 19, 2024
2 parents e0427b0 + cded1fa commit 981efd3
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
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

0 comments on commit 981efd3

Please sign in to comment.